Am I doing this correctly with a font?
Yes.
Do I need to restore the old BkMode bkmodeprev using SetBkMode(dc, bkmodeprev) , or will EndPaint do this for me?
EndPaint will not restore the background mix mode for you. But EndPaint destroys the device context, so it does not need to be restored. However, in my opinion, the best practice is to restore the background mixing mode whenever you change it. Then, if you expand the code in the future, you will not be surprised. But this is really a preference. You can take a different position.
Do I need to free DC?
No, an EndPaint call is EndPaint .
I would write it like this:
dc := BeginPaint(hDlg, ps); bkmodeprev := SetBkMode(dc, TRANSPARENT); hfnt := SendMessage(hDlg, WM_GETFONT, 0, 0); hfntPrev := SelectObject(dc, hfnt); DrawTextW(dc, 'Text', -1, R, DT_SINGLELINE or DT_CENTER or DT_VCENTER); SelectObject(dc, hfntPrev); SetBkMode(dc, bkmodeprev); EndPaint(hDlg, ps);
Although, it can be argued that it would be better to include some error checking.
As pointed out in the comments, you need to provide a return value for the WM_PAINT message. From docs :
If the dialog procedure processes a message that requires a specific return value, the dialog procedure must set the desired return value by calling SetWindowLong (hwndDlg, DWL_MSGRESULT, lResult) immediately before returning TRUE. Note that you must immediately call SetWindowLong before returning TRUE; this may cause the DWL_MSGRESULT value to be overwritten by the nested dialog box.