Tony Burcham's code (2003/2004) slightly modified by Chris Holbrook June 2008 to do multi-line tips. Note that the label needs the SS_NOTIFY style to get tooltipped!
Small compileable DTT example containing Tony's original SDK code.
Small compileable DTT example containing Tony's original SDK code.
Code:
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' slightly modified by Chris Holbrook June 2008 ' to do multi-line tips. Note that the label needs the SS_NOTIFY ' style to get tooltipped! ' DTT example containing Tony's original SDK code. ' "ToolTips.inc" by Tony Burcham from PB forums 2003/2004 '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #COMPILE EXE #DIM ALL #INCLUDE "WIN32API.INC" #INCLUDE "COMMCTRL.INC" %IDD_DIALOG1 = 101 %IDC_TEXTBOX1 = 1001 %IDC_TEXTBOX2 = 1002 %IDC_LABEL1 = 1003 %IDC_LISTBOX1 = 1004 %IDC_SYSLISTVIEW32_1 = 1005 %IDC_BUTTON1 = 1006 '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ 'The first call only initializes it. Subsequent 'calls will add tips. 'tl is the ID or window handle of the tool 'to receive the tip. 'To set a tooltip for a control using its 'ID, set hToolParWnd to the parent dialog's 'handle. 'To set a tooltip for a control using it's 'window handle set hToolParWnd to 0 'Global hToolParWnd As Dword 'handle of tooltip's parent window GLOBAL hWndToolTip AS DWORD '----------------------------------------------------------------- SUB CreateTip( hDlg AS DWORD, tl AS DWORD, Tip AS STRING ) STATIC Crt AS CREATESTRUCT STATIC TlInfo AS TOOLINFO STATIC hInst AS LONG IF hWndToolTip THEN 'it's been initialized IF tl = 0 THEN EXIT IF 'Tip = Left$(Tip, 79) CONTROL HANDLE hDlg, tl TO tl TlInfo.hwnd = tl TlInfo.uId = tl TlInfo.lpszText = STRPTR(Tip) SendMessage( hWndToolTip, %TTM_ADDTOOL, 0, VARPTR( TlInfo ) ) SendMessage( hWndToolTip, %TTM_ACTIVATE, 1, 0 ) ELSE 'just initializing this time through LOCAL ice AS INIT_COMMON_CONTROLSEX ice.dwSize = SIZEOF(ice) ice.dwICC = %ICC_WIN95_CLASSES InitCommonControlsEx(ice) hInst = GetModuleHandle("") Tip = "ToolTip" Crt.lpCreateParams = 0 Crt.hInstance = hInst Crt.hMenu = 0 Crt.hwndParent = hDlg Crt.style = %WS_POPUP OR %TTS_NOPREFIX OR %TTS_ALWAYSTIP Crt.lpszName = STRPTR(Tip) Tip = $TOOLTIPS_CLASS Crt.lpszClass = STRPTR(Tip) Crt.dwExStyle = %WS_EX_TOPMOST hWndToolTip = CreateWindowEx( %WS_EX_TOPMOST, $TOOLTIPS_CLASS, "", _ %WS_POPUP OR %TTS_NOPREFIX OR %TTS_ALWAYSTIP OR %TTS_BALLOON, _ %CW_USEDEFAULT, %CW_USEDEFAULT, %CW_USEDEFAULT, _ %CW_USEDEFAULT, hDlg, 0, hInst, Crt ) DIALOG SEND hWndToolTip, %TTM_SETMAXTIPWIDTH, 0, 200 SetWindowPos( hWndToolTip, %HWND_TOPMOST, 100, 100, 300, 300, _ %SWP_NOMOVE OR %SWP_NOSIZE OR %SWP_NOACTIVATE ) SendMessage( hWndToolTip, %TTM_SETDELAYTIME, %TTDT_INITIAL, 100 ) 'time a pointer must remain stationary before the tooltip appears SendMessage( hWndToolTip, %TTM_SETDELAYTIME, %TTDT_AUTOPOP, 5000 ) 'time a tooltip window remains visible If the Pointer is stationary SendMessage( hWndToolTip, %TTM_SETDELAYTIME, %TTDT_RESHOW, 500 ) 'time before subsequent tooltips to appear '------------------------------ TlInfo.cbSize = SIZEOF( TOOLINFO ) 'this doesn't make sense, but it works TlInfo.uFlags = %TTF_SUBCLASS OR %TTS_ALWAYSTIP OR %TTS_BALLOON OR %TTF_CENTERTIP 'if hToolParWnd <> 0 then tl is a control ID instead of a window handle TlInfo.hinst = hInst END IF 'hWndToolTip END SUB 'CreateTip '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ SUB SetToolTips(hDlg AS DWORD) STATIC f AS LONG IF f THEN EXIT SUB ELSE INCR f 'make sure it only runs once CreateTip hDlg, 0, "" 'initialize tooltips CreateTip hDlg, %IDD_DIALOG1, "dialog" CreateTip hDlg, %IDC_TEXTBOX1, "There are three friendships which are advantageous, and three which are injurious" + $CRLF + _ "Friendship with the uplight; friendship with the sincere; and friendship with the man of much observation:-these are advantageous. " + $CRLF + _ "Friendship with the man of specious airs; friendship with the insinuatingly soft; and friendship with the glib-tongued:-these are injurious." CreateTip hDlg, %IDC_TEXTBOX2, "TB2" CreateTip hDlg, %IDC_LABEL1, " The mean man does not know the ordinances of Heaven, and consequently does not stand in awe of them." + $CRLF + _ " He is disrespectful to great men. He makes sport of the words of sages" CreateTip hDlg, %IDC_LISTBOX1, "LB" CreateTip hDlg, %IDC_SYSLISTVIEW32_1, "LV" CreateTip hDlg, %IDC_BUTTON1, "BUTTON" END SUB 'SetToolTips '------------------------------------ CALLBACK FUNCTION ShowDIALOG1Proc() LOCAL i AS LONG SELECT CASE AS LONG CBMSG CASE %WM_INITDIALOG FOR i = 1 TO 10: LISTBOX ADD CBHNDL, %IDC_LISTBOX1, USING$("My Item #", i):NEXT settooltips(CBHNDL) END SELECT END FUNCTION FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG LOCAL lRslt AS LONG LOCAL hDlg AS DWORD DIALOG NEW hParent, "Tooltip Tooltips - DDT & multiline", 151, 118, 201, 133, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR _ %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT _ OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "TextBox1", 10, 5, 55, 30 CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX2, "TextBox2", 10, 45, 55, 30 CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "Label1", 95, 5, 65, 30, _ %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR %SS_LEFT OR %SS_NOTIFY, _ %WS_EX_LEFT OR %WS_EX_LTRREADING CONTROL ADD LISTBOX, hDlg, %IDC_LISTBOX1, , 95, 45, 65, 40 CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, "Button1", 125, 95, 60, 25 DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt FUNCTION = lRslt END FUNCTION '================================================================================ FUNCTION PBMAIN() InitCommonControls ShowDIALOG1 %HWND_DESKTOP END FUNCTION
Comment