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. Change the shape of CEdit custom draw?

Change the shape of CEdit custom draw?

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicsquestion
8 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.
  • K Offline
    K Offline
    karhong
    wrote on last edited by
    #1

    Hi, I've created CCustomEdit inherited from CEdit and managed to change its background color and text color. I'm trying to change the shape of it ( eg : on each end i plan to make it like curve a bit rather than 90 degrees ) Is there any ways to change the shape of the CEdit ? Any tutorials/sample would be highly appreciated. Can GDI able to change the style of it? My project is MFC based. With thanks, KarHong

    good

    N C 2 Replies Last reply
    0
    • K karhong

      Hi, I've created CCustomEdit inherited from CEdit and managed to change its background color and text color. I'm trying to change the shape of it ( eg : on each end i plan to make it like curve a bit rather than 90 degrees ) Is there any ways to change the shape of the CEdit ? Any tutorials/sample would be highly appreciated. Can GDI able to change the style of it? My project is MFC based. With thanks, KarHong

      good

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      karhong wrote:

      Is there any ways to change the shape of the CEdit ?

      Not only edit control, but the shape of any window can be changed by setting appropriate region. In your case, create a round rect region using the CreateRoundRectRgn() function and set that region to the edit control using the SetWindowRgn() function.

      nave [OpenedFileFinder] [My Blog]

      K 2 Replies Last reply
      0
      • K karhong

        Hi, I've created CCustomEdit inherited from CEdit and managed to change its background color and text color. I'm trying to change the shape of it ( eg : on each end i plan to make it like curve a bit rather than 90 degrees ) Is there any ways to change the shape of the CEdit ? Any tutorials/sample would be highly appreciated. Can GDI able to change the style of it? My project is MFC based. With thanks, KarHong

        good

        C Offline
        C Offline
        Chandrasekharan P
        wrote on last edited by
        #3

        This may help you http://www.codeproject.com/KB/edit/EditStyle.aspx

        K 1 Reply Last reply
        0
        • N Naveen

          karhong wrote:

          Is there any ways to change the shape of the CEdit ?

          Not only edit control, but the shape of any window can be changed by setting appropriate region. In your case, create a round rect region using the CreateRoundRectRgn() function and set that region to the edit control using the SetWindowRgn() function.

          nave [OpenedFileFinder] [My Blog]

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

          Thank you very much.. I'll get back to you later after i tried your method..

          good

          1 Reply Last reply
          0
          • C Chandrasekharan P

            This may help you http://www.codeproject.com/KB/edit/EditStyle.aspx

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

            Hi, I've tested out but the shape of the box is still square. Thanks for your reply

            good

            1 Reply Last reply
            0
            • N Naveen

              karhong wrote:

              Is there any ways to change the shape of the CEdit ?

              Not only edit control, but the shape of any window can be changed by setting appropriate region. In your case, create a round rect region using the CreateRoundRectRgn() function and set that region to the edit control using the SetWindowRgn() function.

              nave [OpenedFileFinder] [My Blog]

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

              what place should i place the CreateRoundRectRgn() and SetWindowRgn() ? I've try below code but it seems like the EditBox keep on blinking CRect rcItem; CDC* pDC=this->GetDC(); this->GetClientRect(&rcItem); CRgn rgn; rgn.CreateRoundRectRgn(rcItem.left, rcItem.top, rcItem.right, rcItem.bottom, 50, 50); SetWindowRgn( (HRGN)rgn.Detach(), TRUE ); Thanks, KarHong

              good

              N 1 Reply Last reply
              0
              • K karhong

                what place should i place the CreateRoundRectRgn() and SetWindowRgn() ? I've try below code but it seems like the EditBox keep on blinking CRect rcItem; CDC* pDC=this->GetDC(); this->GetClientRect(&rcItem); CRgn rgn; rgn.CreateRoundRectRgn(rcItem.left, rcItem.top, rcItem.right, rcItem.bottom, 50, 50); SetWindowRgn( (HRGN)rgn.Detach(), TRUE ); Thanks, KarHong

                good

                N Offline
                N Offline
                Naveen
                wrote on last edited by
                #7

                karhong wrote:

                what place should i place the CreateRoundRectRgn() and SetWindowRgn() ?

                The PreSubclassWindow() function is a good place.

                karhong wrote:

                CDC* pDC=this->GetDC();

                Why are you calling this function?

                nave [OpenedFileFinder] [My Blog]

                K 1 Reply Last reply
                0
                • N Naveen

                  karhong wrote:

                  what place should i place the CreateRoundRectRgn() and SetWindowRgn() ?

                  The PreSubclassWindow() function is a good place.

                  karhong wrote:

                  CDC* pDC=this->GetDC();

                  Why are you calling this function?

                  nave [OpenedFileFinder] [My Blog]

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

                  oh i'm using the pDC to draw the rectangle. That one I'm just testing out with the link given by Chandrasekharanp I'm taking pDC out now and try your method. But after i put below code, and execute it then the button went dissapear void CCustomEdit::PreSubclassWindow() { CRect rcItem; this->GetClientRect(&rcItem); CRgn rgn; rgn.CreateRoundRectRgn(rcItem.left, rcItem.top, rcItem.right, rcItem.bottom, 50, 50); SetWindowRgn( (HRGN)rgn.Detach(), TRUE ); CEdit::PreSubclassWindow(); }

                  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