Hi,
I have a problem, i have a form which when you press a button another form is displayed in front, this works fine but whenever i press the close button on the popup form (A button I made) both forms are closed.
I have tried it lots of different ways and it makes no difference, has anybody had this problem or could tell me where i could be going wrong?
Thanks :)
Can you show the code you are using to (1) Show the second "popup" form, and (2) the code you're calling to close the second form.
To display the second popup form use something like:
FORM2_SHOW hWndForm, %TRUE ' show the second "popup" form in modal mode
- or -
FORM2_SHOW HWND_FORM1, %TRUE ' show the second "popup" form in modal mode
To close the second form, respond to your close button with something like this:
FF_CloseForm hWndForm
- or -
FF_CloseForm HWND_FORM2
Thanks for the quick reply, i'm miles away today and completely forgot the actual problem i was having.
Pressing the button closes the form correctly but i wanted to be able to press the escape key to close the form (or any key really)
i use the same functions you mentioned above and this code (i have a textbox which has focus):
Function FORM1_TEXT1_CUSTOM ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
wMsg As Long, _ ' type of message
wParam As Dword, _ ' first message parameter
lParam As Long _ ' second message parameter
) As Long
Select Case wMsg
Case %WM_GETDLGCODE
Function = %DLGC_WANTALLKEYS
Exit Function
Case %WM_KEYDOWN
Select Case wParam
Case %VK_ESCAPE
FF_CloseForm HWND_POPUP
End Select
End Select
End Function
Thanks for your help :-)
Hi,
Has anybody got any ideas with this?
I still haven't got a solution
Any suggestions what be most appreciated.
Thanks
Hi,
On the second Form, create a Command Button and set it's "Cancel" property equal to "True". If you don't want the Command Button to be visible then uncheck the "WS_VISIBLE" style in the "WindowStyles".
Now, when you show your popup Form and the TextBox has focus, pressing the "ESC" key will cause the default button with the "Cancel" property set to fire - in this case, the Command Button which has FF_CloseForm in it's BN_CLICKED message handler.
I created a simple demo project and the above logic seems to work okay.
Hope it works for you and solves your problem.
Wait a second.... Your TextBox - is it on the main form or the second popup Form? I'm looking at your code snippet and it would suggest that it is on the main Form.
Is this what you're trying to do:
You have a main Form with a TextBox on it. As you are typing in the TextBox, you press ESC in order to close a second popup Form?
If that is the case then you were on the right track, however, instead of WM_KEYDOWN put your code in WM_KEYUP.
Function FORM1_TEXT1_WM_KEYUP ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle in Control
nVirtKey As Long, _ ' virtual key code
lKeyData As Long _ ' key data
) As Long
Select Case nVirtKey
Case %VK_ESCAPE
FF_CloseForm HWND_POPUP
End Select
End Function
Thanks for the help again, unfortuantely it has not fixed it.
My textbox is on the popup form, the problem is when i put the custom event handler in.
If i don't use the custom event the default button works fine.
But as soon as i put the custom handler in it handles the escape key itself.
If i don't put anything in for escape it does nothing and if i put close form for escape key my app crashes.
Any ideas?
Thanks
OK, I think I see the problem. I experienced the GPF like you describe. I am pretty sure it is because we are closing the Form in the middle of the WM_KEYUP message firing. To fix that, we need to let the WM_KEYUP finish prior to closing the Form by Posting a message to the main Form's CUSTOM handler and close the Form there instead. The code below works perfectly. Notice the PostMessage in the TextBoxes CUSTOM handler that posts a user defined message to the Form's CUSTOM message handler.
%MSG_CLOSE_FORM = %WM_USER + 100
'------------------------------------------------------------------------------------------------------------------------
Function POPUP_TEXT1_CUSTOM ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
wMsg As Long, _ ' type of message
wParam As Dword, _ ' first message parameter
lParam As Long _ ' second message parameter
) As Long
Select Case wMsg
Case %WM_GETDLGCODE
Function = %DLGC_WANTALLKEYS
Exit Function
Case %WM_KEYDOWN
Select Case wParam
Case %VK_ESCAPE
PostMessage hWndForm, %MSG_CLOSE_FORM, 0, 0
End Select
End Select
End Function
'------------------------------------------------------------------------------------------------------------------------
Function POPUP_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_CLOSE_FORM ' user defined message to close Form
FF_CloseForm HWND_POPUP
End Select
End Function