user5401362
user5401362

Reputation:

How to detect which button is pressed in windows form message box?

In my windows form application,I want to prompt to user to restart the PC. This is my code:

 if(MessageBox::Show(L"Restart your PC now?", "Attention!", MessageBoxButtons::YesNo, MessageBoxIcon::Question)==::DialogResult::Yes)
{
//restarting pc
     system("c:\\windows\\system32\\shutdown /r /t 10 \n\n");
     system("PAUSE");
}

But this code give me error at ::DialogResult::Yes. I'm following Microsoft documentation. How to solve this?

Upvotes: 0

Views: 123

Answers (1)

Christian.K
Christian.K

Reputation: 49300

Guessing...

It looks like this is .NET code (albeit in C++) in this case the DialogResult type is not defined at global scope, but in the System::Windows::Forms namespace. So, remove the leading :: (or fully qualify it as System::Windows::Forms::DialogResult).

Also note, that there are APIs to restart windows ExitWindowsEx or InitiateShutdownEx. No need to invoke an external program.

Upvotes: 2

Related Questions