I am trying to figure out how to have my program show a second form (login form) automatically, after the main form starts. This form is not a child form.
Post the following code in your main application Form (this is also your Startup Form). Make sure that the Form names and Control names are changed to match the names that you are using in your code. The 'trick' is to do a 'PostMessage' during the WM_CREATE message that triggers the Logon form to show after the main form shows (i.e. after the WM_CREATE message for the main form finishes executing).
%MSG_USER_SHOWLOGON = %WM_USER + 1000
'------------------------------------------------------------------------------------------------------------------------
Function FORM1_WM_CREATE ( _
hWndForm As Dword, _ ' handle of Form
ByVal UserData As Long _ 'optional user defined Long value
) As Long
PostMessage hWndForm, %MSG_USER_SHOWLOGON, 0, 0
End Function
'------------------------------------------------------------------------------------------------------------------------
Function FORM1_CUSTOM ( _
hWndForm As Dword, _ ' handle of Form
wMsg As Long, _ ' type of message
wParam As Dword, _ ' first message parameter
lParam As Long _ ' second message parameter
) As Long
Select Case wMsg
Case %MSG_USER_SHOWLOGON
' Show the Logon Form and process whether the OK or Cancel
' button was pressed. OK returns TRUE, CANCEL returns FALSE.
If frmLogon_Show( hWndForm, %TRUE ) = %FALSE Then
' Close the main Form of the application.
FF_CloseForm hWndForm
End If
End Select
End Function
In your Logon Form code place the following. It only deals with an OK and Cancel button on the Logon form.
'------------------------------------------------------------------------------------------------------------------------
Function FRMLOGON_CMDOK_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
FF_CloseForm hWndForm, %TRUE
End Function
'------------------------------------------------------------------------------------------------------------------------
Function FRMLOGON_CMDCANCEL_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
FF_CloseForm hWndForm, %FALSE
End Function
Thanks, it works just the way I need it to. BTW, where can I find information on how to use the WM_USER messages?
Hi Andy,
The %MSG_USER_SHOWLOGON message is just a simple message that I created. I could have named it anything that I wanted, for example, %ANDY_FLOWERS_MESSAGE. The numbers > %WM_USER are reserved for use by the programmer. I could have set it to %WM_USER + 999 if I wanted to.
Paul, Thanks again for you help. I was able to find the information on how to use the WM_USER messages.