Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Thanks to Guido for the great tooltip code!
~Marc
;+========================================================================+ ;|TTCreate : Creates a tool window | ;|------------------------------------------------------------------------| ;|DlgHandle : WIL dialog handle | ;|Balloon : @TRUE : balloon tooltips (Comctl32.dll v.5.8 IE5) | ;| @FALSE : normal tooltips | ;|------------------------------------------------------------------------| ;|Returns : Tool window handle | ;+------------------------------------------------------------------------+ #DefineFunction TTCreate (DlgHandle,Balloon) ;~~~~~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 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If Balloon Then TTS_BALLOON=64 Else TTS_BALLOON=0 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=WS_POPUP|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 ;+------------------------------------------------------------------------+ ;|TTAdd : Adds a tooltip to a control | ;|------------------------------------------------------------------------| ;|HTT : Tool window handle returned by TTCreate() | ;|DlgHandle : The handle of the dialog (passed from the dialog callback) | ;|CtrlId : Real control ID obtained with Roboscripter | ;|Text : The text to display as the tooltip | ;|------------------------------------------------------------------------| ;|Returns : Returns TRUE if successful, or FALSE otherwise. | ;+------------------------------------------------------------------------+ #DefineFunction TTAdd (HTT,DlgHandle,CtrlId,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 ; CtrlId=cWndbyseq (DlgHandle,CtrNumber) ;Get location of control CtrlId=DllCall(StrCat(DirWindows(1),"User32.dll"),long:"GetDlgItem",long:DlgHandle,long:CtrlId);-->must get CtrlID from RoboScripter DllCall (StrCat(DirWindows(1),"User32.dll"),long:"GetClientRect",long:CtrlId,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,CtrlId) ;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(RECT) BinaryFree(TOOLINFO) Return (RetVal) #EndFunction ;+-----------------------------------------------------------------------------+ ;|TTSetMaxWidth : Sets the maximum width for a ToolTip window. | ;| Use this function only if you want a multiline tooltip. | ;|-----------------------------------------------------------------------------| ;|Htt : Tool window handle | ;|Width : Maximum ToolTip window width to be set. | ;|-----------------------------------------------------------------------------| ;|Returns : The previous maximum ToolTip width. | ;|-----------------------------------------------------------------------------| ;|Remarks : If a ToolTip string exceeds Width value, the control uses | ;|spaces to determine line breaks. If the text cannot be segmented into mult- | ;|iple lines, it will be displayed on a single line, which may exceed the Width| ;|value. A line break can be forced with @CRLF (use StrCat()) | ;+-----------------------------------------------------------------------------+ #DefineFunction TTSetMaxTipWidth (Htt,Width) User32=StrCat(DirWindows(1),"User32.dll") TTM_SETMAXTIPWIDTH=1024+24 Return DllCall(User32,long:"SendMessageA",long:htt,long:TTM_SETMAXTIPWIDTH,long:0,long:Width) #EndFunction #DefineSubRoutine DlgCallback (DlgName,DlgEvent,DlgCtrl,Res4,Res5) If DlgEvent==00 ;Dialog initialization DialogProcOptions (DlgName,2,1) ;Watch for button presses DialogProcOptions (DlgName,7,1) ;Watch ItemBox_Select event HTT=TTCreate (DlgName,@TRUE) ;This needs to be called before the TTAdd can be used. TTSetMaxTipWidth (HTT,128) EndIf If DlgEvent==02 ;Button press event If DlgCtrl==001 Then Exit EndIf If DlgEvent==07 ToolTip="" ;Clear Tooltip AllItems=DialogControlGet (DlgName,002,5) Selected=DialogControlGet (DlgName,002,6) ; If ItemLocate ("Item1",Selected,@TAB) Then ToolTip=StrCat (ToolTip,"Item1 is selected",@TAB) ; If ItemLocate ("Item2",Selected,@TAB) Then ToolTip=StrCat (ToolTip,"Item2 is selected",@TAB) ; If ItemLocate ("Item3",Selected,@TAB) Then ToolTip=StrCat (ToolTip,"Item3 is selected",@TAB) ;Determine selected items For EachItem=1 To ItemCount (Selected,@TAB) ThisItem=ItemExtract (EachItem,Selected,@TAB) ToolTip=StrCat (ToolTip,ThisItem," is selected",@TAB) Next If ItemExtract (-1,Selected,@TAB)=="" Then Selected=ItemRemove (-1,Selected,@TAB) Selected=StrReplace (Selected,@TAB,@CRLF) TTAdd (HTT,DlgName,101,ToolTip) ;Add ToolTip to control #002 EndIf Return (-2) #EndSubRoutine ;Generate list of items Items=StrCat("Item1|Item2|Item3|Item4|Item5|Item6|Item7|Item8|Item9|Item10") Items=StrReplace (Items,"|",@TAB) ItemPopupFormat=`WWWDLGED,6.1` ItemPopupCaption=`Popup Item Descriptions` ItemPopupX=039 ItemPopupY=080 ItemPopupWidth=166 ItemPopupHeight=135 ItemPopupNumControls=002 ItemPopupProcedure=`DlgCallback` ItemPopupFont=`DEFAULT` ItemPopupTextColor=`DEFAULT` ItemPopupBackground=`DEFAULT,DEFAULT` ItemPopupConfig=1 ItemPopup001=`65,112,036,012,PUSHBUTTON,DEFAULT,"&Quit",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ItemPopup002=`007,009,148,106,ITEMBOX,Items,DEFAULT,DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ItemPopupButtonPushed=Dialog("ItemPopup") Exit
Article ID: W15924
File Created: 2004:03:30:15:41:42
Last Updated: 2004:03:30:15:41:42