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. how to ownerdraw the button borders in VC++6.0 [modified]

how to ownerdraw the button borders in VC++6.0 [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
3 Posts 2 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
    Krauze
    wrote on last edited by
    #1

    I've overriden the funx CMyButton::DrawItem(), and some lines in it are:

    CDC\* pDC = CDC::FromHandle( lpDrawItemStruct->hDC );
    CRect rc = lpDrawItemStruct->rcItem;
    CPen pen( PS\_SOLID, 1, RGB(0,0,0) );
    CPen \*pOld = pDC->SelectObject( &pen );
    pDC->LineTo( rc.right, rc.top );
    pDC->LineTo( rc.right, rc.bottom );
    pDC->LineTo( rc.left, rc.bottom );
    pDC->LineTo( rc.left, rc.top );
    pDC->SelectObject( pOld );
    

    But the prob occurs that only the upper and left borders drawn can be seen while the lower and right can't. At first, I thought it was caused by the 3D effect of the button. But though I've added BS_FLAT, the prob still exists. In fact, I can't use the following to draw the borders:

    pDC->Rectangle( &rc );
    

    Cos I want the button background to be transparent so that the back image of the dialog isn't covered. So anyone knows about this kinda prob and helps me out? Really thx!

    modified on Tuesday, April 20, 2010 4:51 AM

    S 1 Reply Last reply
    0
    • K Krauze

      I've overriden the funx CMyButton::DrawItem(), and some lines in it are:

      CDC\* pDC = CDC::FromHandle( lpDrawItemStruct->hDC );
      CRect rc = lpDrawItemStruct->rcItem;
      CPen pen( PS\_SOLID, 1, RGB(0,0,0) );
      CPen \*pOld = pDC->SelectObject( &pen );
      pDC->LineTo( rc.right, rc.top );
      pDC->LineTo( rc.right, rc.bottom );
      pDC->LineTo( rc.left, rc.bottom );
      pDC->LineTo( rc.left, rc.top );
      pDC->SelectObject( pOld );
      

      But the prob occurs that only the upper and left borders drawn can be seen while the lower and right can't. At first, I thought it was caused by the 3D effect of the button. But though I've added BS_FLAT, the prob still exists. In fact, I can't use the following to draw the borders:

      pDC->Rectangle( &rc );
      

      Cos I want the button background to be transparent so that the back image of the dialog isn't covered. So anyone knows about this kinda prob and helps me out? Really thx!

      modified on Tuesday, April 20, 2010 4:51 AM

      S Offline
      S Offline
      stebich
      wrote on last edited by
      #2

      1st I miss a pDC->MoveTo( rc.left, rc.top ); for the starting point before the first LineTo() 2nd Have you tried to change rc.bottom and rc.right? Decrement both should be enough to see the right and bottom lines. The rcItem rectangle defines the controls boundaries, painting outside this boundaries is prohibited by clipping.

      K 1 Reply Last reply
      0
      • S stebich

        1st I miss a pDC->MoveTo( rc.left, rc.top ); for the starting point before the first LineTo() 2nd Have you tried to change rc.bottom and rc.right? Decrement both should be enough to see the right and bottom lines. The rcItem rectangle defines the controls boundaries, painting outside this boundaries is prohibited by clipping.

        K Offline
        K Offline
        Krauze
        wrote on last edited by
        #3

        Really thx! In fact, pDC->MoveTo() isn't needed cos the GDI defines the starting point as the left-top automatically. And I use

        rc.DeflateRect(0,0,1,1);
        

        Thus the borders are all visible.

        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