I’m trying to create a tooltip in VBA using winapi calls, basically following the tutorial from MSDN remapped to VBA with Declare statements etc. The call to CreateWindowsEx()
returns NULL
and the follow-on GetLastError()
returns 0 as well. I’ve tried both in Excel and Outlook, but it gives the same result. Is this simply not possible, or is there anything wrong with the parameters I pass to CreateWindowsEx()
?
Here is the complete code snippet:
Private Type INITCOMMONCONTROLSEX_REC
dwSize As Long
dwICC As Long
End Type
Private Const ICC_WIN95_CLASSES = &HFF
Private Declare PtrSafe Function InitCommonControlsEx Lib "Comctl32.dll" (ByRef icce As INITCOMMONCONTROLSEX_REC) As Long
Private Const WS_EX_TOPMOST As Long = &H8
Private Const WS_POPUP As Long = &H80000000
Private Const TTS_ALWAYSTIP As Long = &H1
Private Const TTS_NOPREFIX As Long = &H2
Private Const TOOLTIPS_CLASS = "tooltips_class32"
Private Declare PtrSafe Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA" (dwExStyle As Long, lpClassName As String, lpWindowName As String, _
ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As LongPtr, ByVal hMenu As LongPtr, _
ByVal hInstance As LongPtr, lpParam As Any) As LongPtr
Public Sub CreateToolTip()
Dim ret As Long
Dim retLng As LongPtr
Dim iccRec As INITCOMMONCONTROLSEX_REC
iccRec.dwSize = LenB(iccRec)
iccRec.dwICC = ICC_WIN95_CLASSES
ret = InitCommonControlsEx(iccRec)
Dim wc_info As WNDCLASSEX
wc_info.cbSize = LenB(wc_info)
ret = GetClassInfoEx(0, TOOLTIPS_CLASS, wc_info)
Dim hWndTip As LongPtr
hWndTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, vbNullString, _
WS_POPUP Or TTS_NOPREFIX Or TTS_ALWAYSTIP, _
0, 0, 0, 0, 0, 0, 0, ByVal 0)
End Sub
Brogon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.