Click to See Complete Forum and Search --> : Wm_killfocus & wm_close


s_sagar4u
June 1st, 2009, 06:18 AM
Hi,

I am working on an application in VC++ and Win32. Currently I am having child dialog box on the Parent window. This child dialog has 2-3 Edit box controls and 2 Comboboxes and 2 buttons.
Now, the problem is, whenever user clicks on any of the Edit box (i.e. sets focus on the edit box by clicking on it) and clicks on Close (X) button on the parent window, my application is crashing.

The reason is, whever user clicks on Close button, my application is using DestroyWindow() to destroy the window. But since user has clicked on Edit box, it sends EN_KILLFOCUS message in the queue. This message is coming after I destroy the window. That means there is no handle available for EN_KILLFOCUS to process. That's why eventhough I try to handle this message in the dialog proc, it won't go there.

Please suggest me somthing on this.
Thanks in advance.

Regards,
Sagar

s_sagar4u
June 1st, 2009, 10:35 AM
Hi,

I have also noticed that, though the function uses DestroyWindow(hwnd), it is not going upto WM_DESTROY message case in my dialog proc.
It's crashing before that because of EN_KILLFOCUS message.

Thanks,
Sagar

_Superman_
June 4th, 2009, 05:24 AM
Try calling PeekMessage in a loop with the PM_REMOVE flag till there are no more messages in the queue. You can then call DestroyWindow.

s_sagar4u
June 5th, 2009, 02:49 AM
Try calling PeekMessage in a loop with the PM_REMOVE flag till there are no more messages in the queue. You can then call DestroyWindow.

Thanks for your help Supreman...
I've tried the same. In the while loop i tried to get and remove the message using PM_REMOVE but it didn't work, it just couldn't find the message and got out of the loop...

wigga
June 8th, 2009, 11:22 AM
you have to call enddialog to close dialogs.