// definition of windows.h application file contains the desired data type and data structure #include <windows.h> #include <stdlib.h> #include <time.h> LRESULT CALLBACK the WndProc (the HWND, UINT, WPARAM, LPARAM); // window function description // --------- following initialization window class -------------- int WINAPI the WinMain (hInstance the hINSTANCE, the hINSTANCE hPrevInst, LPSTR the lpszCmdLine, int the nCmdShow) { the HWND HWND; the MSG Msg; the WNDCLASS WNDCLASS; char , lpszClassName [] = " window " ; // window class name char lpszTitle [] = " My_Windows " ; // window title name // window class definition wndclass.style = CS_HREDRAW | CS_VREDRAW; // window type is the default type wndclass.lpfnWndProc = the WndProc; // window handler for the WndProc wndclass.cbClsExtra = 0 ; // window class None extended wndclass.cbWndExtra = 0 ; // window instance no extension wndclass.hInstance = hInstance; // this instance handle wndclass.hIcon = the LoadIcon (NULL, IDI_APPLICATION); // minimized icon in the window to the default icon wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); // window using the cursor arrow = wndclass.hbrBackground (HBRUSH) the GetStockObject (WHITE_BRUSH); // window background is white wndclass.lpszMenuName = NULL; // window no menu wndclass.lpszClassName =, lpszClassName; // window class named "sample window" // - be --------- following registration window class IF (! the RegisterClass (& WNDCLASS)) // if the registration fails sound an alarm sound Gao { the MessageBeep ( 0 ); return FALSE; } // create a window HWND = the CreateWindow ( lpszClassName, // window class name lpszTitle, // title name of the window instance WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, CW_USEDEFAULT, // upper left corner of the window coordinates to the default value CW_USEDEFAULT, CW_USEDEFAULT, // window of Gao and wide to the default value NULL, // the window no parent window NULL, // this window without main menu hInstance, // create the window of the application currently handle NULL // do not use this value ); ShowWindow (hwnd, nCmdShow); //Display window the UpdateWindow (HWND); // draw a user area the while (the GetMessage (& Msg, NULL, 0 , 0 )) // message loop { TranslateMessage ( & Msg); the DispatchMessage ( & Msg); } return msg.wParam; // program termination information back to the system } // window function LRESULT CALLBACK the WndProc (the HWND the hWnd, UINT message, WPARAM the wParam, LPARAM the lParam) { the HDC the hDC; HBRUSH hBrush; the RECT RECT; HPEN HPEN; the PAINTSTRUCT PTSTR; static int i = 0; COLORREF color[7] = {RGB(255,0,0), RGB(255,165,0), RGB(255,255,0), RGB(0,255,0), RGB(0,255,255), RGB(0,0,255), RGB(139,0,255)}; switch(message) { case WM_PAINT: GetClientRect(hWnd, &rect); hDC = BeginPaint(hWnd, &PtStr); hBrush = CreateSolidBrush(color[i]); SelectObject(hDC, hBrush); Rectangle(hDC, rect.left, rect.top, rect.right, rect.bottom); i++; Sleep(500); if (i == 7) i = 0; InvalidateRect(hWnd, NULL, 1); DeleteObject(hBrush); EndPaint(hWnd, &PtStr); return 0 ; Case the WM_DESTROY: PostQuitMessage ( 0 ); // calls PostQuitMessage WM_QUIT message sent return 0 ; default : return the DefWindowProc (the hWnd, Message, the wParam, the lParam); // use the system default message handler default } }