// definition of data types and data structures windows.h file contains the desired application #include <windows.h> #include <stdlib.h> #include <time.h> #include " menu_1.h " # the include <math.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, the lpszCmdLine LPSTR, 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 the CS_HREDRAW = | CS_VREDRAW; // window type is the default type wndclass.lpfnWndProc = the WndProc; // window handler for the WndProc WNDCLASS. = cbClsExtra 0 ; // window class without extension wndclass.cbWndExtra = 0 ; // window instance no extension wndclass.hInstance = hInstance; // this instance handle wndclass.hIcon = the LoadIcon (NULL, IDI_APPLICATION); // minimized window icon is the default icon = the LoadCursor wndclass.hCursor (NULL, IDC_ARROW); // window using the cursor arrow wndclass.hbrBackground = (HBRUSH) the GetStockObject (WHITE_BRUSH); // window background is white wndclass.lpszMenuName = " the MENU1 " ; // window no menu wndclass =, lpszClassName .lpszClassName; // window class named "sample window" // ----------- the register window classes IF (! the RegisterClass (& WNDCLASS)) // if the registration fails issuing warnings Gao sound { the MessageBeep ( 0 ); return FALSE; } // Create 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, // Gao and wide to the default value of the window NULL, // the window no parent window NULL, // the window without the main menu hInstance, // create this window applications currently handles NULL // do not use this value ); the ShowWindow (HWND, the 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 } #define the LR (+ rect.left rect.right) #define TD (rect.bottom+rect.top) #define R 50 #define PI acos(-1) //窗口函数 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hDC; HBRUSH hBrush; RECT rect; HPEN hPen; PAINTSTRUCT PtStr; POINT p; static bool isTria = false, isCir = false, isTex = false; 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_COMMAND: switch(LOWORD(wParam)) { case IDM_DRAW_CIR: isCir = true; InvalidateRect(hWnd, NULL, 1); return 0; case IDM_DRAW_TRI: isTria = true; InvalidateRect(hWnd, NULL, 1); return 0; case IDM_DRAW_TEX: isTex = true; InvalidateRect(hWnd, NULL, 1); return 0; } return 0; case WM_CREATE: return 0; case WM_PAINT: GetClientRect(hWnd, &rect); hDC = BeginPaint(hWnd, &PtStr); GetClientRect(hWnd,&rect); if (isCir) { hPen = CreatePen(PS_SOLID, 5, color[2]); SelectObject(hDC, hPen); Ellipse(hDC, (rect.right+rect.left)/2-100, (rect.bottom+rect.top)/2-100, (rect.right+rect.left)/2+100, (rect.bottom+rect.top)/2+100); DeleteObject(hPen); isCir = false; } else if (isTria) { hPen = CreatePen(PS_SOLID, 5, color[5]); SelectObject(hDC, hPen); MoveToEx(hDC, (rect.right+rect.left)/2, (rect.bottom+rect.top)/3,NULL); LineTo(hDC, (rect.right+rect.left)*2/3, (rect.bottom+rect.top)*2/3); LineTo(hDC, (rect.right+rect.left)/3, (rect.bottom+rect.top)*2/3); LineTo(hDC,(rect.right+rect.left)/2, (rect.bottom+rect.top)/3); DeleteObject(hPen); isTria = false; } else if (isTex) { SetTextColor(hDC, color[0]); DrawText(hDC, "我爱学VC++", -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); isTex = false; } Of EndPaint (the 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 default system messages The default handler } }