/* example using windows message box */ #include #include #include // declare WindProc LONG FAR PASCAL WindProc(HWND hwnd, // handle of window UINT message, // message WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ); char szWinName[] ="MyWin"; // name of window class //char str[80] ="Sample output"; // holds output string //int X=1, Y=1; // holds screen position /************************** WinMain() *********************************/ int PASCAL WinMain( HINSTANCE hinstCurrent, // handle of current instance HINSTANCE hinstPrevious, // handle of previous instance LPSTR lpszCmdLine, // address of command line int nCmdShow) // show-window type (open/icon) { HWND hwnd; // declare handle for class inst MSG msg; // declare msg WNDCLASS wc; // create inst of WNDCLASS /* DEFINE THE WINDOW CLASS */ wc.style = 0; // style 0=default wc.lpfnWndProc = WindProc; // name of windproc() wc.cbClsExtra = 0; // extra info wc.cbWndExtra = 0; // extra info wc.hInstance = hinstCurrent; // handle to this instance wc.hIcon = LoadIcon(hinstCurrent, "MyIcon"); // icon style // to use built-in //wc.hIcon = LoadIcon(NULL, IDI_EXCLAMATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); // cursor style wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+6); // window colour wc.lpszMenuName = NULL; // menu name NULL = NO MENU wc.lpszClassName = szWinName; /* register the window class */ if (!RegisterClass(&wc)) return FALSE; /* CreateWindow() */ hwnd = CreateWindow(szWinName, // name of window class "Message Boxes", // title WS_OVERLAPPEDWINDOW, // window style eg.(WS_OVERLAPPED | WS_SYSMENU) CW_USEDEFAULT, // x co-ord CW_USEDEFAULT, // y co-ord(0 FILLS SCRN) CW_USEDEFAULT, // width CW_USEDEFAULT, // height(0 FILLS SCRN) NULL, // parent window NULL, // menu hinstCurrent, // handle of this inst NULL // additional args ); /* display the window */ ShowWindow(hwnd, // handle nCmdShow // window maximised / minimised ); UpdateWindow(hwnd); /* create the message loop */ while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); // translates virtual key codes DispatchMessage(&msg); // dispatches message to window } return (int) msg.wParam; // return value of PostQuitMessage } // WinMain /**************************** WindowProc() ******************************/ // Called by Windows // Passed messages from the message queue //////////////// LONG FAR PASCAL WindProc(HWND hwnd, // handle of window UINT message, // message WPARAM wParam, // first message parameter LPARAM lParam) // second message parameter { int response; switch(message) { case WM_RBUTTONDOWN: // process right mouse button press response =MessageBox(hwnd, // handle of parent window "Press One:", // addr of text in message box "Right Button", // addr of title of msgbox MB_ABORTRETRYIGNORE // style of msgbox ); switch(response) { case IDABORT: MessageBox(hwnd, "", "Abort", MB_OK); break; case IDRETRY: MessageBox(hwnd, "", "Retry", MB_OK); break; case IDIGNORE: MessageBox(hwnd, "", "Ignore", MB_OK); break; } case WM_LBUTTONDOWN: // process left mouse button press response =MessageBox(hwnd, "Continue?", "Left Button", MB_ICONHAND | MB_YESNO); switch(response) { case IDYES: MessageBox(hwnd, "Press Button", "Yes", MB_OK); break; case IDNO: MessageBox(hwnd, "Press Button", "No", MB_OK); break; } case WM_DESTROY: // terminate the program PostQuitMessage(0); break; default: // let windows process any messages not handled by switch return DefWindowProc(hwnd, message, wParam, lParam); } // end switch return 0; }; // END OF WINDPROC()