Determining DPI
-
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
-
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
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 (likeGetDC()
) 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! -
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 (likeGetDC()
) 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!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