Click here to Skip to main content
15,918,471 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Media Decoder Application Pin
Rajkumar R20-May-08 17:40
Rajkumar R20-May-08 17:40 
QuestionBest way to setup this code - two client views Pin
Kwanalouie20-May-08 14:21
Kwanalouie20-May-08 14:21 
AnswerRe: Best way to setup this code - two client views Pin
Rajkumar R20-May-08 19:07
Rajkumar R20-May-08 19:07 
QuestionException caught but not handled completely Pin
Royce Fickling20-May-08 10:27
Royce Fickling20-May-08 10:27 
AnswerRe: Exception caught but not handled completely Pin
led mike20-May-08 11:46
led mike20-May-08 11:46 
QuestionMFC components and minGW... Pin
greghint20-May-08 9:58
greghint20-May-08 9:58 
AnswerRe: MFC components and minGW... Pin
Rajkumar R20-May-08 20:08
Rajkumar R20-May-08 20:08 
GeneralRe: MFC components and minGW... Pin
greghint11-Jun-08 16:27
greghint11-Jun-08 16:27 
I've been using Microsoft's MSDN example[^] as a starting point for my menu. This has been a bit frustrating, since some of the code simply doesn't work: SetMenuItemInfo() fails in their example until you set the cbSize of the MENUITEMINFO structure, which is explained in a different MSDN article. Confused | :confused:

Rather than using the MYITEM structure they do, I have created a class for my menu objects. Since my menu is created dynamically, I don't populate the menu structure when receiving the WM_CREATE message as they do in the example, but I am backpacking a pointer to a class item onto the MENUITEMINFO structure when menu items are created, like so:
MenuItem * myItem = &item;
MENUITEMINFO mii;
mii.fMask = MIIM_FTYPE | MIIM_DATA;
mii.fType = MFT_OWNERDRAW;
mii.dwItemData = (ULONG_PTR) myItem;
mii.cbSize = sizeof(mii); // MS didnt include this in their example wtf
SetMenuItemInfo(menu, item.itemID, FALSE, &mii);

In my function to handle the WM_MEASUREITEM message, I can access all of the class data from the pointer contained in the itemData member of the LPMEASUREITEMSTRUCT:
MenuItem *myItem = (MenuItem *) lpmis->itemData;
HDC hdc = GetDC(hwnd);
HFONT hfntOld = (HFONT)SelectObject(hdc, myItem->itemFont);

Microsoft use this exact same strategy when handling the WM_DRAWITEM message: they access the application-specific info from the itemData member of LPDRAWITEMSTRUCT. My implementation is the exact same as the example:
MenuItem *myItem = (MenuItem *) lpdis->itemData;
...
ExtTextOut(lpdis->lpdis->hDC, 
           x, 
           y, 
           ETO_OPAQUE, 
           &lpdis->rcItem, 
           myItem->itemLabel,
           myItem->itemLabelLen,
           NULL)

Sadly this strategy doesn't seem to work: any attempt to access the class items results in a crash. Is there some other sort of initialization I need to do that is missing from the example to ensure the pointer is passed along to the LPDRAWITEMSTRUCT?

Thanks in advance for any help or suggestions.

~g
Questioninitial position of pop-up dialog box Pin
Kwanalouie20-May-08 7:45
Kwanalouie20-May-08 7:45 
AnswerRe: initial position of pop-up dialog box Pin
David Crow20-May-08 7:48
David Crow20-May-08 7:48 
AnswerRe: initial position of pop-up dialog box Pin
Nelek21-May-08 6:56
protectorNelek21-May-08 6:56 
QuestionLoss of data using CList::AddTail() Pin
piul20-May-08 5:55
piul20-May-08 5:55 
QuestionRe: Loss of data using CList::AddTail() Pin
Ernest Laurentin20-May-08 7:51
Ernest Laurentin20-May-08 7:51 
QuestionRe: Loss of data using CList::AddTail() Pin
David Crow20-May-08 7:55
David Crow20-May-08 7:55 
QuestionHow can i copy raw image buffer to a dc? Pin
Soumyadipta20-May-08 5:09
Soumyadipta20-May-08 5:09 
AnswerRe: How can i copy raw image buffer to a dc? Pin
CPallini20-May-08 6:22
mveCPallini20-May-08 6:22 
GeneralRe: How can i copy raw image buffer to a dc? Pin
Soumyadipta20-May-08 18:49
Soumyadipta20-May-08 18:49 
GeneralRe: How can i copy raw image buffer to a dc? Pin
CPallini20-May-08 21:09
mveCPallini20-May-08 21:09 
GeneralRe: How can i copy raw image buffer to a dc? Pin
Soumyadipta20-May-08 23:08
Soumyadipta20-May-08 23:08 
GeneralRe: How can i copy raw image buffer to a dc? Pin
CPallini20-May-08 23:47
mveCPallini20-May-08 23:47 
GeneralRe: How can i copy raw image buffer to a dc? Pin
Soumyadipta21-May-08 0:26
Soumyadipta21-May-08 0:26 
GeneralRe: How can i copy raw image buffer to a dc? Pin
CPallini21-May-08 1:07
mveCPallini21-May-08 1:07 
GeneralRe: How can i copy raw image buffer to a dc? Pin
Soumyadipta21-May-08 1:55
Soumyadipta21-May-08 1:55 
GeneralRe: How can i copy raw image buffer to a dc? Pin
CPallini21-May-08 2:10
mveCPallini21-May-08 2:10 
QuestionFinding only GDI leaks Pin
Super Hornet20-May-08 4:58
Super Hornet20-May-08 4:58 

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.