qwert Posted January 25, 2015 Share Posted January 25, 2015 (edited) In order to place colored squares on a GUI, I selected GUICtrlCreateGraphic as a logical choice and then used the background color to give the effect. Then I found that, apparently, a graphic can't have a tooltip. Is that true? Or have I omitted something? As a workaround, I've changed some of them to labels and, of course, tooltips work. But that doesn't help me for elements that will eventually contain an actual graphic. This script demonstrates the problem: ; ; Tooltip Test ; GUICreate("Tooltip Text", 400, 300) GUICtrlCreateLabel("", 40, 40, 60, 60) GUICtrlSetBkColor(-1, 0x00AABB) GUICtrlSetTip(-1, "First color block") GUICtrlCreateGraphic(140, 40, 60, 60) GUICtrlSetBkColor(-1, 0xAABBCC) GUICtrlSetTip(-1, "Second color block") GUISetState() Do Until GUIGetMsg() = -3 ' As a related question: can the GUI, itself, have a default tooltip? ... one that will display whenever there's no other control under the cursor? My searches didn't turn up any ideas. I've found GUIToolTip.au3, so this one is answered. Thanks in advance for any help. Edited January 25, 2015 by qwert Link to comment Share on other sites More sharing options...
BrewManNH Posted January 26, 2015 Share Posted January 26, 2015 Here's one way around that limitation. ; ; Tooltip Test ; #include <GUIToolTip.au3> GUICreate("Tooltip Text", 400, 300) GUICtrlCreateLabel("", 40, 40, 60, 60) GUICtrlSetBkColor(-1, 0x00AABB) GUICtrlSetTip(-1, "First color block") $hGraphic = GUICtrlGetHandle(GUICtrlCreateGraphic(140, 40, 60, 60)) GUICtrlSetBkColor(-1, 0xAABBCC) Local $hToolTip = _GUIToolTip_Create(0) ; add a tool to the tooltip control _GUIToolTip_AddTool($hToolTip, 0, "Second color block", $hGraphic) GUISetState() Do Until GUIGetMsg() = -3 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
qwert Posted January 26, 2015 Author Share Posted January 26, 2015 Indeed, that works ... and it produces the same style tooltip as the standard function. Thank you. Your solution led me to explore some of the formatting capabilities of GUIToolTip.au3, which I haven't used before. I ran the help file example with success, and figured out the components/steps involved (which aren't very clear from the help description, particularly the $iID parameter): • Use Create to define each different appearance you want. These are Tooltip Controls. • Using the Control ID, get the handle for each control that you want to add a custom tooltip • Use AddTool to define tooltips for individual controls by providing the appropriate text for each, along with the control's handle. • Upon exit, delete the defined ToolTip Controls. My only remaining question for anyone who's certain: is GUITooltip_Destroy truly necessary upon the script's exit (like shutting down GDI+), or is it a formality, like GUIDelete? Link to comment Share on other sites More sharing options...
BrewManNH Posted January 26, 2015 Share Posted January 26, 2015 It's a formality, it's not necessary to delete them, it's just a good practice to get into. As to the help file, I rewrote 70% of the GUIToolTip UDF and help file, there weren't any examples previously and no one ever used them because they were so maddeningly complex the way they were before. I made the UDF much easier to work with, and the examples are a good starting point to learn how to use the UDF. Another example you might want to look at is the 2nd example of _GUIToolTip_AddTool. This demonstrates how to assign a tooltip to an area of the GUI and not to a specific control. It would be useful if you're using a single graphic with multiple areas on it that you'd want to have different tooltips for. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
qwert Posted January 26, 2015 Author Share Posted January 26, 2015 Interesting points. I'm seeing lots of potential for things to do with custom tooltips. Now, if there was only a setting for font size! Oh, well. Thanks for your help. Link to comment Share on other sites More sharing options...
BrewManNH Posted January 26, 2015 Share Posted January 26, 2015 (edited) There is a way to change the font of the tooltip, size/weight/font etc. I found a function that was written back in 2007 that will work. Here's a demonstration of how to do it, using the example script from the help file, modified with the additional function. expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIToolTip.au3> #include <WinAPI.au3> #include <FontConstants.au3> #include <WindowsConstants.au3> Example() Func Example() Local $hGUI = GUICreate(StringTrimRight(@ScriptName, 4), 350, 200) Local $iAdd = GUICtrlCreateButton("Button ToolTip", 30, 32, 130, 28) Local $hAdd = GUICtrlGetHandle($iAdd) ; Create a tooltip control Local $hToolTip = _GUIToolTip_Create($hGUI, $TTS_BALLOON) ; If using a Windows theme setting, this will disable that for the tooltip displayed, so you can color it ; it has to be placed before you try to actually set the colors, doing it after will reset the colors. DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hToolTip, "wstr", 0, "wstr", 0) ; The color value used in the _GUIToolTip_SetTipBkColor function is an RGB value _GUIToolTip_SetTipBkColor($hToolTip, 0x395A00) ; The color value used in the _GUIToolTip_SetTipTextColor function is an BGR value _GUIToolTip_SetTipTextColor($hToolTip, 0x1EBFFF) ; add a tool to the tooltip control _GUIToolTip_AddTool($hToolTip, 0, "This is the ToolTip text", $hAdd) _SetFont_hWnd($hToolTip, 20) GUISetState() While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop WEnd ; Destroy the tooltip control _GUIToolTip_Destroy($hToolTip) GUIDelete($hGUI) EndFunc ;==>Example ;~ http://www.autoitscript.com/forum/topic/57419-deleting-listviewitem-leaves-a-black-space/?p=441871 Func _SetFont_hWnd($hwnd, $size = 8.5, $weight = 400, $attr = 0, $fontname = "") Local $_tagfont = DllStructCreate($tagLOGFONT) Local $hDC = _WinAPI_GetDC($hwnd) ; lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72) Local $lf_height = -($size * _WinAPI_GetDeviceCaps($hDC, $LOGPIXELSY)) / 72 _WinAPI_ReleaseDC($hwnd, $hDC) DllStructSetData($_tagfont, 'Height', $lf_height); DllStructSetData($_tagfont, 'Width', 0); DllStructSetData($_tagfont, 'Escapement', 0); DllStructSetData($_tagfont, 'Orientation', 0); DllStructSetData($_tagfont, 'Weight', $weight); DllStructSetData($_tagfont, 'Italic', BitAND($attr, 0x2)) DllStructSetData($_tagfont, 'Underline', BitAND($attr, 0x4)) DllStructSetData($_tagfont, 'StrikeOut', BitAND($attr, 0x8)) DllStructSetData($_tagfont, 'CharSet', 0); 0 = ANSI_CHARSET DllStructSetData($_tagfont, 'OutPrecision', 0); 0 = OUT_DEFAULT_PRECIS DllStructSetData($_tagfont, 'ClipPrecision', 0); 0 = CLIP_DEFAULT_PRECIS DllStructSetData($_tagfont, 'Quality', 0); 0 = DEFAULT_QUALITY ; 0 = DEFAULT_PITCH, 1 = FIXED_PITCH, 2 = VARIABLE_PITCH ; $FF_DONTCARE = 0 (FF_ROMAN = 16, FF_SWISS = 32, FF_MODERN = 48, FF_SCRIPT = 64, FF_DECORATIVE = 80) DllStructSetData($_tagfont, 'PitchAndFamily', BitOR(0, $FF_DONTCARE)) DllStructSetData($_tagfont, 'FaceName', $fontname); Local $h_font = _WinAPI_CreateFontIndirect($_tagfont) _SendMessage($hwnd, $WM_SETFONT, $h_font, True) EndFunc ;==>_SetFont_hWnd Not 100% sure what it's all doing, but it does work. Edited January 26, 2015 by BrewManNH ioa747 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
qwert Posted January 26, 2015 Author Share Posted January 26, 2015 Excellent find! Now I have even more ideas for use. I'm a little surprised this hasn't become widely known, considering how tiny tooltips have become on large monitors. (BTW, #include <GUIToolTip2.au3> needed to be: #include <GUIToolTip.au3> on my installation.) Many thanks! Link to comment Share on other sites More sharing options...
BrewManNH Posted January 26, 2015 Share Posted January 26, 2015 No, sorry, just change that to GUIToolTip.au3 without the 2. That was something I was testing and didn't change it before posting. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
qwert Posted January 27, 2015 Author Share Posted January 27, 2015 Having worked with this for a few hours, I'd like to share some things I’ve learned: Created/Added Tooltips are active only when the GUI is active (by default). Standard tooltips are active all the time (by default). You can have both types active for a control and both will display. It’s an interesting effect to have a balloon tip above and a normal tip below. Standard tooltips are usually font size 8.5. A fairly large font for a custom tooltip is 12. The handle order is shown as swapped in the UpdateTipText help page. It’s actually the same as for AddTool. For large text blocks, there is a slight bug in the UDF’s display logic where—if there isn’t sufficient room between the hover point and the edge of the screen (top or bottom)—the entire tooltip block flashes on and off at 1-second intervals. GUIToolTip_Deactivate is a powerful feature for deactivating entire groups of tooltips, without having to change the text in individual tips to blanks. My one complaint about the current UDF is that the tooltips can be “flitty” ... they can flash on/off two or three times while the cursor is settling into a control. The solution would be to implement dampening logic by having the tooltip display for a minimum time (say, 700 milliseconds) whenever it's triggered by a cursor move into a control. I don’t think it needs to be a parameter, but the current 10ms or 20ms is too short. In the mean time, I’ve set these two parameters, which seem to help: $TTDT_INITIAL = 600 $TTDT_RESHOW = 400 Thanks, again, BrewManNH for bringing these features to light. Controlling tooltips at this level is very cool! Link to comment Share on other sites More sharing options...
BrewManNH Posted January 27, 2015 Share Posted January 27, 2015 By default, the tooltips should show whenever you're over the control that the tip is assigned to, regardless of whether the GUI is active or not "Default: $_TT_ghTTDefaultStyle = BitOr($TTS_ALWAYSTIP, $TTS_NOPREFIX)". As to the flashing if too near the edge of the screen, I think that's a Windows thing not a UDF bug. The initial display time ($TTDT_INITIAL) is determined by whatever your double click delay is set to. This is a Windows setting that can be changed by _GUIToolTip_SetDelayTime. The default delay times are based on the double-click time. The autopop time will be ten times the initial time and the reshow time will be one fifth the initial time. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now