PDA

View Full Version : Getting the Device Context



11-24-2002, 03:34 PM
I'm trying to create an opengl window with mfc. When I write "GetDC(hWnd)" in Oncreate, the compiler says "function does not take 1 parameters." Can anybody tell me what I might have done wrong?

11-24-2002, 08:16 PM
I presume this comes from a CWindow or derivative....

In the MSDN docs it says this...

HDC GetDC(HWND)

and in the class CWindow

HDC GetDC()

you are calling the latter in your class, which is fine omit the parameter unless the hwnd is not the CWindow. In that case call

::GetDC(HWND) (notice particularly the "::") to get to global scope

Deiussum
11-25-2002, 05:47 AM
There's also

CDC* CWnd::GetDC();

In that case if you want an HDC for that particular window, you can do something like this..

HDC hDC = GetDC()->GetSafeHdc();