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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Displaying painted areas on Property Sheet

Displaying painted areas on Property Sheet

Scheduled Pinned Locked Moved C / C++ / MFC
questionarchitecturehelp
8 Posts 4 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
    koumodaki
    wrote on last edited by
    #1

    I have a property page with a static control area defined as CONTROL "",IDC_TEMP_GRPH,"Static",SS_GRAYFRAME,154,44,135,129 I am handling WM_PAINT message and the following piece of code gets executed: CDC* pDC = new CDC(GetDC(this->m_hWnd)); HWND hStatic = GetDlgItem(m_hWnd,IDC_TEMP_GRPH); RECT pirect; GetClientRect(hStatic,&pirect); COLORREF bkColor; bkColor = RGB(225,0,0); HBRUSH hBrush = ::CreateSolidBrush(bkColor); ::FillRect(GetDC(hStatic),&pirect,hBrush); The problem is I am not able to see this solid color block. It appears blinking while I drag the Property Sheet but disappears when I switch to next page and switch back to that page. Can anyone please tell me what is missing here?

    I C 2 Replies Last reply
    0
    • K koumodaki

      I have a property page with a static control area defined as CONTROL "",IDC_TEMP_GRPH,"Static",SS_GRAYFRAME,154,44,135,129 I am handling WM_PAINT message and the following piece of code gets executed: CDC* pDC = new CDC(GetDC(this->m_hWnd)); HWND hStatic = GetDlgItem(m_hWnd,IDC_TEMP_GRPH); RECT pirect; GetClientRect(hStatic,&pirect); COLORREF bkColor; bkColor = RGB(225,0,0); HBRUSH hBrush = ::CreateSolidBrush(bkColor); ::FillRect(GetDC(hStatic),&pirect,hBrush); The problem is I am not able to see this solid color block. It appears blinking while I drag the Property Sheet but disappears when I switch to next page and switch back to that page. Can anyone please tell me what is missing here?

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

      Rather than painting from your dialog, try over-riding the static control. Have a look at this article: http://www.codeproject.com/KB/miscctrl/generic_picker.aspx[^] It's not talked about in the article itself, but it uses an owner draw static control to do the pretty picture bit. Feel free to stealreuse it from me. Iain.

      CPalliniC K 2 Replies Last reply
      0
      • K koumodaki

        I have a property page with a static control area defined as CONTROL "",IDC_TEMP_GRPH,"Static",SS_GRAYFRAME,154,44,135,129 I am handling WM_PAINT message and the following piece of code gets executed: CDC* pDC = new CDC(GetDC(this->m_hWnd)); HWND hStatic = GetDlgItem(m_hWnd,IDC_TEMP_GRPH); RECT pirect; GetClientRect(hStatic,&pirect); COLORREF bkColor; bkColor = RGB(225,0,0); HBRUSH hBrush = ::CreateSolidBrush(bkColor); ::FillRect(GetDC(hStatic),&pirect,hBrush); The problem is I am not able to see this solid color block. It appears blinking while I drag the Property Sheet but disappears when I switch to next page and switch back to that page. Can anyone please tell me what is missing here?

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

        First, use CPaintDC in the WM_PAINT message handler, not GetDC, and second, when you do this:

        GetClientRect(hStatic,&pirect);

        You get the client area of the static, not its position in the client area of its parent. If you want to know where the static lies inside of its parent use some coord mapping functions or simply this:

        RECT pirect;
        GetWindowRect(hStatic,&pirect);
        ScreenToClient(&pirect);

        > The problem with computers is that they do what you tell them to do and not what you want them to do. <

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

          Rather than painting from your dialog, try over-riding the static control. Have a look at this article: http://www.codeproject.com/KB/miscctrl/generic_picker.aspx[^] It's not talked about in the article itself, but it uses an owner draw static control to do the pretty picture bit. Feel free to stealreuse it from me. Iain.

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          Got my 5, thank you for posting it. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

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

            Rather than painting from your dialog, try over-riding the static control. Have a look at this article: http://www.codeproject.com/KB/miscctrl/generic_picker.aspx[^] It's not talked about in the article itself, but it uses an owner draw static control to do the pretty picture bit. Feel free to stealreuse it from me. Iain.

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

            Thanks. But I foound out what was missing from my code. I had to add PAINTSTRUCT ps; HDC hdc = ::BeginPaint(m_hWnd, &ps); at the start and ::EndPaint(m_hWnd, &ps); at end of my code snippet and it works. :)

            1 Reply Last reply
            0
            • C Code o mat

              First, use CPaintDC in the WM_PAINT message handler, not GetDC, and second, when you do this:

              GetClientRect(hStatic,&pirect);

              You get the client area of the static, not its position in the client area of its parent. If you want to know where the static lies inside of its parent use some coord mapping functions or simply this:

              RECT pirect;
              GetWindowRect(hStatic,&pirect);
              ScreenToClient(&pirect);

              > The problem with computers is that they do what you tell them to do and not what you want them to do. <

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

              I am using SDK so CPaintDC is ruled out. So I have to add BeginPaint() and EndPaint() instead fro it to work.

              1 Reply Last reply
              0
              • CPalliniC CPallini

                Got my 5, thank you for posting it. :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

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

                Thanks. I've got so much useful code from CP, I like to give back when I can. I hope you've added yourself to pointy haired thread hijackers list... Iain.

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

                  Thanks. I've got so much useful code from CP, I like to give back when I can. I hope you've added yourself to pointy haired thread hijackers list... Iain.

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #8

                  Iain Clarke wrote:

                  I hope you've added yourself to pointy haired thread hijackers list...

                  Well, since I'm (together with Rajesh) the proud founder of the Brigade, my name is necessarily there. :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  In testa che avete, signor di Ceprano?

                  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