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. Getting a Pointer to DC from Document

Getting a Pointer to DC from Document

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

    Dear All, how can I get a pointer to DC (that is associated with the View):-> from the document class? I need a pointer to DC to do some manipulation... I am using: CDC *pDC = AfxGetMainWnd()->GetDC(); .... .... AfxGetMainWnd()->ReleaseDC(); but it's not working as expected... - A programmer's national anthem; "AAAAAHHHHH!!!!"

    I 1 Reply Last reply
    0
    • S signbit

      Dear All, how can I get a pointer to DC (that is associated with the View):-> from the document class? I need a pointer to DC to do some manipulation... I am using: CDC *pDC = AfxGetMainWnd()->GetDC(); .... .... AfxGetMainWnd()->ReleaseDC(); but it's not working as expected... - A programmer's national anthem; "AAAAAHHHHH!!!!"

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

      You can use CDocument::GetFirstViewPosition / GetNextView to get the view windows. Then, as CView inherits from CWnd, you can use CWnd::GetDC to get the view's DC. If you are in a SDI app, you can get the view straight away. In am MDI view, you potentially need to iterate ythrough them. Another alternative, is to us CDocument::UpdateAllView (...) with a custom lParam, and let the views draw on themselves. A CDocument is supposed to have no idea about how its data is displayed - thats the point of separating them! Iain.

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

        You can use CDocument::GetFirstViewPosition / GetNextView to get the view windows. Then, as CView inherits from CWnd, you can use CWnd::GetDC to get the view's DC. If you are in a SDI app, you can get the view straight away. In am MDI view, you potentially need to iterate ythrough them. Another alternative, is to us CDocument::UpdateAllView (...) with a custom lParam, and let the views draw on themselves. A CDocument is supposed to have no idea about how its data is displayed - thats the point of separating them! Iain.

        S Offline
        S Offline
        signbit
        wrote on last edited by
        #3

        Iain Clarke wrote:

        A CDocument is supposed to have no idea about how its data is displayed

        Yup! but we break the rules sometimes! ;) Actually, I just need a refrence to a DC (the View's DC) to set some parameters, I am not doing any drawing... - A programmer's national anthem; "AAAAAHHHHH!!!!"

        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