Windows programming question....

Started by
5 comments, last by jim bob 23 years, 5 months ago
Hello again. I never did this particular Win32 type of program before, so I wasn''t sure on what to do. I want to create a simple heirachy based app for Windows(32). I know how to do most of it, but I had a question. Here is some test code I already wrote:
    
#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <windowsx.h>

int WINAPI WinMain(HINSTANCE hinstance,
				   HINSTANCE hprevinstance,
				   LPSTR lpcmdline,
				   int ncmdshow)

{
	MessageBox(NULL, "ARE YOU COOL?",
		"COOLNESS",
		MB_YESNO | MB_ICONQUESTION);
	if (..........)
	{
		MessageBox(NULL, "HA! YEAH RIGHT!",
		"COOLNESS",
		MB_OK | MB_ICONEXCLAMATION);
	}
	if (..........)
	{
		MessageBox(NULL, "YEAH, THAT''S WHAT I THOUGHT!",
		"COOLNESS",
		MB_OK | MB_ICONEXCLAMATION);
	}

	return(0);
}
    
I wanted to use IF statements with YES or NO boxes, that lead to something else depending on what you pick. Can I use IF statements like this? If so, what do I put in the IF statement that branches out to different places depending on what you pick. I knew it wouldn''t work, but I tried: . . . if (YES) { . . . } But it didn''t work, so what do I do? Thanks a lot! I am not worthy of a sig! ;)
I am not worthy of a sig! ;)
Advertisement
If you want to know how to get the return value of MessageBox(), do this:

    int Result = MessageBox(...);if(Result == IDYES){     // handle "yes" here}else{     // handle "no" here}     


get the idea?

Visit my site!

Edited by - SHilbert on October 29, 2000 3:59:53 PM
Thanks, I think I get it. One question, why use an IF and an ELSE? Can''t you just use an IF and another IF? What and why is the point and reason for that?

I now have this:

    #define WIN32_LEAN_AND_MEAN#include <windows.h>#include <windowsx.h>int WINAPI WinMain(HINSTANCE hinstance,				   HINSTANCE hprevinstance,				   LPSTR lpcmdline,				   int ncmdshow){	MessageBox(NULL, "ARE YOU COOL?",		"COOLNESS",		MB_YESNO | MB_ICONQUESTION);		int Result = MessageBox(NULL, "ARE YOU COOL?",		"COOLNESS",		MB_YESNO | MB_ICONQUESTION);	if(Result == IDYES)	{     		// handle "yes" here		MessageBox(NULL, "HA! YEAH RIGHT! DON''T YOU WISH!",		"COOLNESS",		MB_OK | MB_ICONEXCLAMATION);	}	if(Result == IDNO)	{     		// handle "no" here		MessageBox(NULL, "YEAH, THAT''S WHAT I THOUGHT!",		"COOLNESS",		MB_OK | MB_ICONEXCLAMATION);	}	return(0);}    


It compiles fine, but the execution repeats the question and acts weird. Why and how can I fix it?
Also, where can you get all this info and commands? Is there any good and free tutorials on the internet? I am a really good C++ programmer, and program games, but I never really worked to much right with Windows like this. I get most of it, but jus need a few odd-ball questions cleared up. Thanks again.

I am not worthy of a sig! ;)
I am not worthy of a sig! ;)
Its good to have if else statements because if you are testing a variable and you just have a bunch of if statements, it will test all of them even though the first if statement could have been true. If you have if else statements, it will stop testing at the first true one it finds. Hope this is right.

thanks

Edited by - saisoft on October 29, 2000 4:20:49 PM
Oh ok, makes sense.

But what is wrong with my code that it repeats itself?

I am not worthy of a sig! ;)
I am not worthy of a sig! ;)
Jim Bob, the reason why everything is happening twice is because you are executing each messagebox twice, this is how it works.

This will run your Messagebox once, but not store the result:
MessageBox(NULL, "ARE YOU COOL?","COOLNESS",MB_YESNO|MB_ICONQUESTION);


This will also run your Messagebox, but store the result:
int Result = MessageBox(NULL,"ARE YOU COOL?","COOLNESS",MB_YESNO|MB_ICONQUESTION);

So instead of having both of these just have the one that stores the result, so your modified code would look like this:


#define WIN32_LEAN_AND_MEAN
#include
#include
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline,int ncmdshow)

{

int Result = MessageBox(NULL, "ARE YOU COOL?", "COOLNESS",MB_YESNO | MB_ICONQUESTION);
if(Result == IDYES)
MessageBox(NULL, "HA! YEAH RIGHT! DON''T YOU WISH!","COOLNESS", MB_OK | MB_ICONEXCLAMATION);

else if(Result == IDNO)
MessageBox(NULL, "YEAH, THAT''S WHAT I THOUGHT!", "COOLNESS",MB_OK | MB_ICONEXCLAMATION);
return(0);
}


Ahhhhhh! DUH! Thanks a lot guys. I never deleted the code from the first version when I had to modify it, hello?!?!?!? But thanks, works cool now. BTW, that is not my program, just a test!

I am not worthy of a sig! ;)
I am not worthy of a sig! ;)

This topic is closed to new replies.

Advertisement