![]() |
Pop-up menu not disappear in thread |
Post Reply ![]() |
Author | |
hijerry ![]() Newbie ![]() Joined: 12 February 2007 Status: Offline Points: 5 |
![]() ![]() ![]() ![]() ![]() 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 hereCMenu 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; } |
|
![]() |
|
akur ![]() Senior Member ![]() Joined: 16 May 2006 Status: Offline Points: 139 |
![]() ![]() ![]() ![]() ![]() |
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. |
|
![]() |
|
hijerry ![]() Newbie ![]() Joined: 12 February 2007 Status: Offline Points: 5 |
![]() ![]() ![]() ![]() ![]() |
Thanks for your suggestion. Anyway, is there someone that met the same problem? Or is there any solution to make the menu disappear?
|
|
![]() |
|
lbvlad ![]() Newbie ![]() ![]() Joined: 10 November 2006 Location: United States Status: Offline Points: 2 |
![]() ![]() ![]() ![]() ![]() |
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. |
|
![]() |
|
hijerry ![]() Newbie ![]() Joined: 12 February 2007 Status: Offline Points: 5 |
![]() ![]() ![]() ![]() ![]() |
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. |
|
![]() |
|
lbvlad ![]() Newbie ![]() ![]() Joined: 10 November 2006 Location: United States Status: Offline Points: 2 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
|
hijerry ![]() Newbie ![]() Joined: 12 February 2007 Status: Offline Points: 5 |
![]() ![]() ![]() ![]() ![]() |
Now //ensure any popup menus are destroyed
XTPMouseManager()->SendTrackLost(); works both in main thread and CWinThread.
Thanks again :)
|
|
![]() |
|
hijerry ![]() Newbie ![]() Joined: 12 February 2007 Status: Offline Points: 5 |
![]() ![]() ![]() ![]() ![]() |
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?
|
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |