LividCode Posted August 18, 2020 Share Posted August 18, 2020 I'm trying to get tooltips to show for the toolbar buttons and I just can't seem to get them to work along with the other code. What am I doing wrong here? expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <GuiImageList.au3> ;#include <ImageListConstants.au3> #include <GuiToolbar.au3> ;#include <GuiReBar.au3> #include <ListViewConstants.au3> #include <ToolbarConstants.au3> #include <WindowsConstants.au3> #include <WinAPIConstants.au3> #include <GuiMenu.au3> #include <GuiListView.au3> #include <GuiToolTip.au3> Global Enum $savebtn = 3000, $newbtn $frmMain = GUICreate("frmMain", 839, 508, 192, 124, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_TABSTOP)) $menu_File = GUICtrlCreateMenu("&File") $menu_Exit = GUICtrlCreateMenuItem("E&xit", $menu_File) $ImageList1 = _GUIImageList_Create(32, 32, 5) _GUIImageList_AddIcon($ImageList1, "C:\Windows\System32\shell32.dll", 258, True) _GUIImageList_AddIcon($ImageList1, "C:\Windows\System32\imageres.dll", 2, True) $tbMain = _GUICtrlToolbar_Create($frmMain) _GUICtrlToolbar_SetExtendedStyle($tbMain, $TBSTYLE_EX_DRAWDDARROWS) _GUICtrlToolbar_SetImageList($tbMain, $ImageList1) _GUICtrlToolbar_AddButton($tbMain, $savebtn, 0, 0) _GUICtrlToolbar_AddButton($tbMain, $newbtn, 1, 0, $BTNS_DROPDOWN) $sbMain = _GUICtrlStatusBar_Create($frmMain) Dim $sbMain_PartsWidth[5] = [125, 325, 525, 650, -1] $ListView1 = GUICtrlCreateListView("COL1|COL2|COL3|", 1, 46, 834, 414) GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM) GUICtrlCreateListViewItem("COL1ROW1|COL2ROW1|COL3ROW1", $ListView1) GUICtrlCreateListViewItem("COL1ROW2|COL2ROW2|COL3ROW2", $ListView1) GUICtrlCreateListViewItem("COL1ROW3|COL2ROW3|COL3ROW3", $ListView1) GUICtrlCreateListViewItem("COL1ROW4|COL2ROW4|COL3ROW4", $ListView1) ; Create ToolTip $hToolTip = _GUIToolTip_Create($tbMain) _GUICtrlToolbar_SetToolTips($tbMain, $hToolTip) Opt("GUIOnEventMode", 1) ;// Change to OnEvent mode Opt("GUICloseOnEsc", 0) ;//esc key does not close windows OnAutoItExitRegister("OnAutoItExit") ;//on autoit script exit, call this function GUISetOnEvent($GUI_EVENT_CLOSE, "Event_closeApplication",$frmMain) GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW, $frmMain) While 1 Sleep(10) ; Sleep to reduce CPU usage WEnd Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam) _GUICtrlStatusBar_Resize($sbMain) ;auto size statusbar _WinAPI_MoveWindow($tbMain, 0, 0 , 0, 0) ;auto size toolbar Return $GUI_RUNDEFMSG EndFunc ;==>MY_WM_SIZE Func Event_closeApplication() Switch @GUI_WinHandle Case $frmMain local $doclose = MsgBox(BitOR($MB_ICONWARNING,$MB_YESNO,$MB_TASKMODAL), "Close Application", "You are about to close this application! Are you sure you want to do this?") Switch $doclose case $IDYES ;clicked yes Exit case $IDNO ;clicked no ;do nothing, the application continues to run. EndSwitch ;Case $frmAsset ; GUISetState(@SW_HIDE,$frmAsset) ; GUISetState(@SW_ENABLE, $frmMain) ; WinActivate($frmMain) EndSwitch EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $ListView1 If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK ;ConsoleWrite("Left click") Case $NM_DBLCLK ConsoleWrite("Double left click" & _GUICtrlListView_GetItemText ( $hWndFrom, _GUICtrlListView_GetSelectedIndices($ListView1),0)) Case $NM_RDBLCLK ;ConsoleWrite("Double right click") Case $NM_RCLICK ConsoleWrite("right click") ;ListView_RClick() Return 0 Case $LVN_COLUMNCLICK ; A column was clicked Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) ConsoleWrite("Sort LV") EndSwitch Case $tbMain ;ConsoleWrite("FROM: " & $icode & @CRLF) Switch $iCode Case $TBN_DROPDOWN ConsoleWrite("button drop down") Case $TTN_GETDISPINFO $tInfo = DllStructCreate($tagNMTTDISPINFO, $ilParam) ConsoleWrite("Set Tooltips") $iID = DllStructGetData($tInfo, "IDFrom") Switch $iID Case $savebtn DllStructSetData($tInfo, "aText", "Save") Case $newbtn DllStructSetData($tInfo, "aText", "New") EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func OnAutoItExit() ;function runs when the application is closing. Event_closeApplication() runs first. ;do application cleanup EndFunc ;==>OnAutoItExit Link to comment Share on other sites More sharing options...
Zedna Posted August 19, 2020 Share Posted August 19, 2020 (edited) First BIG source of potential problems is that you mix Message and Event mode. Don't do this. EDIT: Here is basic functional example for tooltips & toolbar, try compare and eliminate method to make your code to work like this https://www.autoitscript.com/autoit3/docs/libfunctions/_GUICtrlToolbar_SetToolTips.htm Edited August 19, 2020 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted August 19, 2020 Share Posted August 19, 2020 Here is fixed/working code: see lines with this comments "(Zedna) ****************************************" expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <GuiImageList.au3> ;#include <ImageListConstants.au3> #include <GuiToolbar.au3> ;#include <GuiReBar.au3> #include <ListViewConstants.au3> #include <ToolbarConstants.au3> #include <WindowsConstants.au3> #include <WinAPIConstants.au3> #include <GuiMenu.au3> #include <GuiListView.au3> #include <GuiToolTip.au3> Global Enum $savebtn = 3000, $newbtn $frmMain = GUICreate("frmMain", 839, 508, 192, 124, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_TABSTOP)) $menu_File = GUICtrlCreateMenu("&File") $menu_Exit = GUICtrlCreateMenuItem("E&xit", $menu_File) $ImageList1 = _GUIImageList_Create(32, 32, 5) _GUIImageList_AddIcon($ImageList1, "C:\Windows\System32\shell32.dll", 258, True) _GUIImageList_AddIcon($ImageList1, "C:\Windows\System32\imageres.dll", 2, True) $tbMain = _GUICtrlToolbar_Create($frmMain) GUISetState(@SW_SHOW, $frmMain) ; --> moved here (Zedna) **************************************** $hToolTip = _GUIToolTip_Create($tbMain) ; --> moved here (Zedna) **************************************** _GUICtrlToolbar_SetToolTips($tbMain, $hToolTip) _GUICtrlToolbar_SetExtendedStyle($tbMain, $TBSTYLE_EX_DRAWDDARROWS) _GUICtrlToolbar_SetImageList($tbMain, $ImageList1) _GUICtrlToolbar_AddButton($tbMain, $savebtn, 0, 0) _GUICtrlToolbar_AddButton($tbMain, $newbtn, 1, 0, $BTNS_DROPDOWN) $sbMain = _GUICtrlStatusBar_Create($frmMain) Dim $sbMain_PartsWidth[5] = [125, 325, 525, 650, -1] $ListView1 = GUICtrlCreateListView("COL1|COL2|COL3|", 1, 46, 834, 414) GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM) GUICtrlCreateListViewItem("COL1ROW1|COL2ROW1|COL3ROW1", $ListView1) GUICtrlCreateListViewItem("COL1ROW2|COL2ROW2|COL3ROW2", $ListView1) GUICtrlCreateListViewItem("COL1ROW3|COL2ROW3|COL3ROW3", $ListView1) GUICtrlCreateListViewItem("COL1ROW4|COL2ROW4|COL3ROW4", $ListView1) ; Create ToolTip ;~ $hToolTip = _GUIToolTip_Create($tbMain) ; --> moved up from here (Zedna) **************************************** ;~ _GUICtrlToolbar_SetToolTips($tbMain, $hToolTip) Opt("GUIOnEventMode", 1) ;// Change to OnEvent mode Opt("GUICloseOnEsc", 0) ;//esc key does not close windows OnAutoItExitRegister("OnAutoItExit") ;//on autoit script exit, call this function GUISetOnEvent($GUI_EVENT_CLOSE, "Event_closeApplication",$frmMain) GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;~ GUISetState(@SW_SHOW, $frmMain) ; --> moved up from here (Zedna) **************************************** While 1 Sleep(10) ; Sleep to reduce CPU usage WEnd Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam) _GUICtrlStatusBar_Resize($sbMain) ;auto size statusbar _WinAPI_MoveWindow($tbMain, 0, 0 , 0, 0) ;auto size toolbar Return $GUI_RUNDEFMSG EndFunc ;==>MY_WM_SIZE Func Event_closeApplication() Switch @GUI_WinHandle Case $frmMain local $doclose = MsgBox(BitOR($MB_ICONWARNING,$MB_YESNO,$MB_TASKMODAL), "Close Application", "You are about to close this application! Are you sure you want to do this?") Switch $doclose case $IDYES ;clicked yes Exit case $IDNO ;clicked no ;do nothing, the application continues to run. EndSwitch ;Case $frmAsset ; GUISetState(@SW_HIDE,$frmAsset) ; GUISetState(@SW_ENABLE, $frmMain) ; WinActivate($frmMain) EndSwitch EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $ListView1 If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK ;ConsoleWrite("Left click") Case $NM_DBLCLK ConsoleWrite("Double left click" & _GUICtrlListView_GetItemText ( $hWndFrom, _GUICtrlListView_GetSelectedIndices($ListView1),0)) Case $NM_RDBLCLK ;ConsoleWrite("Double right click") Case $NM_RCLICK ConsoleWrite("right click") ;ListView_RClick() Return 0 Case $LVN_COLUMNCLICK ; A column was clicked Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) ConsoleWrite("Sort LV") EndSwitch ; --> changed/commented (Zedna) **************************************** ;~ Case $tbMain ;~ ;ConsoleWrite("FROM: " & $icode & @CRLF) ;~ Switch $iCode ;~ Case $TBN_DROPDOWN ;~ ConsoleWrite("button drop down") ;~ Case $TTN_GETDISPINFO ;~ $tInfo = DllStructCreate($tagNMTTDISPINFO, $ilParam) ;~ ConsoleWrite("Set Tooltips") ;~ $iID = DllStructGetData($tInfo, "IDFrom") ;~ Switch $iID ;~ Case $savebtn ;~ DllStructSetData($tInfo, "aText", "Save") ;~ Case $newbtn ;~ DllStructSetData($tInfo, "aText", "New") ;~ EndSwitch ;~ EndSwitch EndSwitch ; --> changed (Zedna) **************************************** $tInfo = DllStructCreate($tagNMTTDISPINFO, $ilParam) $iCode = DllStructGetData($tInfo, "Code") ;~ ConsoleWrite("WM_NOTIFY iCode: " & $icode & @CRLF) Switch $iCode Case $TBN_DROPDOWN ConsoleWrite("button drop down") ; Case $TBN_HOTITEMCHANGE ; ConsoleWrite("button TBN_HOTITEMCHANGE"&@CRLF) Case $TTN_GETDISPINFOW $tInfo = DllStructCreate($tagNMTTDISPINFO, $ilParam) ConsoleWrite("Set Tooltips") $iID = DllStructGetData($tInfo, "IDFrom") Switch $iID Case $savebtn DllStructSetData($tInfo, "aText", "Save") Case $newbtn DllStructSetData($tInfo, "aText", "New") EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func OnAutoItExit() ;function runs when the application is closing. Event_closeApplication() runs first. ;do application cleanup EndFunc ;==>OnAutoItExit LividCode 1 Resources UDF ResourcesEx UDF AutoIt Forum Search 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