///////////////////////////////////////////////////////////////// // // // minwin.cpp - small windows demo program // // // // Creates a movable, resizable window with title and // // system menu, and a brief message. // // // // Jim Fawcett, 27 July 1998, modified 20 Sep 2000 // // Ref: Programming Windows, Fifth Edition, Charles Petzold // // Microsoft Press, 1999 // ///////////////////////////////////////////////////////////////// #include #include HWND hWnd; // handle to window created in InitInstance HANDLE hInst; // handle to current module //----< process windows messages >----------------------------- LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hDC; // device context RECT rect; // will hold dimensions of client area PAINTSTRUCT ps; // used by Windows to hold painting information const char *msg1 = "CSE681 - Software Modeling and Analysis"; const char *msg2 = "Hello World"; switch(message) { case WM_PAINT : hDC = BeginPaint(hWnd,&ps); GetClientRect(hWnd,&rect); DrawText( hDC,msg2,strlen(msg2),&rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER ); TextOut(hDC,30,30,msg1,strlen(msg1)); MoveToEx(hDC,25,50,NULL); LineTo(hDC,315,50); EndPaint(hWnd, &ps); break; case WM_LBUTTONDOWN: MessageBox( hWnd,"left mouse button clicked","Response to WM_LBUTTON",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) { hInst = hInstance; hWnd = CreateWindow( "BasicWindow", // "class" to use when creating "CSE681 - Basic Window", // window title WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // default horizontal position CW_USEDEFAULT, // default vertical position 400, // 200 pixels wide 300, // 150 pixels high // 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); }