* PC.PRG (Parent Child demo PRG - Thurber) * * I Liked where you were going with your PRG form - so I slapped * together a demo of all I know about PRG top and in top behavior * management. * * Here's the deal - I think - your sample form was the only form. * A good generaliztion might be that if you have just one form - * it should be "Top Level". A "CLEAR EVENTS" should only fire * when ALL the application is being closed. IOW - only one * Read Event and only one CLEAR EVENT. Also, only the TOP LEVEL * form should have the priviledge to to issue a clear event. * * With any PRG Form - when it closes it should clear and you should * not have to cancel the program. When it is acceptably desgined and * implemented, the pre launch state should be as it was when * you application shut down. * * The child form - once it is instanciated (createobject-ed) is not * released until you exit the Parent. If you toggle the parents right, * or child form button - each click will reverses it's current * visibility state. You can click the Parents "right" button to both * open and close the "Child" form. * * I have also been able to avoid the "greyed" X close button. It is * very important that you parent form receive the "focus" before * a CLEAR VENT is fired - check how the "txtFB" object is used, on the * parent form to service "Exit" calls. I also added a little toolbar so * you could get a feel for how controls that don't receive focus, like * the ToolBar buttons, affect behaviors. * * I did not put "captions in the toolbar buttons - I use imagelist * pictures - and they don't look right (not square or small) when * I put captions in them (but they to have tooltips!). * If you want to see how Images are loaded into a TB - download RIO! * * On the Parent - the left TB button is an exit - the right one opens * the CHild Form. On the Child form, the TB button is also an exit * button. With Eaxh from you have 3 exit controls - the Forms [X] * close, a command button and a toolbar button. PUBLIC frmPF , frmCF, ulExitFlag, ulLeaveAsIs && Parent Form ,Child Form ON ERROR DO errhand WITH ERROR( ),MESSAGE( ),MESSAGE(1),PROGRAM( ),LINENO( ) frmPF=CREATEOBJECT('clsPF') frmPF.Show READ EVENTS * Last House cleaning ??chr(7) on error release all clear all cancel * End of all events and objects!! PROCEDURE runClickButton(oform,oButton) IIF(oform.name="frmCF",frmCF.QueryUnload(),frmPF.QueryUnload()) ENDPROC &&runClickButton(oform,oButton) PROCEDURE runForm_Init(oform,lccmdCaption) oform.addobject('cmdExit','clsCommand') oform.cmdExit.Caption=lccmdCaption oform.cmdExit.toolTipText=[Sets a Focus:]+lccmdCaption runAddToolBar(oForm) runForm_Resize(oform,oform.cmdExit) *oform.visible=.t. ENDPROC &&runForm_Init(oform,oButton) PROCEDURE runAddToolBar(oForm) oform.addobject('cntToolBar','cntToolBarClass') addToolBar(oform,oform.cntToolBar) ENDPROC PROCEDURE runForm_Resize(oform,oButton) oform.cntToolBar.Width=oform.width-2 oform.cntToolBar.ocxToolBar.width=oform.cntToolBar.width-4 oButton.top=oform.height-22 oButton.left=(oform.width/2)-(oButton.width/2) ENDPROC &&runForm_Resize(oform,oButton) PROCEDURE addToolBar(oForm,oCnt) oForm.cntToolBar.AddObject('ocxToolBar','ocxToolBarClass','MSComctlLib.Toolbar.2') oform.cntToolBar.width=oform.width-4 WITH oForm.cntToolBar.ocxToolBar .AllowCustomize=.f. .Appearance=0 .Wrappable=.f. .buttonheight=18 .buttonwidth=18 .TextAlignment=0 .Style=0 && One will make transparent .top=2 .left=4 .width=oForm.cntToolBar.Width-4 .buttons.add(,[EXIT]) .buttons([EXIT]).ToolTipText=[Eixt]+IIF(UPPER(oform.name)="FRMPF",[Parent],[Child])+[ Form] IF UPPER(oform.Name)=[FRMPF] && Add an open child vutton to the parent .buttons.add(,[CHILD]) .buttons([CHILD]).ToolTipText=[Toggle the child's invisible property] ENDIF ENDWITH &&oForm.cntToolBar.ocxToolBar STORE .t. to oForm.cntToolBar.ocxToolBar.Visible,oForm.cntToolBar.Visible ENDPROC &&RIOAddToolBar(oForm,oImageList) PROCEDURE runExitAll(oform) IF MESSAGEBOX([Ready to Exit],4+48+256,[runExitAll])=6 ulExitFlag=.t. oform.txtFB.Setfocus IF VARTYPE(frmCF)==[O] frmCF.Release ENDIF oform.visible=.f. oform.release clear events ELSE ulLeaveAsIs=.t. ENDIF ENDPROC &&runExitAll() PROCEDURE errhand (merror, mess, mess1, mprog, mlineno) on error messagebox(tran(merror)+[:]+tran(mess)+[:]+tran(mprog)+[:]+tran(mlineno); ,48,[Error Trapped!]) ON ERROR DO errhand WITH ERROR( ),MESSAGE( ),MESSAGE(1),PROGRAM( ),LINENO( ) ENDPROC && errhand DEFINE CLASS cntToolBarClass as Container left=1 height=29 width=1 borderwidth=1 bordercolor=RGB(128,128,192) top=1 ENDDEFINE &&CLASS cntToolBarClass as Container DEFINE CLASS ocxToolBarClass as Olecontrol PROCEDURE ButtonClick(Button) && Happens at ToolBar Click runToolBarButtonClicks(thisform,Button) ENDPROC &&ButtontonClick(Button) ENDDEFINE &&ocxToolBarClass as Olecontrol PROCEDURE runToolBarButtonClicks(oform,oButton) lcKey=oButton.key IF oButton.key=[CHILD] IF !TYPE('frmCF')==[O] frmCF=CREATEOBJECT('clsCF') ENDIF frmCF.visible=!frmCF.visible ELSE && One of the exit buttons IF oform.name=[frmCF] frmCF.visible=.f. ELSE frmPF.release ENDIF ENDIF ENDPROC &&runToolBarButtonClicks(oform) DEFINE CLASS clsPF as Form && The Parent form name="frmPF" caption="Parent Form" height=500 width=600 desktop=.f. showwindow=2 && toplevel windowtype=0 && Modeless backcolor=16777215 autocenter=.t. ADD OBJECT txtFB as subFB PROCEDURE init runForm_Init(this,[Exit Parent Form]) ENDPROC PROCEDURE resize runForm_Resize(this,this.cmdExit) endproc PROCEDURE QueryUnload runExitAll(this) IF !ulExitFlag NODEFAULT ENDIF ENDPROC ENDDEFINE &&clsPF DEFINE CLASS clsCF as Form && The child form base class name="frmCF" caption="Child Form" height=300 width=300 showwindow=1 && in toplevel windowtype=0 && Modeless alwaysontop=.t. backcolor=15990496 && Default for child autocenter=.t. PROCEDURE init runForm_Init(this,[Exit Child Form]) ENDPROC PROCEDURE resize runForm_Resize(this,this.cmdExit) ENDPROC PROCEDURE QueryUnload IF ulExitFlag dodefault ELSE NODEFAULT this.visible=IIF(ulLeaveAsIs,this.visible,.f.) ulLeaveAsIs=.F. ENDIF ENDPROC ENDDEFINE &&clsCF DEFINE CLASS clsCommand as CommandButton FontName="Arial" FontSize=8 height=20 width=80 visible=.t. PROCEDURE click runClickButton(thisform,this) ENDPROC ENDDEFINE && clsCommand as CommandButton define class subFB AS TextBox Visible=.t. borderstyle=0 backstyle=0 Top=-100 Height=1 Width=1 enddefine ** END OF PROGRAM *****************************************