Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. checkmark/icon in submenu[owner draw menu]

checkmark/icon in submenu[owner draw menu]

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpquestion
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    karhong
    wrote on last edited by
    #1

    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

    L I C 3 Replies Last reply
    0
    • K karhong

      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

      L Offline
      L Offline
      L Madhavan
      wrote on last edited by
      #2

      What problem are you facing in drawing the icon? You can use DrawIconEx[^] and pass in the DC from the DRAWITEMSTRUCT.

      K 1 Reply Last reply
      0
      • K karhong

        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

        I Offline
        I Offline
        Iain Clarke Warrior Programmer
        wrote on last edited by
        #3

        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 Close

        CFont 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);
        

        }

        K 1 Reply Last reply
        0
        • K karhong

          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

          C Offline
          C Offline
          Code o mat
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • L L Madhavan

            What problem are you facing in drawing the icon? You can use DrawIconEx[^] and pass in the DC from the DRAWITEMSTRUCT.

            K Offline
            K Offline
            karhong
            wrote on last edited by
            #5

            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

            L 1 Reply Last reply
            0
            • I Iain Clarke Warrior Programmer

              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 Close

              CFont 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);
              

              }

              K Offline
              K Offline
              karhong
              wrote on last edited by
              #6

              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

              I 1 Reply Last reply
              0
              • K karhong

                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

                I Offline
                I Offline
                Iain Clarke Warrior Programmer
                wrote on last edited by
                #7

                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.

                L 1 Reply Last reply
                0
                • I Iain Clarke Warrior Programmer

                  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.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Marlett is not a standard Windows font on all Microsoft operating systems and may not exist on the client computer. I would not recommend this hackish way of drawing a checkmark at all. Standard Window Fonts[^] Best Wishes, -David Delaune

                  1 Reply Last reply
                  0
                  • K karhong

                    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

                    L Offline
                    L Offline
                    L Madhavan
                    wrote on last edited by
                    #9

                    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/submenu

                    You can load standard images such as check mark etc. using LoadBitmap[^]

                    K 1 Reply Last reply
                    0
                    • L L Madhavan

                      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/submenu

                      You can load standard images such as check mark etc. using LoadBitmap[^]

                      K Offline
                      K Offline
                      karhong
                      wrote on last edited by
                      #10

                      thanks ! ^^ got it worked out :-\

                      good

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups