Owner Draw Elements in Custom Forms

  • Thread starter Thread starter frank vandalay
  • Start date Start date
F

frank vandalay

Hello,

im creating an COM Addin (OL 2000) with dynamic custom form in the
appointment item. I need to draw some custom element on the UserForm
using LineTo or DrawText. Does somebody know, if there are any
possibilities to catch the handle (hdc) of the UserForm?

Thanks for help!

Frank
 
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)
 
Back
Top