I moved the following code from an MFC dialog-based project to an MFC library dll:
CWnd dummyWnd;
standard = new Gdiplus::Font(dummyWnd.GetDC()->GetSafeHdc(), &logfont); //GetDC() returns null, which did not happen in an MFC dialog-based app
I need a temporary DC to create gdiplus fonts, measure strings and other utility functionality.
My Questions:
- is it possible to use CWnd as I've done in the dialog based app?
- or can I simply get a DC for that purpose in another way?
CWnd dummyWnd;
creates a unattached (no window)CWnd
object; thendummyWnd.GetDC();
tries to get a client area Device Context with no window attached. This should fail. See: docs.microsoft.com/en-us/cpp/mfc/reference/… and docs.microsoft.com/en-us/cpp/mfc/reference/… – Richard CrittenCDC::GetSafeHdc
: strange remark in the docs "...this member function also works with null pointers...." Your guess as to what that means is a good as mine. source: docs.microsoft.com/en-us/cpp/mfc/reference/… – Richard CrittenCClientDC dc(NULL)
to get desktop dc, followed byCreateCompatibleDC
... see example – Barmak Shemirani