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. CButton DrawItem problem

CButton DrawItem problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
4 Posts 3 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.
  • B Offline
    B Offline
    Brian van der Beek
    wrote on last edited by
    #1

    I've create my own CButton derived class with the BS_OWNERDRAW style. Somehow the button's DrawItem method is not called, and the button is not displayed. When I remove the BS_OWNERDRAW style the button is draw. I'm not getting this, am I'm missing something? This should be simple.

    H 1 Reply Last reply
    0
    • B Brian van der Beek

      I've create my own CButton derived class with the BS_OWNERDRAW style. Somehow the button's DrawItem method is not called, and the button is not displayed. When I remove the BS_OWNERDRAW style the button is draw. I'm not getting this, am I'm missing something? This should be simple.

      H Offline
      H Offline
      HENDRIK R
      wrote on last edited by
      #2

      Did you consider the correct declaration of the function, that means did you declare it as virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct ) ?

      B 1 Reply Last reply
      0
      • H HENDRIK R

        Did you consider the correct declaration of the function, that means did you declare it as virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct ) ?

        B Offline
        B Offline
        Brian van der Beek
        wrote on last edited by
        #3

        I did. And I probalby also found the cause of the problem. I copied the code to a simple dialog and it works there. In my current project there are a lot of OnCommand function (I did not write the code) and someting probably goes wrong there.

        A 1 Reply Last reply
        0
        • B Brian van der Beek

          I did. And I probalby also found the cause of the problem. I copied the code to a simple dialog and it works there. In my current project there are a lot of OnCommand function (I did not write the code) and someting probably goes wrong there.

          A Offline
          A Offline
          ANIL KUMAR SHARMA INDIA
          wrote on last edited by
          #4

          I like to autosize the owner draw button depending upon the text that it load dynamically based on localization strings. so some strings are large than others. Keeping this I override DrawItem in the inherited class from CButton. The sample code is below void CMyGraphicButton::DrawItem (LPDRAWITEMSTRUCT lpDrawItemStruct) { CString cs; CString cslong; ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON); LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData; if (!lpszText || lpszText == (LPCTSTR)-1) { GetWindowText (cs); } else cs = lpszText; // now i m trying to resize , so let try to increase the size of button unconditioally // I get //lpDrawItemStruct>rcItem.left =0 //lpDrawItemStruct>rcItem.right =75 //lpDrawItemStruct>rcItem.top = 0 //lpDrawItemStruct>rcItem.bottom = 25 //As my button is on extreme right side of dialog so i tried to extend/increase the size of // button of the left side as follows lpDrawItemStruct>rcItem.left -= 25 ; // but the above causes the text to be moved on right side insead of resize/increase the //button size. other code here... Any idea or help is appriciated. Thanks Anil

          [AKS]

          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