/* skeletal windoze prog */ #include #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[] ="WinClock"; // name of window class char str[80] =""; // 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+1); // 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 "Win Clock", // title WS_OVERLAPPEDWINDOW, // window style eg.(WS_OVERLAPPED | WS_SYSMENU) 1, // x co-ord 1, // y co-ord(0 FILLS SCRN) 180, // width CW_USEDEFAULT is default 50, // 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 ); /* start timer */ SetTimer(hwnd, // handle of window for timer messages 1, // timer id 1000, // time-out duration 1 sec = 1000 NULL); // instance add of timer procedure UpdateWindow(hwnd); /* create the message loop */ while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); // translates virtual key codes DispatchMessage(&msg); // dispatches message to window } KillTimer(hwnd,1); // stop timer 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; struct tm* newtime; time_t t; switch(message) { /* 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_TIMER: // timer went off t =time(NULL); newtime =localtime(&t); // get new time /* display new time */ strcpy(str, asctime(newtime)); str[strlen(str)-1] ='\0'; // remove/r/n InvalidateRect(hwnd, NULL, 0); // update scrn 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()