Left-click tray and double-click Problems

Source: Internet
Author: User

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.

<

Related Article

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.