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!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.


  • 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...

Sign In or Register to comment.