CMenu/menus, a tough question for smarties - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

CMenu/menus, a tough question for smarties

I'm trying to make an owner-draw menu in C++ and I'm having a lot of trouble. I'm using MFC's CMenu class and I'm trying InsertMenu();

mymenu->InsertMenu(0, MF_BYPOSITION|MF_OWNERDRAW, ID_RED, "Red");

After doing this, my OnDrawItem function retrieves a DRAWITEMSTRUCT as one of it's argumens and the structure contains a variable called itemData, which is a unsigned integer that contains the fourth parameter of InsertMenu. In my OnDrawItem, I do:

CString data = (LPCTSTR) lpdis->itemData; (lpdis is the DRAWITEMSTRUCT structure).

this works fine if I implement InsertMenu() like above, but when I fill InsertMenu with the fourth parameter being a variable that contains the string I want it to be, it doesn't work. Basically, I need figuring out why this works:

mymenu->InsertMenu(0, MF_BYPOSITION|MF_OWNERDRAW, ID_RED, "Red");

and not this:

CString red = "red";
mymenu->InsertMenu(0, MF_BYPOSITION|MF_OWNERDRAW, ID_RED, red);

If you have any hints or suggestions, please help me.

Comments

  • ColdShineColdShine Posts: 597Member
    I don't program in MFC, but I know a little of. Try this:[code]CString red = "red";
    mymenu->InsertMenu(0, MF_BYPOSITION | MF_OWNERDRAW, ID_RED, [red](LPCTSTR)[/red]red);[/code]Or this:[code]CString red = "red";
    mymenu->InsertMenu(0, MF_BYPOSITION | MF_OWNERDRAW, ID_RED, [red](LPTSTR)[/red]red);[/code]There's only a capital C of difference, but may help...
    ________
    [size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b][/size]


Sign In or Register to comment.