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. Determining DPI

Determining DPI

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
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.
  • J Offline
    J Offline
    JD Steffen
    wrote on last edited by
    #1

    Hello all, Got a small problem that I was hoping I could get some help on. Using the CView class I need to get the current screen DPI. I know that I can use the GetDeviceCaps method in the CDC class to get the current DPI. The problem is that I want to retreive the values and store them somewhere in a variable BEFORE CView's OnDraw method. For example I tried this in CView's constuctor: CTestView::CTestView() { CDC *Test; Test = GetDC(); PixPerInchX=Test->GetDeviceCaps(LOGPIXELSX); PixPerInchY=Test->GetDeviceCaps(LOGPIXELSY); ReleaseDC(Test); } PixPerInchX, and PixPerInchY are defined elsewhere as an INT. When I run this, it ASSERT fails. I think that my Test pointer is coming up NULL. Any ideas? (P.S. I'm not a very good programmer yet, so if this is stupidly obvious I apologize.) Thanks, JD

    M 1 Reply Last reply
    0
    • J JD Steffen

      Hello all, Got a small problem that I was hoping I could get some help on. Using the CView class I need to get the current screen DPI. I know that I can use the GetDeviceCaps method in the CDC class to get the current DPI. The problem is that I want to retreive the values and store them somewhere in a variable BEFORE CView's OnDraw method. For example I tried this in CView's constuctor: CTestView::CTestView() { CDC *Test; Test = GetDC(); PixPerInchX=Test->GetDeviceCaps(LOGPIXELSX); PixPerInchY=Test->GetDeviceCaps(LOGPIXELSY); ReleaseDC(Test); } PixPerInchX, and PixPerInchY are defined elsewhere as an INT. When I run this, it ASSERT fails. I think that my Test pointer is coming up NULL. Any ideas? (P.S. I'm not a very good programmer yet, so if this is stupidly obvious I apologize.) Thanks, JD

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

      Look at the assertion that is failing for an idea of what MFC was testing for. When the CTestView constructor runs, it's not yet a window, it's just a C++ object, so any window-related functions that operate on the view window (like GetDC()) will fail. CView::OnInitialUpdate() is a good place for initialization. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- Wizard needs food, badly!

      J 1 Reply Last reply
      0
      • M Michael Dunn

        Look at the assertion that is failing for an idea of what MFC was testing for. When the CTestView constructor runs, it's not yet a window, it's just a C++ object, so any window-related functions that operate on the view window (like GetDC()) will fail. CView::OnInitialUpdate() is a good place for initialization. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- Wizard needs food, badly!

        J Offline
        J Offline
        JD Steffen
        wrote on last edited by
        #3

        Okay, that worked. However when the code runs inside of OnInitalUpdate GetDeviceCaps returns garbage. (Well, the variable contains garbage when I look at it, anyways). When I run the same code inside the OnDraw it returns the expected value. (96) Any ideas on that one? Thanks, JD

        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