Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello, Always thank you for your help.

Well, I've just made a simple program which can show trackpopupmenu. The trackpopupmenu is made by dynamically by code and it contains items like this.

A1
A2
A2_1
A2_2
A3
A3_1
A3_2

The problem is that I want to check sub menu item named "A2_1". Below is what I've implemented.
C++
...

const UINT A= (UINT)-101;
const UINT X= (UINT)-201;
const UINT Y = (UINT)-301;

UINT id_x_check;
UINT id_y_check;

CMenu menu;
menu.CreatePopupMenu();
{
 CString strItem;

 CMenu x_menu;
 x_menu.CreatePopupMenu();
 {
  for (UINT i = 0; i < 10; i++) {

   strItem.Format(_T("X_%d"), i);
   x_menu.AppendMenu(MF_STRING, X + i, strItem);
  }
 }

 x_menu.CheckMenuItem(X, MF_CHECKED);

 CMenu y_menu;
 y_menu.CreatePopupMenu();
 {
  for (UINT i = 0; i < 10; i++) {

   strItem.Format(_T("Y_%d"), i);
   x_menu.AppendMenu(MF_STRING, Y + i, strItem);
  }
 }

 y_menu.CheckMenuItem(Y, MF_CHECKED);

 strItem.SetString(_T("A"));
 menu.AppendMenu(MF_STRING, A, strItem);
 strItem.SetString(_T("X"));
 menu.AppendMenu(MF_STRING | MF_POPUP, (UINT_PTR)x_menu.Detach(), strItem);
 strItem.SetString(_T("Y"));
 menu.AppendMenu(MF_STRING | MF_POPUP, (UINT_PTR)y_menu.Detach(), strItem);
}

menu.CheckMenuItem(A, MF_CHECKED);


int nMenuResult = afxContextMenuManager->TrackPopupMenu(
 menu, point.x, point.y, this);

//int nMenuResult = menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);

switch(nMenuResult) {
...

Whenever I used menu.TrackPopupMenu() function(in code, it is commented) to populate popup menu, submenu item named "X" or "Y" is checked well, But when I used afxContextmenumanager->TrackPopupMenu() function to show popup menu, sub menu item "X" or "Y" is not checked. What's the problem? What is the difference between afxContextmenumanger->TrackPopupMenu() and menu.TrackPopupmenu()? How can I check sub menu item using afxContextmenumanger->TrackPopupMenu()?

Thank you.
Posted
Updated 5-Dec-13 15:01pm
v3
Comments
Richard MacCutchan 5-Dec-13 12:09pm    
Without seeing your code it is impossible to tell what you are doing. Are you getting the correct sub-menu handle?
WuRunZhe 5-Dec-13 21:43pm    
Sorry, I've just changed my question.
Richard MacCutchan 6-Dec-13 3:51am    
You need to check that your call to afxContextmenumanger->TrackPopupMenu() has the correct parameters.
WuRunZhe 9-Dec-13 2:06am    
Well, parameters of afxContextmenumanger->TrackPopupMenu() is correct.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900