PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Shawn Anderson on April 28, 2009, 08:38:23 PM

Title: using menus
Post by: Shawn Anderson on April 28, 2009, 08:38:23 PM
When I used to create menus with PB forms, I would create a set of controls for each menu item, and when a menu item was chosen, I would hide all of the form elements except for the ones pertaining to the chosen menu item.

I was wondering if this was a similar process in Firefly, or if I should create a separate form for each menu item and somehow display the form I want, like when using tabs. I can figure this out with a non-modal form, but I want the different form elements to display on the same form, without opening a new form (is that MDI?).

Does that make sense?
Title: Re: using menus
Post by: TechSupport on April 28, 2009, 09:16:31 PM
Hi Shawn,

You can do it both ways. Your PBForms approach will work the same in FireFly.

I use the Form approach. For example, take a look at FireFly's "Environment Options" form. Whenever you click on an option in the right hand side treeview, I display the appropriate in the right hand side. I accomplish this by loading all of the right hand side forms as non-modal during the WM_CREATE message handler. It is easy to then show/hide the forms whenever the treeview item changes.


Title: Re: using menus
Post by: Shawn Anderson on April 28, 2009, 09:40:03 PM
thanks Paul.
Can you point me to a small example of how to do that?
I'm trying something like this with a simple 2-element menu, but it shows up in a new window.


Select Case wID
    Case IDC_MAIN_MNUSETUP
        hwndForm=setup_Show(hWndForm, %false) ' non-modal
    Case IDC_MAIN_MNUEXIT
                     Dialog End hWndForm
    End Select
Title: Re: using menus
Post by: TechSupport on April 28, 2009, 11:03:16 PM
Hi Shawn,

I uploaded a pretty basic example a long time ago. Check out this sample: http://www.planetsquires.com/files/PropDialog.zip

Oh, and *never* use "Dialog End" in FireFly. Always use FF_CloseForm.



Title: Re: using menus
Post by: Shawn Anderson on April 29, 2009, 03:40:58 PM
Thanks Paul, that's what I needed.

Now I have another question:
is there a better place to initialize dll's than wm_create?
After I added the menu code, wm_create seems to be being called multiple times.
I worked around it by using a global variable dbIsOpen:
   
    If dbIsOpen=0 Then
SQL_Authorize %MY_SQLT_AUTHCODE
SQL_Initialize 2,2,256,3,3,0,0,0                                     

result=openDB()   
If result<>-1 Then FF_CloseForm hWndForm     

dbIsOpen=-1
    End If


is there a better way?
thanks!
Title: Re: using menus
Post by: TechSupport on April 29, 2009, 04:04:28 PM
Hi Shawn,

I would do the SQL_Auhtorize and SQL_Initialize in the FF_WinMain function. That is a "Special Function" located in the "FireFly Workspace" under the "Explorer" tab.

BTW, WM_CREATE does not get called multiple times... unless you are closing the Form and then doing additional FORM1_Show calls. The WM_CREATE only gets called one time at the time the Form is created. Are you sure that you have your code in the WM_CREATE handler for the Form and not in the WM_COMMAND handler by mistake?


Title: Re: using menus
Post by: Shawn Anderson on April 29, 2009, 04:41:31 PM
thanks I'll use ff_winmain

here is my code


Global gChildForms() As Dword     
Global dbIsOpen As Long

'------------------------------------------------------------------------------------------------------------------------
Function MAIN_WM_CREATE ( _
                        hWndForm As Dword, _  ' handle of Form
                        ByVal UserData As Long _  'optional user defined Long value
                        ) As Long
Local result As Long               
                                   
' open and ititialize sql tools   
    If dbIsOpen=0Then
SQL_Authorize %MY_SQLT_AUTHCODE
SQL_Initialize 2,2,256,3,3,0,0,0                                     

result=openDB() 

Select Case result
Case -1
' success
dbIsOpen=-1
Case 0
' error   
FF_CloseForm hWndForm   
Case 2
' need setup below
dbIsOpen=-1
End Select


End If

' dimension array holding form data
Dim gChildForms( 2 ) As Global Dword

' Load the child pages (Forms)
gChildForms(0) = main_Show( hWndForm, %FALSE )
gChildForms(1) = setup_Show( hWndForm, %FALSE )   
gChildForms(2) = convert_Show( hWndForm, %FALSE )

' Display the first child page       
    If result=2 Then
        DisplayChildForm 1
    Else
DisplayChildForm 2           
End If

End Function


'------------------------------------------------------------------------------------------------------------------------
Function MAIN_WM_DESTROY ( _
                         hWndForm      As Dword _  ' handle of Form
                         ) As Long     
                         
    ' close dll's here 
sql_Shutdown

End Function   

'------------------------------------------------------------------------------------------------------------------------
Function MAIN_WM_COMMAND ( _
                         hWndForm     As Dword, _  ' handle of Form
                         hWndControl  As Dword, _  ' handle of Control
                         wNotifyCode  As Long,  _  ' notification code
                         wID          As Long   _  ' item, control, or accelerator identifer
                         ) As Long

Select Case wID
    Case IDC_MAIN_MNUSETUP
        DisplayChildForm(1)
        populateSetup()               
    Case IDC_MAIN_MNUconvert
        DisplayChildForm(2)        
    Case IDC_MAIN_MNUEXIT
           FF_CloseForm hWndForm
    End Select
   
           
End Function


'------------------------------------------------------------------------------------------------------------------------
Function DisplayChildForm( ByVal nPageNum As Long ) As Long
   
   Local rc As Rect
   Local x  As Long
   
   ' Hide all of the child pages                     
   For x = LBound(gChildForms) To UBound(gChildForms)
      ShowWindow gChildForms(x), %SW_HIDE
   Next   
   
   ' Display the required page
   GetClientRect HWND_MAIN, rc
   SetWindowPos gChildForms(nPageNum), %HWND_TOP, 0, 0, rc.nRight, rc.nBottom - 80, %SWP_SHOWWINDOW

End Function




Title: Re: using menus
Post by: TechSupport on April 29, 2009, 07:56:02 PM
Hi Shawn,

I think that you have an error in there....  :)

In your WM_CREATE for the "Main" form you are also loading the "Main" form as modeless. Not sure why you would want to do that. I would think that would cause a some type of circular reference.


' Load the child pages (Forms)
gChildForms(0) = main_Show( hWndForm, %FALSE )


Title: Re: using menus
Post by: Shawn Anderson on April 29, 2009, 08:09:35 PM
that was it, thanks