Problem with TrackPopupMenu()
Jim Husband -- jimhus@airmail.net
Thursday, August 08, 1996
Environment: VC++ 4.2, Windows 95
I can't seem to get the TrackPopupMenu() to remove the popup "correctly."
The menu works fine, and if a selection within the menu is made, the message
is sent and the menu goes away. However, if I move the mouse elsewhere on
the screen while the pop-up is visible and click the mouse button, the menu
does not go away. It will go away either after an unknown amount of time, or
if I move the mouse cursor back over the pop-up while focus is on a separate
window (not the desktop).
From the help on TrackPopupMenu() - it appears to me the menu should
disappear once the mouse is clicked outside of the pop-up menu's rectangle
(since the last parameter is NULL (0)). What am I missing here? The dialog
itself is hidden via ShowWindow(SW_HIDE) - and serves as the message loop
for the app. I read a thread in the MFC-L archive that indicated
TrackPopupMenu() functioned differently under Win95 than NT, but no
work-around was mentioned.
Thanks in advance.
Jim Husband
jimhus@airmail.net
~~~~~~~~~~~~ Snippit starts ~~~~~~~~~~~~~
case WM_RBUTTONDOWN:
{
POINT point;
CMenu hMenu;
hMenu.CreatePopupMenu();
hMenu.AppendMenu(MF_STRING | MF_CHECKED, IDC_CB_JAVA, "&Protect Java
classes");
hMenu.AppendMenu(MF_SEPARATOR);
hMenu.AppendMenu(MF_STRING, IDC_DELETE_HTML, "&HTML files");
hMenu.AppendMenu(MF_STRING, IDC_DELETE_NON_BITMAP, "&Non-bitmap files");
hMenu.AppendMenu(MF_STRING, IDC_DELETE_ZIP_EXE, "&Zip && EXE files");
hMenu.AppendMenu(MF_SEPARATOR);
hMenu.AppendMenu(MF_STRING, IDC_CLOSE, "&Close");
GetCursorPos(&point);
hMenu.TrackPopupMenu(TPM_RIGHTALIGN | TPM_LEFTBUTTON, point.x, point.y,
(CWnd *)this, NULL);
hMenu.DestroyMenu();
break;
}
~~~~~~~~~~~~ Snippit ends ~~~~~~~~~~~~~
Brad Wilson/Crucial Software -- crucial@pobox.com
Sunday, August 11, 1996
[Mini-digest: 2 responses]
I had the same problem you did with my tool tray application.
> case WM_RBUTTONDOWN:
Calling TrackPopupMenu() when you're in the middle of the mouse message
"sequence" appears to cause problems. I solved this by posting a message
to myself and using the posted message to call the TrackPopupMenu function
instead.
--
Brad Wilson, Objectivist philosopher, software engineer, web designer
crucial@pobox.com http://pobox.com/~crucial Objectvst@Undernet
"I'm not a savior, I'm not a king, it's only the voice in your head."
-----From: "Bradley A. Burns"
Hi there, Jim...
Your menu problem is certainly a strange happening. I don't exactly have
an answer for you. I just wanted to say that the DestroyMenu() function in
your code is not necessary since it is called in the CMenu destructor,
which, in the case of your code snippet, would be in another 2 lines. I've
never encountered the problem you're having, but the DestroyMenu()
function could possibly be part of the problem.
--
Bradley A. Burns
bburns@sprynet.com
"Rockin' and Codin' all night... and sleepin' every day."
| Вернуться в корень Архива
|