DestroyWindow...

Hello,

I create a thread A (CreateThread) and this thread creates a window (CreateWindow) and then it processes the GetMessage loop.
This thread creates another thread B which creates also a window and processes the message loop...

Thread A posts a WM_QUIT message (PostMessage) to the window of thread B. Thread B will process the message and it's GetMesage loop ends.
The next command after the loop is DestroyWindow (the same window which was used for GetMessage in the loop) - and this command fail. GetLastError says the handle is invalid (code 6).

Any ideas why?

Daniel
[624 byte] By [daw] at [2007-11-19 7:31:09]
# 1 Re: DestroyWindow...
As far as I know, a window is destroyed when you send a WM_QUIT message. So you don't have to destroy it manually yourself.
Tischnoetentoet at 2007-11-11 0:27:13 >
# 2 Re: DestroyWindow...
When DestroyWindow is commented out, the next command, UnregisterClass fails with error code 1412 (there is already a open window for this class).

greetings,
daniel
daw at 2007-11-11 0:28:13 >
# 3 Re: DestroyWindow...
It would be nice if you can post some code up here. I think it will make it easier for people to help that way.
cloudy at 2007-11-11 0:29:20 >
# 4 Re: DestroyWindow...
Post a WM_CLOSE to the window instead.

In the wndproc, handle WM_CLOSE and do cleanup and call DestroyWindow.
In the WM_DESTROY handler, do a PostQuitMessage..

That should take care of it.
kirants at 2007-11-11 0:30:15 >
# 5 Re: DestroyWindow...
i have a WM_DESTROY event that causes crash, i am out of my mind debugging this.

My application can terminate in 2 ways, in the Menu -> close and X button.
While the application is running the user can terminate the application. I close the application using Menu, the program terminated successfully but I close the application with the X button, a memory access violation is display

the code for the 2 close function are similarly

OnDestroy
{
//save file to INI
PostQuitMessage(0);
}

OnAppExit()
{
//call the OnDestroy
OnDestroy();
}

Is there any other special clean up that should be done for WM_DESTROY function?
ideru at 2007-11-11 0:31:22 >
# 6 Re: DestroyWindow...
Do this instead:

OnDestroy
{
//save file to INI

CBaseClass::OnDestroy();
}

OnAppExit()
{
PostMessage(WM_CLOSE);
}
cilu at 2007-11-11 0:32:21 >