Re: CreateWindow never returning



William DePalo [MVP VC++] wrote:
What should I have in my WM_DESTROY handler?

The clean up code that you need to execute when your window is torn down
should be there.

It seems to me that one needs to be very careful if returning from
WM_CREATE with -1. The 'natural' use of this return (certainly the way
I was trying to use it) is to abort the window creation if something
fails during initialisation: in my case it was a failed memory
allocation. However since returning -1 from WM_CREATE causes the code
in WM_DESTROY to be executed, and since that should contain the 'clean
up' code as you say, you'll very likely find yourself trying to 'clean
up' something that has never been dirtied!

This explains why, in my main application, the consequence of returning
-1 from WM_CREATE was more serious than just failing to display a
message box: the entire application froze. I can see now that this was
because of code in WM_DESTROY waiting for a worker thread - that had
never been created - to terminate!

I know it's easy to ctiticise the documentation, but really I think the
comment under WM_CREATE that "the window is destroyed" should more
explicitly state that the code in WM_DESTROY is executed.

I'll continue to use the technique of moving some of my initialisation
into WM_NCCREATE, from which it appears I can return zero without any
problems. That's easier than modifying WM_DESTROY to test that various
elements of WM_CREATE have completed successfully.

Richard.
http://www.rtrussell.co.uk/
To reply by email change 'news' to my forename.

.



Relevant Pages


Quantcast