The hDC isn't exposed for either Outlook forms or for VBA UserForms, if
that's what you mean by UserForm.
You would have to find the window for the form using the Win32 API's and
then from there get the hDC. It would be the same thing if you wanted to get
the hWnd of the window.
You can use FindWindow to get the hWnd of a window if you have the caption:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName$, _
ByVal lpWindowName$) As Long
FoundHwnd = FindWindow(vbNullString, strCaption)
If you don't have the caption of the window and it's the foreground window
you can get the caption this way:
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias
"GetWindowTextLengthA" _
(ByVal hWnd As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
( _
ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
hWnd = GetForegroundWindow
'Get the windowtext length
strText = Space$(GetWindowTextLength(hWnd) + 1)
'get the window text (caption)
lngReturn = GetWindowText(hWnd, strText, Len(strText))
'remove the last Chr$(0)
Caption = StripNulls(strText)
From the hWnd you can use this to get the hDC:
Public Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
hDC = GetDC(hWnd)