Is it possible to use TrackPopupMenu from a secondary thread?
Is it possible to use TrackPopupMenu
from a secondar开发者_C百科y thread? I'm trying to use it with TPM_NONOTIFY
and TPM_RETURNCMD
flags.
In our code, the call to TrackPopupMenu
returns immediately without displaying the menu, indicating that the user cancelled the menu.
The same code, when called from the main/gui thread works fine.
You need to run this from the same thread that owns the window to which the menu is attached.
The threading rule in Windows is that windows have affinity to the thread that creates the window. Since TrackPopupMenu receives a window handle, you can assume that it must be called from that window's thread.
In practice on Windows (and all GUI frameworks that I have ever come across), everything related to the GUI should happen in the main thread.
精彩评论