Mouse Double-Clicks

A mouse double-click is two clicks in quick succession. To qualify as a double-click, the two clicks must occur within a specific interval called the ”double-click time.“ If you want your window procedure to receive double-click mouse messages, you must include the identifier CS_DBLCLKS when initializing the window style in the window class structure before calling RegisterClass:

wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ;

If you do not include CS_DBLCLKS in the window style and the user clicks the left mouse button twice in quick succession, your window procedure receives these messages: WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDOWN, and WM_LBUTTONUP. (The window procedure might also receive other messages between these button messages.) If you want to implement your own double-click logic, you can use the Windows function GetMessageTime to obtain the relative times of the WM_LBUTTONDOWN messages. This function is discussed in more detail in Chapter 5.

If you include CS_DBLCLKS in your window class, the window procedure receives these messages for a double-click: WM_LBUTTONDOWN, WM_LBUTTONUP, WM- LBUTTONDBLCLK, and WM_LBUTTONUP. The WM_LBUTTONDBLCLK message simply replaces the second WM_LBUTTONDOWN message.

Double-click messages are much easier to process if the first click of a double-click performs the same action as a single click. The second click (the WM_LBUTTONDBLCLK message) then does something in addition to the first click. For example, look at how the mouse works with the file list in the File Manager program. A single click selects the file. The File Manager highlights the file with a reverse-video bar. A double-click performs two actions: The first click selects the file, just as a single click does; the second click (which is a WM_LBUTTONDBLCLK message) directs the File Manager to run the file. That's fairly easy logic.

Mouse-handling logic could get more complex if the first click of a double-click does not perform the same action as a single click.