Blokout1 in Windows Programming

Source: Internet
Author: User
Lresult callback (hwnd, uint message, wparam, lparam) {static bool fblocking, fvalidbox; static point ptbeg, ptend, terminal, ptboxend; HDC; paintstruct pS; switch (Message) {Case wm_lbuttondown: ptbeg. X = ptend. X = loword (lparam); ptbeg. y = ptend. y = hiword (lparam); drawboxoutline (hwnd, ptbeg, ptend); // set the cursor to idc_cross, indicating that the rectangle setcursor (loadcursor (null, idc_cross) is being drawn )); // flag. True indicates that fblocking = true; return 0; Case wm_mousemove: If (fblocking) {// when the mouse moves, set the cursor to idc_crosssetcursor (loadcursor (null, idc_cross); // when the following line is commented, move the mouse to display the following figure drawboxoutline (hwnd, ptbeg, ptend); ptend. X = loword (lparam); ptend. y = hiword (lparam); // the following line also displays the following figure: drawboxoutline (hwnd, ptbeg, ptend);} return 0; Case wm_lbuttonup: If (fblocking) {drawboxoutline (hwnd, ptbeg, ptend); // used to save the final rectangle ptboxbeg = ptbeg; ptboxend. X = loword (lparam); ptboxend. y = hiword (lparam); // setcursor (loadcursor (null, idc_arrow); fblocking = false; fvalidbox = true; // call wm_paintinvalidaterect (hwnd, null, true);} return 0; Case wm_char: // x1b is ESC, implementation effect, when painting, if (fblocking & (wparam = '\ x1b') {drawboxoutline (hwnd, ptbeg, ptend); setcursor (loadcursor (null, idc_arrow )); fblocking = false;} return 0; Case wm_paint: HDC = beginpaint (hwnd, & PS); // This is the final rectangle if (fvalidbox) when the mouse is released) {SelectObject (HDC, getstockobject (black_brush); rectangle (HDC, ptboxbeg. x, ptboxbeg. y, ptboxend. x, ptboxend. y);} // This is the effect of moving the mouse after clicking the left button, but it is not called when the mouse moves. I know it is useless/* If (fblocking) {setrop2 (HDC, r2_not); SelectObject (HDC, getstockobject (null_brush); rectangle (HDC, ptbeg. x, ptbeg. y, ptend. x, ptend. y);} */endpaint (hwnd, & PS); Return 0; Case wm_destroy: postquitmessage (0); Return 0;} return defwindowproc (hwnd, message, wparam, lparam );}

AboveCodeTwo questions have not been clarified:

There are two drawboxoutline lines in lines 25---30. I tried to remove either of them, but the effect would be like this.

I think it should be related to wm_mousemove, and it cannot always be appropriate.

Line 66-----72 of the Code removed me. I don't know it because wm_paint is not called in wm_mousemove, And that code should not be executed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.