Jump to content
  • Advertisement
Sign in to follow this  

MessageBox

This topic is 4313 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
We can help you, but you must ask a question first. We don't have access to your computer, so we have no idea about your code or these errors you talk about.

Share this post


Link to post
Share on other sites
Hello,

Heres a little basic message box example:


#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd)
{
MessageBox(NULL, "Hello World",
"Title", MB_OK | MB_ICONINFORMATION);

if (MessageBox(NULL, "Do you like cereal", "Do You?",
MB_YESNO | MB_ICONQUESTION) == IDYES)
MessageBox(NULL, "I bet you LOVE cereal", "Yes", MB_OK);
else
MessageBox(NULL, "I guess you like cofee.", "You Answered No!", MB_OK);

return 0;
}


Hope it helps [smile]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Are you using visual studio 2005 and getting an error along the lines of:
cannot convert parameter from 'char [1000]' to 'LPWSTR'

Go to project | properties and in the tree on the left click configuration properties. Then in the right goto character set and change it to use multi-byte character set.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mike2343
You shouldn't use NULL, but instead the HWND from your main or current window.


Definately. You shouldn't use NULL if you want the message box to operate modally i.e. not allow you to click on or move the calling window before the message box has gone, which certainly is the normal behaviour.

If you use NULL, the message box has no parent window and will just exist until one of its buttons is clicked or the application terminates since, as far as I can see, there would be no way to send a message to it to close it manually.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
the window created for the message box belongs to your app's thread that called the api function, and therefore will be automatically destroyed when that thread is terminated. i've also used NULL for my message box's "parent" hwnd for years in hundreds of apps used worldwide w/o any problems.

Share this post


Link to post
Share on other sites
AP - so how would you programatically close a message box without a parent window? Surely once it has been created, it is going to be hanging around until the user clicks one of its buttons, or the thread that called it terminated?

Message boxes are designed to be modal. If you have a realistic example of when you would want a message box to operate modelessly, I'd be interested to hear it and will happily eat my words.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!