一个类模块,命名为:ctooltip,代码如下:
option explicit
private declare sub initcommoncontrols lib "comctl32.dll" ()
''windows api functions
private declare function createwindowex lib "user32" alias "createwindowexa" (byval dwexstyle as long, byval lpclassname as string, byval 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 long, byval hmenu as long, byval hinstance as long, lpparam as any) as long
private declare function sendmessage lib "user32" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long
private declare function sendmessagelong lib "user32" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, byval lparam as long) as long
private declare function destroywindow lib "user32" (byval hwnd as long) as long
''windows api constants
private const wm_user = &h400
private const cw_usedefault = &h80000000
''windows api types
private type rect
left as long
top as long
right as long
bottom as long
end type
''tooltip window constants
private const tts_noprefix = &h2
private const ttf_transparent = &h100
private const ttf_centertip = &h2
private const ttm_addtoola = (wm_user + 4)
private const ttm_activate = wm_user + 1
private const ttm_updatetiptexta = (wm_user + 12)
private const ttm_setmaxtipwidth = (wm_user + 24)
private const ttm_settipbkcolor = (wm_user + 19)
private const ttm_settiptextcolor = (wm_user + 20)
private const ttm_settitle = (wm_user + 32)
private const tts_balloon = &h40
private const tts_alwaystip = &h1
private const ttf_subclass = &h10
private const ttf_idishwnd = &h1
private const ttm_setdelaytime = (wm_user + 3)
private const ttdt_autopop = 2
private const ttdt_initial = 3
private const tooltips_classa = "tooltips_class32"
''tooltip window types
private type toolinfo
lsize as long
lflags as long
hwnd as long
lid as long
lprect as rect
hinstance as long
lpstr as string
lparam as long
end type
public enum tticontype
ttnoicon = 0
tticoninfo = 1
tticonwarning = 2
tticonerror = 3
end enum
public enum ttstyleenum
ttstandard
ttballoon
end enum
'local variable(s) to hold property value(s)
private mvarbackcolor as long
private mvartitle as string
private mvarforecolor as long
private mvaricon as tticontype
private mvarcentered as boolean
private mvarstyle as ttstyleenum
private mvartiptext as string
private mvarvisibletime as long
private mvardelaytime as long
'private data
private m_ltthwnd as long ' hwnd of the tooltip
private m_lparenthwnd as long ' hwnd of the window the tooltip attached to
private ti as toolinfo
public property let style(byval vdata as ttstyleenum)
'used when assigning a value to the property, on the left side of an assignment.
'syntax: x.style = 5
mvarstyle = vdata
end property
public property get style() as ttstyleenum
'used when retrieving value of a property, on the right side of an assignment.
'syntax: debug.print x.style
style = mvarstyle
end property
public property let centered(byval vdata as boolean)
'used when assigning a value to the property, on the left side of an assignment.
'syntax: x.centered = 5
mvarcentered = vdata
end property
public property get centered() as boolean
'used when retrieving value of a property, on the right side of an assignment.
'syntax: debug.print x.centered
centered = mvarcentered
end property
public function create(byval parenthwnd as long) as boolean
dim lwinstyle as long
if m_ltthwnd <> 0 then
destroywindow m_ltthwnd
end if
m_lparenthwnd = parenthwnd
lwinstyle = tts_alwaystip or tts_noprefix
''create baloon style if desired
if mvarstyle = ttballoon then lwinstyle = lwinstyle or tts_balloon
m_ltthwnd = createwindowex(0&, _