See, this class is really boring, like to sleep in class books do not see, what a simple tutorial? CodePudding user response:
Learn the basic knowledge to write code, from simple to start, difficult to write, is easily understood CodePudding user response:
Talk is being, show me the code! # pragma comment (lib, "user32") # pragma comment (lib, "gdi32") # include & lt; Stdio. H> # include & lt; Windows. H> Int flag=0; LRESULT a CALLBACK WndProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM) { PAINTSTRUCT ps; HDC HDC. The RECT r; HPEN HPEN, op; The switch (the message) { Case WM_CLOSE://Alt + F4 exit The PostQuitMessage (0); break; Case WM_LBUTTONUP: If (flag==0) { flag=1; The InvalidateRect (hWnd, NULL, TRUE); } In case the WM_PAINT: BeginPaint (hWnd, & amp; Ps); HDC=ps. HDC;//the device context to the draw in GetClientRect (hWnd, & amp; R);//Obtain the window 's client rectangle If (flag==1) { Hpen=CreatePen (PS_SOLID, 0, 0 x00FF0000); Op=(HPEN) SelectObject (HDC, HPEN); MoveToEx (HDC, r.l eft + 10, r.t op + 100, NULL); LineTo (HDC, r.r d.light - 10, r. b ottom - 100); SelectObject (HDC, op); DeleteObject (hpen); } EndPaint (hWnd, & amp; Ps); break; Default: Return DefWindowProc (hWnd, message, wParam, lParam); } return 0; } Int WINAPI WinMain (HINSTANCE HINSTANCE, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG MSG={0}; WNDCLASS wc={0}; HBRUSH HBRH; X00ffffff HBRH=CreateSolidBrush (0); Wc. LpfnWndProc=WndProc; The wc. The hInstance=hInstance; Wc. HbrBackground=HBRH; Wc. LpszClassName="minwindowsapp"; Wc. HCursor=LoadCursor (NULL, IDC_ARROW); If (FAILED (RegisterClass (& amp; Wc))) return 1; If (FAILED (CreateWindow (wc) lpszClassName, "Minimal Windows Application," WS_SYSMENU | WS_CAPTION | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, 0, 0, HInstance, NULL))) return 2; While (GetMessage (& amp; MSG, NULL, 0, 0) & gt; 0 { DispatchMessage (& amp; MSG); } DeleteObject (HBRH); return 0; }