TrackPopupMenu |
Post Reply |
Author | |
Michl
Senior Member Joined: 14 September 2007 Status: Offline Points: 138 |
Post Options
Thanks(0)
Posted: 22 December 2010 at 3:29am |
Hi
first of all, I know it is not a very good programming style - but it is windows :) In a windows(!)-system-callback (this is raising in another worker-thread-context!), I like to view a small popup context window with TrackPopupMenu. MFC build in function works without assertions. But if I use Codejocks CommandBars the application crashes! I know ToolkitPro is not thread safe, but I don't manipulate data. The question is, ToolkitPro?
AfxGetThread() returns NULL because theApp object was created in main thread. This is correct and highly recommended to avoid simultaneous execution. What do you mean, Oleg? Make it sense to check pointer and call only PreTranslateMessage in same thread? Or avoid using your TrackPopupMenu because more functions potentially unsafe. Thanks |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hi,
If you need GUI you should run GUI-thread. in this case AfxGetThread will return CWinThread you created. |
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
Michl
Senior Member Joined: 14 September 2007 Status: Offline Points: 138 |
Post Options
Thanks(0)
|
Hello Oleg
Sorry, I was in christmas holidays. I know that only the main thread should create user interfaces. But our problem don't occur in a (normal) executable application. We developed an ad-snapin extension (.dll) After you have registered the snapin, windows will be called a COM callback 'AddPages' of interface 'IShellPropSheetExt'. Before, windows must loading the dll and initialize (indirect) MFC (because CWinApp is static object as known). This initialize also the structure wich returns the pointer by calling AfxGetThread(). But this all happens in thread A. This functions creates an user defined tab (CPropertyPage) which contains a button for extended settings and returns it. Additional a callback function is defined by a message map. This function is calling, but from thread B!??? I don't understand it, too. I like to know what windows is doing in his own internal message map!? (perhaps saving main property page for crashes) However, in my oppinion it should be possible to create a standalone popup or window with own message loop. If you are not in gui thread (AfxGetThread() == NULL), you should don't call PreTranslateMessage()! As you can see, the internal function TrackPopupMenu of MFC works! What is your oppinion? |
|
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 |