Tyler
Tyler

Reputation: 41

MessageBox returning 0 if HWND is bad

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.

Upvotes: 2

Views: 887

Answers (2)

jeffm
jeffm

Reputation: 3151

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.)

Upvotes: 0

chollida
chollida

Reputation: 7894

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.

Upvotes: 9

Related Questions