Click here to Skip to main content
15,917,652 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionSame code takes different times!! Pin
Kiran Satish16-Jun-08 12:16
Kiran Satish16-Jun-08 12:16 
AnswerRe: Same code takes different times!! Pin
zildjohn0116-Jun-08 16:01
zildjohn0116-Jun-08 16:01 
GeneralRe: Same code takes different times!! Pin
Kiran Satish16-Jun-08 16:19
Kiran Satish16-Jun-08 16:19 
AnswerRe: Same code takes different times!! Pin
Alan Balkany17-Jun-08 5:02
Alan Balkany17-Jun-08 5:02 
GeneralRe: Same code takes different times!! Pin
Kiran Satish18-Jun-08 8:51
Kiran Satish18-Jun-08 8:51 
GeneralRe: Same code takes different times!! Pin
Alan Balkany19-Jun-08 3:22
Alan Balkany19-Jun-08 3:22 
QuestionWinSock Remote Connection Pin
Knight Rider16-Jun-08 11:29
Knight Rider16-Jun-08 11:29 
Questionwin32 user-drawn menus Pin
greghint16-Jun-08 6:33
greghint16-Jun-08 6:33 
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? All examples of user-drawn menus that I've found on the site are MFC based. Here's hoping someone out there has some experience doing this in win32.

I'm also curious to find out if this may be an issue with the api that came with the mingw compiler that I'm using to compile and run my code...

Thanks in advance for any help or suggestions.

~g
AnswerRe: win32 user-drawn menus Pin
James R. Twine16-Jun-08 8:01
James R. Twine16-Jun-08 8:01 
GeneralRe: win32 user-drawn menus Pin
greghint16-Jun-08 9:25
greghint16-Jun-08 9:25 
GeneralRe: win32 user-drawn menus Pin
zildjohn0117-Jun-08 2:09
zildjohn0117-Jun-08 2:09 
GeneralRe: win32 user-drawn menus Pin
greghint17-Jun-08 9:35
greghint17-Jun-08 9:35 
GeneralRe: win32 user-drawn menus [modified] Pin
greghint18-Jun-08 8:00
greghint18-Jun-08 8:00 
QuestionMoving desktop shortcuts to desired position Pin
Manfred Staiger16-Jun-08 5:13
Manfred Staiger16-Jun-08 5:13 
QuestionCRuntimeClass linker error unresolved external – how to troubleshoot? Pin
Vaclav_16-Jun-08 5:13
Vaclav_16-Jun-08 5:13 
AnswerRe: CRuntimeClass linker error unresolved external – how to troubleshoot? Pin
Chris Losinger16-Jun-08 6:54
professionalChris Losinger16-Jun-08 6:54 
GeneralRe: CRuntimeClass linker error unresolved external – how to troubleshoot? Pin
Vaclav_16-Jun-08 7:13
Vaclav_16-Jun-08 7:13 
GeneralRe: CRuntimeClass linker error unresolved external – how to troubleshoot? Pin
Vaclav_16-Jun-08 7:16
Vaclav_16-Jun-08 7:16 
AnswerRe: CRuntimeClass linker error unresolved external – how to troubleshoot? Pin
Stephen Hewitt16-Jun-08 15:44
Stephen Hewitt16-Jun-08 15:44 
GeneralRe: CRuntimeClass linker error unresolved external – how to troubleshoot? Pin
Vaclav_16-Jun-08 17:28
Vaclav_16-Jun-08 17:28 
QuestionCreating an embeded window in Internet Explorer Pin
chatko16-Jun-08 2:30
chatko16-Jun-08 2:30 
AnswerRe: Creating an embeded window in Internet Explorer Pin
ThatsAlok16-Jun-08 3:22
ThatsAlok16-Jun-08 3:22 
QuestionProblem with a program that does Copy-Paste functionality. Pin
ritz123416-Jun-08 2:26
ritz123416-Jun-08 2:26 
AnswerRe: Problem with a program that does Copy-Paste functionality. Pin
CPallini16-Jun-08 2:40
mveCPallini16-Jun-08 2:40 
GeneralRe: Problem with a program that does Copy-Paste functionality. Pin
ritz123416-Jun-08 2:57
ritz123416-Jun-08 2:57 

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.