WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Dialog Editor version 6.X
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Ballon Tool Tips on Dialogs

 Keywords: ballon tooltips tool tip dialog 

Question:

Is there a way in WinBatch or VB to create those nifty Balloon tooltips (like you see with Windows Update)? The regular tooltip is OK, but I'd like to go one better.

Answer:

Here is some sample code posted by a user:
;ToolTip control
;Guido 09/2002 - Made into UDF's Iain Dickason 1/2003 - Constants sorted and comments added by Marc Worrel 1/2003
;http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/tooltip/reflist.asp

;FUNCTIONS
;=================================================================
;=SetupToolTips - Needs to be run before AddToolTip can be called=
;DlgHandle      - WIL dialog handle                              =
;Returns        - Tool window handle                             =
;=================================================================
#DefineFunction SetupToolTips(DlgHandle)
;~~~~~CONSTANTS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   HWND_TOPMOST    = -1           ;Stay on top
   ICC_BAR_CLASSES = 4            ;Load toolbar, status bar, trackbar, and ToolTip control classes;
   ;-----WindowPosition--------------------------
   SWP_NOSIZE      = 1            ;Retains the current size (ignores the cx and cy parameters
   SWP_NOMOVE      = 2            ;Retains the current position (ignores X and Y parameters)
   SWP_NOACTIVATE  = 16           ;Does not activate the window
   ;-----ToolTip Styles--------------------------
   TTS_ALWAYSTIP   = 1            ;Shows tooltip on mouseover even if window is not active
   TTS_NOPREFIX    = 2            ;Prevents the system from stripping the ampersand character from a string
   TTS_NOANIMATE   = 16           ;Disables sliding ToolTip animation on Win98/ME/2k/XP 
   TTS_NOFADE      = 32           ;Disables fading ToolTip animation on Windows 2k/XP systems
   TTS_BALLOON     = 64           ;Gives ToolTip cartoon "balloon" appearance, with stem 
   ;-----Window styles---------------------------
   WS_EX_TOPMOST   = 8            ;Always on top
   WS_POPUP        = 2147483648   ;Window has Popup style
   CW_USEDEFAULT   = 2147483648   ;Uses default position for window's upper-left, ignores Y parameter   
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   hInst=DllHinst("")                                      ;Get instance handle of dialog window
   User32=StrCat (DirWindows(1),"User32.dll")
   ComCtl32=StrCat (DirWindows(1),"ComCtl32.dll")
   ;-----Initialize common controls--------------
   COMMONCONTROLSEX=BinaryAlloc(8)                         ;Create buffer for CommonControlsEX buffer
   BinaryPoke4 (COMMONCONTROLSEX,0,8)
   BinaryPoke4 (COMMONCONTROLSEX,4,ICC_BAR_CLASSES)
   ICC=DllCall (ComCtl32,long:"InitCommonControlsEx",lpbinary:COMMONCONTROLSEX)
   BinaryFree  (COMMONCONTROLSEX)                          ;Free CommonControlsEX buffer
   ;-----Create ToolWindow-----------------------
   TTS_Styles=TTS_NOPREFIX|TTS_ALWAYSTIP|TTS_BALLOON       ;Determine Style flags for ToolTips
   HTT=DllCall (User32,long:"CreateWindowExA",long:WS_EX_TOPMOST,lpstr:"tooltips_class32",lpstr:"",long:TTS_Styles,long:CW_USEDEFAULT,long:CW_USEDEFAULT,long:CW_USEDEFAULT,long:CW_USEDEFAULT,long:DlgHandle,long:0,long:hInst,long:0)
   DllCall (User32,long:"SetWindowPos",long:HTT,long:HWND_TOPMOST,long:0,long:0,long:0,long:0,long:SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE)
   Return (HTT)
#EndFunction

;========================================================================
;=AddToolTip - Used to add a tooltip to a control                       =
;= HTT       - Tool window handle returned by SetupToolTips()           =
;= DlgHandle - The handle of the dialog (passed from the dialog callback=
;= CtrNumber - The number of the control from the dialog setup          =
;= Text      - The text to display as the tooltip                       =
;========================================================================
#DefineFunction AddToolTip(htt,DlgHandle,CtrNumber,Text)
AddExtender ("WWCTL34I.DLL")      ;Control Manager extender
;~~~~~CONSTANTS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   WM_USER         = 1024         ;Helps define private messages for use by private window classes
   TTM_ADDTOOL     = WM_USER+4    ;Defines integer for private window class
   ;-----ToolInfo.uFlags-------------------------
   TTF_IDISHWND    = 1            ;Indicates that the uId member is the window handle to the tool
   TTF_CENTERTIP   = 2            ;Centers the ToolTip window below the control
   TTF_RTLREADING  = 4            ;Right-to-left text (actually, opposite direction of control)
   TTF_SUBCLASS    = 16           ;Indicates that ToolTip should subclass tool's window to intercept messages
   TTF_TRACK       = 32           ;Keeps ToolTip next to control even if it moves
   TTF_ABSOLUTE    = 128          ;Positions ToolTip at same coordinates provided by TTM_TRACKPOSITION (Requires TTF_TRACK flag) 
   TTF_TRANSPARENT = 256          ;Causes the ToolTip control to forward mouse event messages to the parent window 
   TTF_DI_SETITEM  = 32768        ;ToolTip control will retain the supplied information and not request it again  
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   hInst=DllHinst("")                                      ;Get instance handle of dialog window
   RECT=BinaryAlloc(16)                                    ;Allocate buffer for RECT structure
   CtrHandle=cWndbyseq (DlgHandle,CtrNumber)               ;Get location of control
;   CtrHandle=DllCall(StrCat(DirWindows(1),"User32.dll"),long:"GetDlgItem",long:DlgHandle,long:CtrNumber);-->must get CtrlID from RoboScripter
   DllCall (StrCat(DirWindows(1),"User32.dll"),long:"GetClientRect",long:CtrHandle,lpbinary:RECT)   ;Get coordinates of window's client area
   ;-----Tooltip text----------------------------
   TEXTBUF=BinaryAlloc(StrLen(Text)+1)
   BinaryPokeStr(TextBuf,0,Text)
   TextAd=IntControl(42,TextBuf,0,0,0)
   ;-----Fill ToolInfo structure-----------------
   TOOLINFO=BinaryAlloc(44)                                ;Create buffer for ToolInfo structure
   BinaryPoke4(TOOLINFO,0,44)                              ;ToolInfo.cbSize
   BinaryPoke4(TOOLINFO,4,TTF_SUBCLASS)                    ;ToolInfo.uFlags
   BinaryPoke4(TOOLINFO,8,CtrHandle)                       ;ToolInfo.hwnd
   BinaryPoke4(TOOLINFO,12,0)                              ;ToolInfo.uId
   BinaryPoke4(TOOLINFO,16,BinaryPeek4(RECT,0))            ;rect.left
   BinaryPoke4(TOOLINFO,20,BinaryPeek4(RECT,4))            ;rect.top
   BinaryPoke4(TOOLINFO,24,BinaryPeek4(RECT,8))            ;rect.right
   BinaryPoke4(TOOLINFO,28,BinaryPeek4(RECT,12))           ;rect.bottom
   BinaryPoke4(TOOLINFO,32,hInst)                          ;ToolInfo.hinst
   BinaryPoke4(TOOLINFO,36,TextAd)                         ;ToolInfo.lpszText
   BinaryPoke4(TOOLINFO,40,0)                              ;ToolInfo.lParam
   ;-----Add tooltip-----------------------------
   RetVal=DllCall(StrCat(DirWindows(1),"User32.dll"),long:"SendMessageA",long:HTT,long:TTM_ADDTOOL,long:0,lpbinary:TOOLINFO)
   BinaryFree(TEXTBUF)
	BinaryFree(RECT)
   BinaryFree(TOOLINFO)
   Return (RetVal)
#EndFunction
;==========================================

;DIALOG CALLBACK
#DefineSubRoutine DlgCallback(DlgName,DlgEvent,DlgCtrl,p4,p5)
If DlgEvent==0                                             ;Initialization
   DialogProcOptions(DlgName,2,1)                          ;Watch Buttonpress events
   HTT=SetupToolTips(DlgName)                              ;This needs to be called before the AddToolTips can be used.
   AddToolTip(HTT,DlgName,1,"This will close the dialog")  ;Add ToolTip to control #001
   AddToolTip(HTT,DlgName,2,"And this will cancel it")     ;Add ToolTip to control #002
EndIf                 
If DlgEvent==2                                             ;Button pushed
   If DlgCtrl==001                                         ;OK 
      Return (-1)
   EndIf
   If DlgCtrl==002                                         ;Cancel 
;      Message("","")
      Return (-2)
   EndIf
EndIf
Return (-1)
#EndSubRoutine

;DIALOG
MyDialogFormat=`WWWDLGED,6.1`
MyDialogCaption=`ToolTip Control`
MyDialogX=-1
MyDialogY=-1
MyDialogWidth=234
MyDialogHeight=098
MyDialogNumControls=002
MyDialogProcedure=`DlgCallback`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialog001=`053,077,036,012,PUSHBUTTON,DEFAULT,"OK",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`145,077,036,012,PUSHBUTTON,DEFAULT,"Cancel",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ButtonPushed=Dialog("MyDialog")

;END SCRIPT
Exit


Article ID:   W15455
File Created: 2003:06:30:08:49:22
Last Updated: 2003:06:30:08:49:22