Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Pop-up menu not disappear in thread
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Pop-up menu not disappear in thread

 Post Reply Post Reply
Author
Message
hijerry View Drop Down
Newbie
Newbie


Joined: 12 February 2007
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote hijerry Quote  Post ReplyReply Direct Link To This Post Topic: Pop-up menu not disappear in thread
    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;

}

Back to Top
akur View Drop Down
Senior Member
Senior Member


Joined: 16 May 2006
Status: Offline
Points: 139
Post Options Post Options   Thanks (0) Thanks(0)   Quote akur Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
hijerry View Drop Down
Newbie
Newbie


Joined: 12 February 2007
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote hijerry Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
lbvlad View Drop Down
Newbie
Newbie
Avatar

Joined: 10 November 2006
Location: United States
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote lbvlad Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
hijerry View Drop Down
Newbie
Newbie


Joined: 12 February 2007
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote hijerry Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
lbvlad View Drop Down
Newbie
Newbie
Avatar

Joined: 10 November 2006
Location: United States
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote lbvlad Quote  Post ReplyReply Direct Link To This Post 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)
Back to Top
hijerry View Drop Down
Newbie
Newbie


Joined: 12 February 2007
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote hijerry Quote  Post ReplyReply Direct Link To This Post 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 :)
Back to Top
hijerry View Drop Down
Newbie
Newbie


Joined: 12 February 2007
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote hijerry Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.031 seconds.