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. how not to draw outside a static control?

how not to draw outside a static control?

Scheduled Pinned Locked Moved C / C++ / MFC
questionlearning
6 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.
  • C Offline
    C Offline
    code_discuss
    wrote on last edited by
    #1

    I'm using a static control to draw something on it. the static is in a dialog create by resource editer. It's strange that I can draw outside the static contol, but not outside the dialog. How can I prevent this? I want to draw only inside the static contol.

    S M 2 Replies Last reply
    0
    • C code_discuss

      I'm using a static control to draw something on it. the static is in a dialog create by resource editer. It's strange that I can draw outside the static contol, but not outside the dialog. How can I prevent this? I want to draw only inside the static contol.

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      Check out the CS_PARENTDC windows class style for information on why this happens. One solution is simply not to draw outside the window! Another is to set a clipping region with the GetDCEx function.

      Steve

      1 Reply Last reply
      0
      • C code_discuss

        I'm using a static control to draw something on it. the static is in a dialog create by resource editer. It's strange that I can draw outside the static contol, but not outside the dialog. How can I prevent this? I want to draw only inside the static contol.

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        When you draw in a DC, you can't draw outside the window that the DC is for. So it sounds like you're getting a DC for the dialog, not the control.

        --Mike-- Visual C++ MVP :cool: LINKS~! CP SearchBar v3.0 | C++ Forum FAQ I work for Keyser Söze

        S 1 Reply Last reply
        0
        • M Michael Dunn

          When you draw in a DC, you can't draw outside the window that the DC is for. So it sounds like you're getting a DC for the dialog, not the control.

          --Mike-- Visual C++ MVP :cool: LINKS~! CP SearchBar v3.0 | C++ Forum FAQ I work for Keyser Söze

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          You can if the window class has the CS_PARENTDC style set. From MSDN:

          CS_PARENTDC Sets the clipping rectangle of the child window to that of the parent window so that the child can draw on the parent. A window with the CS_PARENTDC style bit receives a regular device context from the system's cache of device contexts. It does not give the child the parent's device context or device context settings. Specifying CS_PARENTDC enhances an application's performance.

          Steve

          C M 2 Replies Last reply
          0
          • S Stephen Hewitt

            You can if the window class has the CS_PARENTDC style set. From MSDN:

            CS_PARENTDC Sets the clipping rectangle of the child window to that of the parent window so that the child can draw on the parent. A window with the CS_PARENTDC style bit receives a regular device context from the system's cache of device contexts. It does not give the child the parent's device context or device context settings. Specifying CS_PARENTDC enhances an application's performance.

            Steve

            C Offline
            C Offline
            code_discuss
            wrote on last edited by
            #5

            Yes I agree. Thank you very much, you did let know why I have this bug and how I can fix it. I used SelectClipRgn() to fix it, which is similiar to your GetDCEx.

            1 Reply Last reply
            0
            • S Stephen Hewitt

              You can if the window class has the CS_PARENTDC style set. From MSDN:

              CS_PARENTDC Sets the clipping rectangle of the child window to that of the parent window so that the child can draw on the parent. A window with the CS_PARENTDC style bit receives a regular device context from the system's cache of device contexts. It does not give the child the parent's device context or device context settings. Specifying CS_PARENTDC enhances an application's performance.

              Steve

              M Offline
              M Offline
              Michael Dunn
              wrote on last edited by
              #6

              That looks like an optimization that made sense when our computers were running at 4.77 MHz. ;)

              --Mike-- Visual C++ MVP :cool: LINKS~! CP SearchBar v3.0 | C++ Forum FAQ I work for Keyser Söze

              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