Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

phil05

Win32 API Help!!!

This topic is 5160 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

I can't get this working... idea is when you execute the program, a message box asks if you want to load or cancel the loading. So I'm new to the IDOK / IDCANCEL stuff. Here's part of the code:
	switch(Msg)
	{
		case WM_CREATE:  MessageBox(NULL, "Do you want to load the window?", "Message", MB_YESNO);
						 
						 switch( LOWORD( wParam ) )		
						 {    
							case IDOK: MessageBox(NULL, "Yes.", "Yes", MB_OK);
									   break;
						    case IDCANCEL: MessageBox(NULL, "No", "No", MB_OK);
										   PostQuitMessage(WM_QUIT);
										   break;
							default: MessageBox(NULL, "Didn't work", "Didn't work", MB_OK);
									 PostQuitMessage(WM_QUIT);
						 }
						 break;   
[edited by - philvaira on May 31, 2004 5:42:58 PM]

Share this post


Link to post
Share on other sites
Advertisement
What the heck is that code doing?

Ignoring the code for the moment, if you want to process the result of the MessageBox(), check it''s return value. If the user presses the OK button, MessageBox() returns IDOK. If the user presses yes, MessageBox() returns IDYES, etc. Look up the MessageBox() documentation for more details.

Share this post


Link to post
Share on other sites
SiCrane, please don't reply if you can't help with the code. You've never been any help to me in your previous posts.

Thank you.

Now the problem is no matter what I click, the default comes on. Why is this, and how can it be solved?

[edited by - philvaira on May 31, 2004 5:49:53 PM]

Share this post


Link to post
Share on other sites
I didn't actually try your code, but I'm assuming the problem you have is that the window isn't created in either case.

This is because when you handle the WM_CREATE message, you are expected to take whatever action is necessary to create the window. In most cases, you pass the request on to DefWindowProc to actually create the window for you and if you don't pass the message on to DefWindowProc, the window isn't created. I think you want something like this:


switch (Msg)
{
case WM_CREATE:
if (MessageBox(hWnd, "Do you want to load the window?", "Message", MB_YESNO) == IDYES)
DefWindowProc(hWnd, Msg, wParam, lParam);
break;


Hope this helps...

[edited by - EvilSteve on May 31, 2004 5:55:39 PM]

Share this post


Link to post
Share on other sites
It''s working, so that''s good. However, when I hit No, the window loads and quits on its own, all taking place in a half of a second. Am I stuck with that?


switch(Msg)
{
case WM_CREATE: if (MessageBox(hWnd, "Do you want to load the window?", "Message", MB_YESNO) == IDYES)
{
DefWindowProc(hWnd, Msg, wParam, lParam);
}
else
{
PostQuitMessage(WM_QUIT);
}

Share this post


Link to post
Share on other sites
quote:
Original post by philvaira
SiCrane, please don''t reply if you can''t help with the code. You''ve never been any help to me in your previous posts.

Thank you.

lol, did you even read what he said?

Share this post


Link to post
Share on other sites
And by the way, what''s the differences with using the two for this code:

DefWindowProc(hWnd, Msg, wParam, lParam);

- and -

return TRUE;

Share this post


Link to post
Share on other sites
quote:
Original post by philvaira
And by the way, what''s the differences with using the two for this code:

DefWindowProc(hWnd, Msg, wParam, lParam);

- and -

return TRUE;


The first is often used in window-proc functions to pass on messages you won''t handle. What I mean is that when you do a switch-case method to test the message you receive against a bunch of ones you do want to handle, sometimes out of the plethora of possible messages you''d get, it might be one you aren''t going to handle in your switch-case code, therefore if the message gets through that part without returning, you can simply do ''return DefWindowProc()'' and windows will use whatever default mechanism to handle that message.

Personally, when I use dialogs, if a message is sent that I don''t want to handle, I''ll just return false, else true if a match is made in switch-case...but that just works for me.

Share this post


Link to post
Share on other sites
Cool, thanks. My last question is if I hit no, it quits fine, but flashes the window really fast and quits. Is that because it''s creating the window no matter what before it quits?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!