Dave's Brain

Browse - programming tips - win32 yes no question

Date: 2008jun7
Platform: win32
Language: C/C++
Level: beginner

Q.  How do I ask the user a yes/no question in win32?

A.  Use the MessageBox() function with flag MB_YESNO.  It will popup
a dialog.  If the user clicks on "Yes" you get IDYES back
and it they click on "No" you get IDNO back.  There is a parameter
for the caption where the program name traditionally goes.
So we can make this handy little function:

BOOL YesNo(const HWND hwnd, LPCSTR szQuestion, LPCSTR szProgramName)
{
	return MessageBox(hwnd, szQuestion, szProgramName, MB_YESNO) == IDYES;
}

void ExampleUse(const HWND hwnd)
{
	if (YesNo(hwnd, "Do you want to delete that file?", "My Program"))
	{
		DeleteFile("c:\\temp\\myfile.txt");
	}
}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Advertisements: