Display MessageBox in Console App
Messagebox dialog can only be shown, if the application has code to receive events. Here is the snippet to display a message box in a console application.
/* snippet to show messagebox in console app
*
*/
#include "stdafx.h"
#include <fstream>
#include <windows.h>
#pragma comment(lib, "kernel32.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "gdi32.lib")
int _tmain(int argc, _TCHAR* argv[])
{
std::wofstream fs("testout.txt");
const wchar_t* txt = L"some Unicode text §";
MessageBoxW(0,txt,L"verify",MB_OK);
fs << txt << std::flush;
MessageBoxW(0,fs.good()? L"Good": L"Bad",L"verify",MB_OK);
return 0;
}
No comments
Post a Comment