Click here to Skip to main content
15,898,036 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: realloc(...) like function in C++ Pin
Neville Franks20-Mar-04 10:58
Neville Franks20-Mar-04 10:58 
GeneralRe: realloc(...) like function in C++ Pin
_moved20-Mar-04 11:18
_moved20-Mar-04 11:18 
GeneralRe: realloc(...) like function in C++ Pin
Ravi Bhavnani20-Mar-04 11:18
professionalRavi Bhavnani20-Mar-04 11:18 
GeneralVery mysterious socket behaviour Pin
Daniel 'Tak' M.20-Mar-04 9:35
Daniel 'Tak' M.20-Mar-04 9:35 
GeneralRe: Very mysterious socket behaviour Pin
bilal7821-Mar-04 23:35
bilal7821-Mar-04 23:35 
GeneralRe: Very mysterious socket behaviour Pin
Daniel 'Tak' M.22-Mar-04 5:49
Daniel 'Tak' M.22-Mar-04 5:49 
GeneralAdding sub menus to a menu Pin
Daniel132420-Mar-04 8:49
Daniel132420-Mar-04 8:49 
GeneralRe: Adding sub menus to a menu Pin
Antti Keskinen20-Mar-04 23:45
Antti Keskinen20-Mar-04 23:45 
The menu objects are always grouped as sub or pop-up menus. Now, considering your code post, there is one crucial difference in creating pop-up menus.

Firstly, you need to create a new CMenu object. Then initialize it with CreatePopupMenu like you have done. After that, you need to create a yet another CMenu item, and initialize it with CreatePopupMenu again.

The second menu object behaves like a pop-up menu on the first one. In order to link these two, first add items and their respective command IDs to the second menu by using AppendMenu or InsertMenu. Then use AppendMenu/InsertMenu on the first menu object, and specify MF_POPUP flag in the first parameter. Adding a MF_STRING flag allows you to have an item text as well, specified in the third parameter. Instead of a command ID in the second parameter, you now must supply a handle to the sub-menu object (HMENU). You can get this from the second menu object by querying CMenu::operator HMENU or CMenu::m_hMenu.

After this, you can launch the first menu object as a pop-up menu with a sub pop-up by calling TrackPopupMenuEx. Here is a complete code fragment to give you a better clue:
// Create a CMenu object and initialize
CMenu* pMenu = new CMenu();
pMenu->CreatePopupMenu();<DIV>

// Create the sub pop-up menu object
CMenu* pSubMenu = new CMenu();
pSubMenu->CreatePopupMenu();<DIV>

// Add menu items into the second menu
pSubMenu->AppendMenu( MF_STRING, 1, "Option 1" );
pSubMenu->AppendMenu( MF_STRING, 2, "Option 2" );<DIV>

// Add the pop-up menu
pMenu->AppendMenu( MF_STRING | MF_POPUP, (UINT_PTR) pSubMenu->m_hMenu, "Sub menu" );<DIV>

// Launch and do cleanup
pMenu->TrackPopupMenuEx(...);<DIV>

pMenu->RemoveMenu( 0, MF_BYPOSITION ); 
pSubMenu->DestroyMenu(); delete pSubMenu; pSubMenu = NULL;
pMenu->DestroyMenu(); delete pMenu; pMenu = NULL;
I am not certain if the RemoveMenu call is necessary, as the menu cleanup code might have a routine that destroys sub-menus as well. Also, the code has no error-checking routines for possible error states like memory reservation failures or checks whether the pointers are valid. You should include these, or your application might cause access violations.

-Antti Keskinen


----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
Generallarge and lower case Pin
Lucky200220-Mar-04 6:59
Lucky200220-Mar-04 6:59 
GeneralRe: large and lower case Pin
Ravi Bhavnani20-Mar-04 7:29
professionalRavi Bhavnani20-Mar-04 7:29 
GeneralWindows Master Volume control Pin
impeham20-Mar-04 6:48
impeham20-Mar-04 6:48 
GeneralRe: Windows Master Volume control Pin
Ravi Bhavnani20-Mar-04 7:30
professionalRavi Bhavnani20-Mar-04 7:30 
GeneralUpload Data via HTTP..VC++ Pin
rasha200320-Mar-04 5:05
rasha200320-Mar-04 5:05 
GeneralKnowing with Network Interface will be used Pin
mmica20-Mar-04 4:52
mmica20-Mar-04 4:52 
GeneralRe: Knowing with Network Interface will be used Pin
Roger Wright20-Mar-04 6:57
professionalRoger Wright20-Mar-04 6:57 
QuestionHow could I make folder as Public Share in windows98 system? Pin
.NetRams19-Mar-04 18:50
.NetRams19-Mar-04 18:50 
GeneralMFC Edit Controls. Pin
Ichiban_Addict19-Mar-04 17:11
Ichiban_Addict19-Mar-04 17:11 
GeneralRe: MFC Edit Controls. Pin
l a u r e n19-Mar-04 17:27
l a u r e n19-Mar-04 17:27 
GeneralRe: MFC Edit Controls. Pin
Ravi Bhavnani20-Mar-04 7:32
professionalRavi Bhavnani20-Mar-04 7:32 
GeneralRe: MFC Edit Controls. Pin
MeterMan21-Mar-04 15:54
MeterMan21-Mar-04 15:54 
GeneralRe: MFC Edit Controls. Pin
Ichiban_Addict21-Mar-04 16:08
Ichiban_Addict21-Mar-04 16:08 
GeneralRe: MFC Edit Controls. Pin
MeterMan21-Mar-04 18:07
MeterMan21-Mar-04 18:07 
GeneralStatus bar gripper Pin
sschilachi19-Mar-04 13:36
sschilachi19-Mar-04 13:36 
GeneralRe: Status bar gripper Pin
_moved20-Mar-04 12:39
_moved20-Mar-04 12:39 
Generalhook Pin
Anonymous19-Mar-04 13:34
Anonymous19-Mar-04 13:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.