/* skeletal windoze prog */ #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 */ if (!RegisterClass(&wc)) return FALSE; /* CreateWindow() */ hwnd = CreateWindow(szWinName, // name of window class "Liane's App", // 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 { HDC hdc; PAINTSTRUCT paintstruct; switch(message) { /* process keypress */ case WM_CHAR: X=Y=1; // displays in top left cnr sprintf(str,"%c", (char) wParam); // stringsize character /* adds a rectangle to a window's update region generates a WM_PAINT message */ InvalidateRect(hwnd, // window handle NULL, // address of struct with rectangle type RECT 1 // erase background flag ); break; /* process WM_PAINT message */// occurs each time window resized etc. case WM_PAINT: hdc= BeginPaint(hwnd, &paintstruct); // get dc TextOut(hdc,X,Y,str,strlen(str)); EndPaint(hwnd, &paintstruct); // release dc break; case WM_RBUTTONDOWN: // process right mouse button press strcpy(str,"Right button down"); X =LOWORD(lParam); // set to current mouse location Y =HIWORD(lParam); // set to current mouse location /* updates specified window rectangle */ // generates a WM_PAINT message InvalidateRect(hwnd, // window handle NULL, // address of RECT struct 1); // erase bground flag break; case WM_LBUTTONDOWN: // process left mouse button press strcpy(str,"Left button down"); X =LOWORD(lParam); // set to current mouse location Y =HIWORD(lParam); // set to current mouse location /* updates specified window rectangle */ // generates a WM_PAINT message InvalidateRect(hwnd, // window handle NULL, // address of RECT struct 1); // erase bground flag 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()