checkmark/icon in submenu[owner draw menu]
-
Hi, Is there any ways for me to add a check marks or icon into the submenu? I'm currently creating owner draw menu. So far, I only able to print out the text into the submenu... I failed to put the check mark/icon into it.. Any help will be appreciated Currently all my drawing are done at: DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { } Regards, KH
good
-
Hi, Is there any ways for me to add a check marks or icon into the submenu? I'm currently creating owner draw menu. So far, I only able to print out the text into the submenu... I failed to put the check mark/icon into it.. Any help will be appreciated Currently all my drawing are done at: DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { } Regards, KH
good
What problem are you facing in drawing the icon? You can use DrawIconEx[^] and pass in the DC from the DRAWITEMSTRUCT.
-
Hi, Is there any ways for me to add a check marks or icon into the submenu? I'm currently creating owner draw menu. So far, I only able to print out the text into the submenu... I failed to put the check mark/icon into it.. Any help will be appreciated Currently all my drawing are done at: DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { } Regards, KH
good
Yesterday I pointed you at an article which is a super reference on this stuff. After a bit of digging, I found how Bruno does it... Not quite as trivial as I thought, but the info is there. Iain.
void CNewMenu::DrawSpecialChar(CDC* pDC, LPCRECT pRect, TCHAR Sign, BOOL bBold)
{
// 48 Min
// 49 Max
// 50 Restore
// 98 Checkmark
// 105 Bullet
// 114 CloseCFont MyFont; LOGFONT logfont; CRect rect(pRect) ; rect.DeflateRect(2,2); logfont.lfHeight = -rect.Height(); logfont.lfWidth = 0; logfont.lfEscapement = 0; logfont.lfOrientation = 0; logfont.lfWeight = (bBold) ? FW\_BOLD:FW\_NORMAL; logfont.lfItalic = FALSE; logfont.lfUnderline = FALSE; logfont.lfStrikeOut = FALSE; logfont.lfCharSet = DEFAULT\_CHARSET; logfont.lfOutPrecision = OUT\_DEFAULT\_PRECIS; logfont.lfClipPrecision = CLIP\_DEFAULT\_PRECIS; logfont.lfQuality = DEFAULT\_QUALITY; logfont.lfPitchAndFamily = DEFAULT\_PITCH; \_tcscpy(logfont.lfFaceName,\_T("Marlett")); MyFont.CreateFontIndirect (&logfont); CFont\* pOldFont = pDC->SelectObject (&MyFont); int OldMode = pDC->SetBkMode(TRANSPARENT); pDC->DrawText (&Sign,1,rect,DT\_CENTER|DT\_SINGLELINE); pDC->SetBkMode(OldMode); pDC->SelectObject(pOldFont);
}
-
Hi, Is there any ways for me to add a check marks or icon into the submenu? I'm currently creating owner draw menu. So far, I only able to print out the text into the submenu... I failed to put the check mark/icon into it.. Any help will be appreciated Currently all my drawing are done at: DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { } Regards, KH
good
How did you try?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
-
What problem are you facing in drawing the icon? You can use DrawIconEx[^] and pass in the DC from the DRAWITEMSTRUCT.
because i currently put some code inside ::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) CDC* pDC; //i used this to draw a rect to the menu CRect rect; rect.left=lpDrawItemStruct->rcItem.left; rect.top=lpDrawItemStruct->rcItem.top + 2; rect.right=lpDrawItemStruct->rcItem.right; rect.bottom=lpDrawItemStruct->rcItem.bottom + 2 //str is a string which i want to output : eg -> Open\tCtrl+O pDC->DrawText (str,rectt,nFormat); //this will draw text into the menu/submenu What i want now is i want to make a checkmark/icon on the left side of the Text. I'm not sure on how to draw it on the left side of the text
good
-
Yesterday I pointed you at an article which is a super reference on this stuff. After a bit of digging, I found how Bruno does it... Not quite as trivial as I thought, but the info is there. Iain.
void CNewMenu::DrawSpecialChar(CDC* pDC, LPCRECT pRect, TCHAR Sign, BOOL bBold)
{
// 48 Min
// 49 Max
// 50 Restore
// 98 Checkmark
// 105 Bullet
// 114 CloseCFont MyFont; LOGFONT logfont; CRect rect(pRect) ; rect.DeflateRect(2,2); logfont.lfHeight = -rect.Height(); logfont.lfWidth = 0; logfont.lfEscapement = 0; logfont.lfOrientation = 0; logfont.lfWeight = (bBold) ? FW\_BOLD:FW\_NORMAL; logfont.lfItalic = FALSE; logfont.lfUnderline = FALSE; logfont.lfStrikeOut = FALSE; logfont.lfCharSet = DEFAULT\_CHARSET; logfont.lfOutPrecision = OUT\_DEFAULT\_PRECIS; logfont.lfClipPrecision = CLIP\_DEFAULT\_PRECIS; logfont.lfQuality = DEFAULT\_QUALITY; logfont.lfPitchAndFamily = DEFAULT\_PITCH; \_tcscpy(logfont.lfFaceName,\_T("Marlett")); MyFont.CreateFontIndirect (&logfont); CFont\* pOldFont = pDC->SelectObject (&MyFont); int OldMode = pDC->SetBkMode(TRANSPARENT); pDC->DrawText (&Sign,1,rect,DT\_CENTER|DT\_SINGLELINE); pDC->SetBkMode(OldMode); pDC->SelectObject(pOldFont);
}
-
Hi Iain, Thanks for your reply. But what u showed are the example of change the font as well as its itallic/bold and draw the text based on the fonts Correct if i'm wrong towards the code you're trying to show Regards, KH
good
karhong wrote:
Correct if i'm wrong
It'll be a pleasure. (cue evil laugh) What is does is to temporarily change the font to Marlett, and then draw one of the characters in a particular place. It is then a good citizen and restores the font to it's previous state. If this is not clear, learn it fast, as you should be doing the same whenever you change the state of a DC. Out of curiosity, I loaded Marlett into charmap. It's a not-real font, with lots of useful characters, like the min / max / etc bits that windows uses in the top right of your windows. Etc. One of those characters (look at the comments in the pasted code) is a check mark / tick. Cunning Mr Podetti! Iain.
-
karhong wrote:
Correct if i'm wrong
It'll be a pleasure. (cue evil laugh) What is does is to temporarily change the font to Marlett, and then draw one of the characters in a particular place. It is then a good citizen and restores the font to it's previous state. If this is not clear, learn it fast, as you should be doing the same whenever you change the state of a DC. Out of curiosity, I loaded Marlett into charmap. It's a not-real font, with lots of useful characters, like the min / max / etc bits that windows uses in the top right of your windows. Etc. One of those characters (look at the comments in the pasted code) is a check mark / tick. Cunning Mr Podetti! Iain.
-
because i currently put some code inside ::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) CDC* pDC; //i used this to draw a rect to the menu CRect rect; rect.left=lpDrawItemStruct->rcItem.left; rect.top=lpDrawItemStruct->rcItem.top + 2; rect.right=lpDrawItemStruct->rcItem.right; rect.bottom=lpDrawItemStruct->rcItem.bottom + 2 //str is a string which i want to output : eg -> Open\tCtrl+O pDC->DrawText (str,rectt,nFormat); //this will draw text into the menu/submenu What i want now is i want to make a checkmark/icon on the left side of the Text. I'm not sure on how to draw it on the left side of the text
good
Shift the rectangle by the icon dimensions, say 16 pixels to the right, then draw the text there. Now draw the icon at the original position.
CRect rect;
rect.left=lpDrawItemStruct->rcItem.left;
rect.top=lpDrawItemStruct->rcItem.top + 2;
rect.right=lpDrawItemStruct->rcItem.right;
rect.bottom=lpDrawItemStruct->rcItem.bottom + 2;// Put code here to draw icon at (rect.left, rect.top)
// Now shift the rectangle before drawing text
rect.OffsetRect(16, 0);//str is a string which i want to output : eg -> Open\tCtrl+O
pDC->DrawText (str,rectt,nFormat); //this will draw text into the menu/submenuYou can load standard images such as check mark etc. using LoadBitmap[^]
-
Shift the rectangle by the icon dimensions, say 16 pixels to the right, then draw the text there. Now draw the icon at the original position.
CRect rect;
rect.left=lpDrawItemStruct->rcItem.left;
rect.top=lpDrawItemStruct->rcItem.top + 2;
rect.right=lpDrawItemStruct->rcItem.right;
rect.bottom=lpDrawItemStruct->rcItem.bottom + 2;// Put code here to draw icon at (rect.left, rect.top)
// Now shift the rectangle before drawing text
rect.OffsetRect(16, 0);//str is a string which i want to output : eg -> Open\tCtrl+O
pDC->DrawText (str,rectt,nFormat); //this will draw text into the menu/submenuYou can load standard images such as check mark etc. using LoadBitmap[^]