messagebox in console program

Started by vedro-compota, October 15, 2011, 03:11:48 PM

Previous topic - Next topic

CommonTater

Hi Stephan;

If you really want to mess with someone...

#include <windows.h>

int main (void)
  { return MessageBox(NULL,"Click Yes or No....","Choose",MB_YESNO | MB_ICONINFORMATION); }


The return value is useable in Batch files (.bat) error levels and can be used to control branching according to the user's input...



TimoVJL

#16
Example using that idea:
// ChooseYesNo.c
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

//int __cdecl WinMainCRTStartup(void)
int __cdecl mainCRTStartup(void)
{
ExitProcess(MessageBox(0, "Yes or No", "Choose", MB_YESNO | MB_ICONINFORMATION));
}
@ECHO OFF
@REM YesNo.bat
@ChooseYesNo.exe
@ECHO %ERRORLEVEL%

@IF NOT ERRORLEVEL 7 GOTO CaseYes

@ECHO No
GOTO TheEnd

:CaseYes
@ECHO Yes
GOTO TheEnd

:TheEnd
@ECHO TheEnd
May the source be with you