/////////////////////////////////////////////////////////////// // // // minwin.cpp - small windows demo program // // // // Creates a movable, resizable window with title and // // system menu, but no contents. // // // // Jim Fawcett, 27 July 1998, modified 15 Sep 1998 // // adapted for Visual C++, ver 6.0 from: // // MFC Internals, Shepard and Wingo, Addison-Wesley, 1996 // // // /////////////////////////////////////////////////////////////// #include HANDLE hInst; // handle to current window //----< process windows messages >----------------------------- LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_LBUTTONDOWN: MessageBox(hWnd,"left mouse button clicked","demo",MB_OK); break; case WM_DESTROY: PostQuitMessage(0); break; default : return(DefWindowProc(hWnd,message, wParam, lParam)); } return (NULL); } //----< define and register window "class" >------------------- BOOL InitApplication(HINSTANCE hInstance) { // define window data in WNDCLASS struct and register WNDCLASS wc; wc.style = NULL; // default style wc.lpfnWndProc = WinProc; // name of function handling messages wc.cbClsExtra = 0; // no per-class user-defined data wc.cbWndExtra = 0; // no per-window user-defined data wc.hInstance = hInstance; // application attached to this class wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; // menu name wc.lpszClassName = "BasicWindow"; // name of this "class" return (RegisterClass(&wc)); } // //----< create and display window >---------------------------- BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { // HWND hWnd; hInst = hInstance; hWnd = CreateWindow( "BasicWindow", // "class" to use when creating "CSE691 - Basic Window", // window title WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // default horizontal position CW_USEDEFAULT, // default vertical position CW_USEDEFAULT, // default width CW_USEDEFAULT, // default height NULL, // no parent window NULL, // use window class menu hInstance, // owner of window NULL); if(!hWnd) return FALSE; ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return (TRUE); } //----< collect and dispatch windows messages >---------------- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; if(!hPrevInstance) { // is this first instance? if(!InitApplication(hInstance)) // return (FALSE); // can't initialize window } if(!InitInstance(hInstance, nCmdShow)) return (FALSE); while(GetMessage(&msg, NULL, NULL, NULL)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (msg.wParam); }