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.