Recently, there was a left-click or double-click event in the project, but it was found that the clicked menu always pops up during double-click (this is normal, because double-click must trigger the click event first ), so how can we avoid this situation ....
Solution 1: Use a thread to process click events and determine the latency. If you double-click an event, the clicked menu is not displayed.
First, add BOOL m_bLButtonFlag in the dialog box; // 0 indicates clicking 1 indicates double-clicking
Then
Lresult xxx: DefWindowProc (UINT message, WPARAM wParam, LPARAM lParam)
Case WM_LBUTTONDOWN:
{
// Display menu
Afxbeginthread ()...
Return TRUE;
}
Case WM_LBUTTONDBLCLK: // restore the display
{
M_bLButtonFlag = TRUE;
...
}
Then process the clicked event information in the thread.
Solution 2: latency processing, SETTIMER (), handling corresponding events in ONTIMER
If (LOWORD (lParam) = WM_LBUTTONDOWN)
{
SetTimer (111,500, NULL );
}
Void CMy12314Dlg: OnTimer (UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
If (m_showflag = false)
{
CMenu menu, * pSubMenu;
If (! Menu. LoadMenu (IDR_MENU2) return;
If (! (PSubMenu = menu. GetSubMenu (0) return;
// Make first menu item the default (bold font)
//: SetMenuDefaultItem (pSubMenu-> m_hMenu, 0, TRUE );
// Display and track the popup menu
CPoint pos;
: GetCursorPos (& pos );
: SetForegroundWindow (nd. hWnd );
: TrackPopupMenu (pSubMenu-> m_hMenu, 0, pos. x, pos. y, 0, this-> GetSafeHwnd (), NULL );
}
Else
{
M_showflag = true;
}
Problem: the menu display in the thread has not been solved. Later, the timer is used, and you can click the menu to display it normally.
<