Another question

Started by Gary Stout, February 06, 2015, 08:28:33 PM

Previous topic - Next topic

Gary Stout

Here is my scenario,
I have a zipcode field that checks to see if more than 1 town exists when either <TAB> or <ENTER> is pressed for the same zipcode. If more than 1 town is found, I need to popup a small form in a particular place on the parent form. I am not sure how to open the secondary form or how to position it in a fixed location on the parent form. Would this need to be a child form or a popup form? It definitely needs to be modal and will close once a selection is made.

Any pointers would be appreciated....
Thanks,
Gary

Klaas Holland

When you want to create a new Form on top of another:

'--------------------------------------------------------------------------------
Function FORMT1_COMMAND1_BN_CLICKED ( _
                                    ControlIndex     As Long,  _  ' index in Control Array
                                    hWndForm         As Dword, _  ' handle of Form
                                    hWndControl      As Dword, _  ' handle of Control
                                    idButtonControl  As Long   _  ' identifier of button
                                    ) As Long

    Local Txt       As String

    FormT1A_Show hWndForm, %FALSE
    FF_Control_Disable HWND_FORM1

End Function


'--------------------------------------------------------------------------------
Function FORMT1A_WM_CREATE ( _
                           hWndForm As Dword, _      ' handle of Form
                           ByVal UserData As Long _  ' optional user defined Long value
                           ) As Long

    Local rc As Rect

    FF_Control_GetLoc HWND_FORM1, rc.nLeft, rc.nTop
   
    FF_Control_SetLoc HWND_FORMT1A, rc.nLeft + 480, rc.nTop + 250
   
   

End Function


'--------------------------------------------------------------------------------
Function FORMT1A_WM_CLOSE ( _
                        hWndForm As Dword _  ' handle of Form
                        ) As Long

    Local Txt       As String

    FF_CloseForm HWND_FORMT1A
    FF_Control_Enable HWND_FORM1

End Function







Another possibility is to just let a Listbox popup:



'--------------------------------------------------------------------------------
Function FORM1_TEXT1_EN_CHANGE ( _
                               ControlIndex   As Long,  _  ' index in Control Array
                               hWndForm       As Dword, _  ' handle of Form
                               hWndControl    As Dword, _  ' handle of Control
                               idTextControl  As Long   _  ' identifier of text control
                               ) As Long

    FF_Control_ShowState HWND_FORM1_LIST1, %SW_SHOW

End Function


'--------------------------------------------------------------------------------
Function FORM1_LIST1_LBN_SELCHANGE ( _
                                   ControlIndex  As Long,  _  ' index in Control Array
                                   hWndForm      As Dword, _  ' handle of Form
                                   hWndControl   As Dword, _  ' handle of Control
                                   idListBox     As Dword  _  ' identifier of listbox
                                   ) As Long

    Local Txt      As String
    Local RowNr    As Long

    FF_ListBox_GetCurSel HWND_FORM1_LIST1 To RowNr   
    FF_ListBox_GetText HWND_FORM1_LIST1, RowNr To Txt     
    FF_ComboBox_FindString HWND_FORM1_COMBO1, -1, Txt To RowNr
    FF_ComboBox_SetCurSel HWND_FORM1_COMBO1, RowNr

    gDebNr = Val(Mid$(Txt,1,4))
    GetDebiteur 1

End Function


'--------------------------------------------------------------------------------
Function FORM1_LIST1_LBN_KILLFOCUS ( _
                                   ControlIndex  As Long,  _  ' index in Control Array
                                   hWndForm      As Dword, _  ' handle of Form
                                   hWndControl   As Dword, _  ' handle of Control
                                   idListBox     As Dword  _  ' identifier of listbox
                                   ) As Long

    FF_TextBox_SetText HWND_FORM1_TEXT1, ""

    FF_Control_ShowState HWND_FORM1_LIST1, %SW_HIDE

End Function





Paul Squires

Hi Gary,

I am assuming that all you want to do is display a popup form relatively placed to a control on your form. The trick is two fold because you want to display a modal popup form but you also want to reposition that form before it displays. Here is one way that I used:

Example: Display the popup to the immediate right of a Command button on the main form.

'--------------------------------------------------------------------------------
Function FORM1_COMMAND1_BN_CLICKED ( _
                                   ControlIndex     As Long,  _  ' index in Control Array
                                   hWndForm         As Dword, _  ' handle of Form
                                   hWndControl      As Dword, _  ' handle of Control
                                   idButtonControl  As Long   _  ' identifier of button
                                   ) As Long
   
   ' Display the popup form.
   frmPopup_Show( hWndForm, %TRUE, HWND_FORM1_COMMAND1 )
   

End Function


As you can see, we are passing the handle of the Command Button to the popup form during creation. In the popup form we would see that window handle via UserData in WM_CREATE.


'--------------------------------------------------------------------------------
Function FRMPOPUP_WM_CREATE ( _
                            hWndForm As Dword, _      ' handle of Form
                            ByVal UserData As Long _  ' optional user defined Long value
                            ) As Long

   ' UserData represents the handle of the control that we want to
   ' position this popup form next to.
   Dim rc As Rect
   GetWindowRect userdata, rc   ' use window/screen coordinates
   
   ' Position the form
   SetWindowPos hWndForm, 0, rc.nRight, rc.nTop, 0, 0, %SWP_NOZORDER Or %SWP_NOSIZE
   
End Function


Take note that I am using GetWindowRect rather than GetClientRect to get the position of the Command Button. That just saves a step from having to GetClientRect and then convert them to screen coordinates (because when displaying the popup form you will need to use screen coordinates because it is not a child form).

I used SetWindowPos to do the positioning. It is such a versatile function that I use it for just anything related to positioning, sizing or window placement.

Lastly, ensure that the Property called "StartupPosition" is set to "0 - False" for the frmPopup.
Paul Squires
PlanetSquires Software

Gary Stout

Thanks Paul and Klaas for the suggestions!

I think I have decided on the Listbox approach...the form idea seemed like more work than necessary for what I was using it for. Having a hidden Listbox appear with the data for multiple citys seems to work great and once a selection is made, it disappears....very nice!

The form approach was basically a small form with only a listview, but for this purpose, the listbox offers a little more flexibility.

I do have other forms in this project with many more controls and Paul, I think your suggestions for those forms will come in handy.

Thanks again guys for the help,
Gary