Getting the menu option from CMenu
-
CRect rect; int x; int l; int y; BSTR string = NULL; pPopupMenu.CreatePopupMenu(); GetWindowRect(&rect); x = rect.right < 0 ? 0 : rect.right; l = rect.left < 0 ? 0: rect.left; if ((x-l) > 700) x = (l+x) / 2; y = rect.bottom; CMenu pPopupMenu; pPopupMenu.CreatePopupMenu(); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option1"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option2"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option3"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option4"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option5"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option6"); iStatus = pPopupMenu.TrackPopupMenu(TPM_RIGHTALIGN | TPM_LEFTBUTTON, x, y, m_hWnd); iStatus = pPopupMenu.GetMenuString(1, string, MF_BYPOSITION); Can someone tell me how to get the the position the cursor is on? I need to get which option was chosen. Forever ignorant, Lilian
-
CRect rect; int x; int l; int y; BSTR string = NULL; pPopupMenu.CreatePopupMenu(); GetWindowRect(&rect); x = rect.right < 0 ? 0 : rect.right; l = rect.left < 0 ? 0: rect.left; if ((x-l) > 700) x = (l+x) / 2; y = rect.bottom; CMenu pPopupMenu; pPopupMenu.CreatePopupMenu(); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option1"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option2"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option3"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option4"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option5"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option6"); iStatus = pPopupMenu.TrackPopupMenu(TPM_RIGHTALIGN | TPM_LEFTBUTTON, x, y, m_hWnd); iStatus = pPopupMenu.GetMenuString(1, string, MF_BYPOSITION); Can someone tell me how to get the the position the cursor is on? I need to get which option was chosen. Forever ignorant, Lilian
You don't really need too keep track of the mouse pointer location. Add a command handler for WM_COMMAND and the selection will be sent there. Of course you'll have to set different IDs to
AppendMenu(MF_STRING, **WM_OPTION1**, "O1")
. These IDs will be sent in the WPARAM (?) to your command handler. -
CRect rect; int x; int l; int y; BSTR string = NULL; pPopupMenu.CreatePopupMenu(); GetWindowRect(&rect); x = rect.right < 0 ? 0 : rect.right; l = rect.left < 0 ? 0: rect.left; if ((x-l) > 700) x = (l+x) / 2; y = rect.bottom; CMenu pPopupMenu; pPopupMenu.CreatePopupMenu(); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option1"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option2"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option3"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option4"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option5"); iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option6"); iStatus = pPopupMenu.TrackPopupMenu(TPM_RIGHTALIGN | TPM_LEFTBUTTON, x, y, m_hWnd); iStatus = pPopupMenu.GetMenuString(1, string, MF_BYPOSITION); Can someone tell me how to get the the position the cursor is on? I need to get which option was chosen. Forever ignorant, Lilian
The value of iStatus will be the ID of the selected item, or 0 if he mehu was aborted so
if (iStatus != 0)
iStatus = pPopupMenu.GetMenuString(iStatus, string, MF_BYCOMMAND);Should do the trick You also need to add each item to the menu with a unique ID
iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option1");
iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER+1, L"Option2"); // +2...Roger Allen Sonork 100.10016 yet to be identified being from the planet Paltinmoriumbanfrettybooter
-
The value of iStatus will be the ID of the selected item, or 0 if he mehu was aborted so
if (iStatus != 0)
iStatus = pPopupMenu.GetMenuString(iStatus, string, MF_BYCOMMAND);Should do the trick You also need to add each item to the menu with a unique ID
iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER, L"Option1");
iStatus = pPopupMenu.AppendMenu(MF_STRING, WM_USER+1, L"Option2"); // +2...Roger Allen Sonork 100.10016 yet to be identified being from the planet Paltinmoriumbanfrettybooter
Thanks for the help, y'all. I got something working using the message handler. :)