views:

139

answers:

3

Is there a case where MessageBox can return 0 other than not enough memory? I have a case where I suspect the HWND I'm passing to MessageBox isn't valid or maybe it belongs to a window that is in the process of being destroyed.

In my case the MessageBox isn't displayed and returns 0, but I seem to have enough memory available.

A: 

Does the problem go away if you pass NULL or GetDesktopWindow() as the HWND parameter? If so, then you are probably correct. You could also try to validate the HWND ahead of time with the IsWindow() or IsWindowVisible() function. (Although I'm not sure if the behaviors of those functions are reliable if the window in question is in the process of being destroyed.)

jeffm
+6  A: 

Is there a case where MessageBox can return 0 other than not enough memory?

From the MSDN documentation:

http://msdn.microsoft.com/en-us/library/ms645505%28VS.85%29.aspx

If the function fails, the return value is zero. To get extended error information, call  GetLastError.

I'd call GetLastError() to see what error code it returns.

chollida
A: 

What does GetLastError() return?

zildjohn01
Why don't you say this in a comment rather than as an answer?!
Time Machine
Because it is the answer, really.
MSalters