Home > Software engineering >  Windows SDK programming related, could you tell me how to after the left key click on the window aut
Windows SDK programming related, could you tell me how to after the left key click on the window aut

Time:09-21

Line drawing is no problem, but always appears on the screen directly, how to display it after left click? Just learning Windows programming, there are many do not understand, if there is a tutorial recommended is better,

CodePudding user response:

Left click? Click on the? Button?

CodePudding user response:

reference 1st floor schlafenhamster response:
left click? Click on the? Button?

Left key point window directly, and then let the straight line,

CodePudding user response:

//case WM_LBUTTONDOWN:
//OutputDebugString (" Main WM_LBUTTONDOWN \ n ");
//break;
Case WM_LBUTTONDBLCLK:
//MessageBeep (110);
//break;

The response message

CodePudding user response:

With a global variable to remember ever draw a straight line,

CodePudding user response:

No clear after drawing, of course, will always be displayed

CodePudding user response:

Sun Xin "vc + + in-depth explanation", if you want to understand in detail, the Hou Jie "a simple MFC
"People who do not buy a book to learn is a fool

CodePudding user response:

If you Resize the window or other Windows after operation, no reservation after drawing a straight line, can draw in the WM_LBUTTONUP
Otherwise, need to save the drawing parameters when LBUTTONDOWN to an array (or other data structure), and then call InvalidateRect, draw the unified operation in the WM_PAINT

CodePudding user response:

refer to 7th floor worldy response:
if you Resize the window or other Windows, without reservation after drawing a straight line, can draw in the WM_LBUTTONUP
Otherwise, when need LBUTTONDOWN will save drawing parameters to an array (or other data structure), and then call InvalidateRect, draw operation unified in the WM_PAINT

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;
}
  • Related