Print Page | Close Window

Pop-up menu not disappear in thread

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=6378
Printed Date: 03 March 2025 at 10:41pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Pop-up menu not disappear in thread
Posted By: hijerry
Subject: Pop-up menu not disappear in thread
Date Posted: 12 February 2007 at 12:10am
 
If the view is created in main thread, the pop-up menu works.
But if the view is created in a CWinThread, the pop-up menu do not disappear when I switch to another widow.
 
Here is the codes: I create a pop-up menu in a MFC CView class:
 

void CXXXView::OnContextMenu(CWnd* /*pWnd*/, CPoint point)

{

// TODO: Add your message handler code here

CMenu MainMenu;

MainMenu.LoadMenu(IDR_MAINFRAME );

CMenu* pCTRMKMenu= NULL;

CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(0);

pCTRMKMenu = MainMenu.GetSubMenu(0);

pPopupBar->LoadMenu(pCTRMKMenu);

CXTPCommandBars::TrackPopupMenu(pPopupBar,TPM_RIGHTBUTTON|TPM_NONOTIFY,point.x, point.y,this);

pPopupBar->InternalRelease();

pPopupBar = NULL;

}




Replies:
Posted By: akur
Date Posted: 12 February 2007 at 1:58am
Hello,

generally it's a good idea to make all the GUI activity from the GUI thread of your application (your "main" thread). I've run into different, more difficult problems in the past when I tried not to do so.
Limiting GUI interaction to the GUI thread will save you many troubles.


Posted By: hijerry
Date Posted: 12 February 2007 at 2:23am
Thanks for your suggestion. Anyway, is there someone that met the same problem? Or is there any solution to make the menu disappear?


Posted By: lbvlad
Date Posted: 12 February 2007 at 2:32pm
Hello,

you need to call
//ensure any popup menus are destroyed
XTPMouseManager()->SendTrackLost();

from the same thread where you have popped up the menu.

for example, when user clicks on another window, send a special message to your CXXXView and execute code above.
It will break tracking loop inside a TrackMenuPopup.


Posted By: hijerry
Date Posted: 12 February 2007 at 8:27pm

Thanks. It does work now. The menu in the CWinThread will disappear if I switch to the view of main thread.

But there is still a problem. When I switch the window from the view in main thread to  the view in CWinThread, the menu of view in the main thread would not disappear.


Posted By: lbvlad
Date Posted: 12 February 2007 at 8:32pm
This is exactly the same problem.
Just when you switch from main thread to another thread and in main thread menu is open, you need to call SendTrackLost (but this time in the context of the main thread)


Posted By: hijerry
Date Posted: 12 February 2007 at 9:15pm

Now

//ensure any popup menus are destroyed
XTPMouseManager()->SendTrackLost();
 
works both in main thread and CWinThread.
Thanks again :)


Posted By: hijerry
Date Posted: 20 March 2007 at 10:04pm
For the huge frame of the program, it's hard to call functions such as SendTrackLost to make the menu disappear. Is there a way to let the menu disappear automatically?



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net