Problem Description
When building a win32 window project, I found that the window could not respond to the WM_LBUTTONDBLCLK (left mouse button double-click) message.
MSDN
https://docs.microsoft.com/en-us/previous-versions/aa926302(v=msdn.10)
problem analysis
Cause one:
Only windows that have the CS_DBLCLKS style can receive WM_LBUTTONDBLCLK messages, which the OS generates when the user presses, releases, and again presses the left mouse button within the time limit for double-clicks for the system.
Translation: Only windows with the CS_DBLCLKS style can receive the WM_LBUTTONDBLCLK message, which is generated by the OS during a system double-click within the time the user presses, releases, and presses the left mouse button again.
Reason two:
Since the WM_LBUTTONDBLCLK message of the mouse double-click is accompanied by the WM_LBUTTONDOWN message, the mouse double-click event is always truncated by the previous WM_LBUTTONDOWN message, and the WM_LBUTTONDBLCLK message cannot be triggered.
solution
For reason one:
Just modify the corresponding style member of WNDCLASS and add the CS_DBLCLKS style.
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
For reason two:
Adjust the message processing order of the message processing function.
Question expansion
CS style |
illustrate |
---|---|
CS_HREDRAW | When the width of the form changes, the window is redrawn. |
CS_VREDRAW | When the height of the form changes, the window is redrawn. |
CS_DBLCLKS | Can receive the user's double-click event on the form. |
CS_OWNDC | Assign each window in this class its own independent device context. |
CS_NOCLOSE | Disable the "Close" command in the system menu. |
CS_CLASSDC | Assigns a shared device context to each window of this window class. |
CS_PARENTDC | Specifies that the child window inherits the device context of its parent window. |
CS_SAVEBITS | Save the portion of the screen image obscured by the window as a bitmap. When the window is moved, Windows uses the saved bitmap to reconstruct the screen image. |
Double-clicking the left mouse button actually generates the following series of four messages:
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBLCLK
WM_LBUTTONUP
Reference articlehttps
://blog.csdn.net/u011296732/article/details/51669181
https://blog.csdn.net/evanlinux/article/details/6598659