Jump to content

Recommended Posts

Hello, First off, I want to say that I very much appreciate the hard work that people put in to replying on these forums and helping newbs. I've gotten 99% of my answers through google, forum searches, and documentation.

Okay, so. I'm actually sure this has been asked before, but I wasn't able to find anything and I'm having some difficulty.
I want to delete tabs in a control with a middle click (or specifically, detect when a tab has been middle-clicked).

Initially I was going to try to use GUIGetCursorInfo along with checking for a middle-click, the problem is, when the cursor is over a tab, it simply returns the ID of the whole control (I'm using the native tab functionality).

If I can avoid it, I REALLY don't want to manually check coordinates of tabs when the middle mouse is clicked, as tabs are going to be generated dynamically (anywhere from one to infinity tabs if the user lets things get out of hand), and the window I'm using will be resizable (thus having to run checks if a tab is out of view, etc), but I can if I have no other choice.


So basically, Is there either 1: a simple native/UDF way to detect middle-click on tabs, 2: a way to get GUIGetCursorInfo give the control ID of the tab itself instead of the control, or 3: something I haven't thought of all together?

Thanks in advance!

Link to post
Share on other sites

I'm looking at find the tab ID of an AutoIt GUI.

Here is some code I threw together from other examples to show what I'm trying to do. (It crashes if you middle-click outside of the GUI window. I didn't want to spend anymore time on it).

#include <GUIConstantsEx.au3>
#include <Misc.au3>

$hGUI = GUICreate("Window with Tabs", 500, 500)
Global $controlID = 0
GUICtrlCreateLabel("ID of clicked control:", 200, 1)
$controlID = GUICtrlCreateLabel("0", 300, 1, 50)
$dll = DllOpen("user32.dll")
HotKeySet("{ESC}", "GetPos")

$hTab = GUICtrlCreateTab(10, 10, 480, 480)

For $i = 0 To 2
    GUICtrlCreateTabItem("Tab " & $i)
    GUICtrlCreateButton("Button " & $i, 20 + ($i * 100), 40 + ($i * 50), 80, 30)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
    If _IsPressed("04", $dll) Then GetPos()


Func GetPos()
    Local $a = GUIGetCursorInfo()
    GUICtrlSetData($controlID, $a[4])

You will see that when you middle-click anywhere inside the GUI tab control, it gives you the ID of the entire control. I need to make it so if you click on the individual tabs at the top, it will display the ID of only that tab.

Link to post
Share on other sites

Perfect! Posting code takes away a lot of the guessing game and I don't have to spend the time putting together the GUI myself o:)

Here's a way to use WM_NOTIFY to get the index of the tab. It appears that WM_MBUTTONDOWN (and UP) are not being received when on a tab so I used the _IsPressed.

#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>
#include <GUITab.au3>

Global $iTabIndex = -1
Global $hGUI = GUICreate("Window with Tabs", 500, 500)
Global $lblId = GUICtrlCreateLabel("ID of clicked control:", 200, 1)
Global $hTab = GUICtrlCreateTab(10, 10, 480, 480)

For $i = 0 To 2
    GUICtrlCreateTabItem("Tab " & $i)
    GUICtrlCreateButton("Button " & $i, 20 + ($i * 100), 40 + ($i * 50), 80, 30)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
    If (_IsPressed(4)) Then DeleteTabItem()

Func DeleteTabItem()
    If ($iTabIndex > -1) Then
        _GUICtrlTab_DeleteItem(GUICtrlGetHandle($hTab), $iTabIndex)
        $iTabIndex = -1
EndFunc   ;==>DeleteTabItem

Func WM_NOTIFY($hWndFrom, $iMsg, $wParam, $lParam)
    #forceref $hWndFrom, $iMsg, $wParam, $lParam
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Local $iIdFrom = DllStructGetData($tNMHDR, "IDFrom")

    Switch ($hWndFrom)
        Case $hGUI
            Switch ($iCode)
                Case -530
                    $iTabIndex = $iIdFrom

EndFunc   ;==>WM_NOTIFY

I'll test a WNDPROC tomorrow, see if it captures the middle mouse click

Also, the -530 is used to parse the application for the tooltip text to display. It's in the ToolTipConstants.au3

Global Const $TTN_GETDISPINFOW = $TTN_FIRST - 10 ; [Unicode] Sent to retrieve information needed to display a ToolTip

We're not displaying a tooltip but it's a good enough value to use to determine that the tab is being highlighted.

Link to post
Share on other sites

That works pretty well, actually. The only problem is there is a delay in trying to use the tooltip display number to determine the tab that is highlighted. It also "keeps" that tab ID if you move outside of the GUI without hovering over another control, and if you middle-cick, it deletes that tab. same goes for if you hover over one tab long enough, and don't sit over another tab long enough for the tooltip ID to display.

Do you think there is any other way we can identify what tab is selected? I even tried playing with the example for "_GUICtrlTab_Create" to see if I could identify what tab is pressed, but that doesn't do it either. It still displays the same ID regardless of different tabs.

At this rate, I'm almost curious if I could just create my own tab system using labels as buttons.


Link to post
Share on other sites

Idk, I feel like you're making it harder than it needs to be. There's nothing wrong with checking mouse coords for something if it works!

I was at work all day and came home to see a question that looked enticing I got carried away. Here's the solution to your dilemma. I even included all of the possible windows messages you can get from the Window procedure for our tab control ;) (There are like 3 values that I got that I could not find in the WindowsConstants.au3 file, even did a global search in the #include folder and didn't find it)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUITab.au3>
#include <WinApi.au3>
#include <WinAPIGdi.au3>

Global $hGUI = GUICreate("Window with Tabs", 500, 500)
Global $lblId = GUICtrlCreateLabel("Hovering over tab index: N/A | N/A", 190, 4, 200, 20)
GUICtrlSetFont(-1, 8, 400, "", "Segoe UI")
Global $tabMainTab = GUICtrlCreateTab(10, 30, 480, 480)
Global $hWndTab = GUICtrlGetHandle($tabMainTab)
Global $hWndProc = DllCallbackRegister("NewWndProc", "ptr", "hwnd;uint;wparam;lparam")
Global $pOldWndProc = _WinAPI_SetWindowLong($hWndTab, $GWL_WNDPROC, DllCallbackGetPtr($hWndProc))
Global $iTabItems = 13

For $i = 0 To $iTabItems
    GUICtrlCreateTabItem("Tab " & $i)
    GUICtrlCreateButton("Button " & $i, 20, 100, 80, 30)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE

Func NewWndProc($hWndFrom, $iMsg, $wParam, $lParam)
    #forceref $hWndFrom, $iMsg, $wParam, $lParam
    ; Struct that can be used to get information for SOME of the Windows Messages below
    ; Use caution, using the $iCode or $iIdFrom on the wrong windows message will break your code.
    ; It's best to initialize them INSIDE the Switch ($iMsg) below.
    ; Check the URL to see what values you can get from the $lParam and $wParam
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    ;Local $iCode = DLLStructGetData($tNMHDR, "Code")
    ;Local $iIdFrom = DLLStructGetData($tNMHDR, "IDFrom")
    ; Only valid on mouse functions
    Local $iMouseX = _WinAPI_LoWord($lParam)
    Local $iMouseY = _WinAPI_HiWord($lParam)

    Switch ($hWndFrom)
        Case $hWndTab
            Switch ($iMsg)
                Case $WM_LBUTTONDOWN
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms645607(v=vs.85).aspx
                Case $WM_LBUTTONUP
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms645608%28v=vs.85%29.aspx
                Case $WM_RBUTTONDOWN
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms646242(v=vs.85).aspx
                Case $WM_RBUTTONUP
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms646243%28v=vs.85%29.aspx
                Case $WM_MBUTTONDOWN
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms645610(v=vs.85).aspx
                Case $WM_MBUTTONUP
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms645611%28v=vs.85%29.aspx
                    For $i = 0 To $iTabItems
                        Local $aTabRect = _GUICtrlTab_GetItemRect($hWndTab, $i)
                        If (Not @error) Then
                            If (_WinAPI_PtInRectEx($iMouseX, $iMouseY, $aTabRect[0], $aTabRect[1], $aTabRect[2], $aTabRect[3])) Then
                                ConsoleWrite("Deleting tab index: " & $i & " | Tab text: " & _GUICtrlTab_GetItemText($hWndTab, $i))
                                _GUICtrlTab_DeleteItem($hWndTab, $i)
                                $iTabItems -= 1
                Case $WM_MOUSEMOVE
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms645616%28v=vs.85%29.aspx
                    For $i = 0 To $iTabItems
                        Local $aTabRect = _GUICtrlTab_GetItemRect($hWndTab, $i)
                        If (Not @error) Then
                            If (_WinAPI_PtInRectEx($iMouseX, $iMouseY, $aTabRect[0], $aTabRect[1], $aTabRect[2], $aTabRect[3])) Then ExitLoop
                    GUICtrlSetData($lblId, "Hovering over tab index: " & $i & " | " & _GUICtrlTab_GetItemText($hWndTab, $i))
                Case $WM_NCHITTEST
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms645618%28v=vs.85%29.aspx
                Case $WM_SETCURSOR
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms648382%28v=vs.85%29.aspx
                Case $WM_PAINT
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/dd145213(v=vs.85).aspx
                Case $WM_MOUSELEAVE
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms645615%28v=vs.85%29.aspx
                    GUICtrlSetData($lblId, "Hovering over tab index: N/A | N/A")
                Case $WM_MOUSEACTIVATE
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms645612%28v=vs.85%29.aspx
                Case $WM_NOTIFY
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775583%28v=vs.85%29.aspx
                Case $WM_NOTIFYFORMAT
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb775584(v=vs.85).aspx
                Case $WM_UPDATEUISTATE
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms646361%28v=vs.85%29.aspx
                Case $WM_GETDLGCODE
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms645425%28v=vs.85%29.aspx
                Case $WM_IME_SETCONTEXT
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/dd374142(v=vs.85).aspx
                Case $WM_SETFOCUS
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms646283(v=vs.85).aspx
                Case $WM_ERASEBKGND
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms648055%28v=vs.85%29.aspx
                Case $WM_NCPAINT
                    ; https://msdn.microsoft.com/en-us/library/windows/desktop/dd145212%28v=vs.85%29.aspx
                Case 0x001308, 0x00130A, 0x002006, 0x00133E, 0x00130C, 0x000129, 0x000210
                    ; Unknown messages that are constantly sent to the tab control but could not identify in WindowsConstants.au3
                Case 0x00133C
                    ; Unknown message sent to the tab control when highlighting an item
                Case Else
                    ConsoleWrite('[' & @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & "] Unknown Message: 0x" & Hex($iMsg, 6) & @LF & "############################################" & @LF)

    Return _WinAPI_CallWindowProc($pOldWndProc, $hWndFrom, $iMsg, $wParam, $lParam)
EndFunc   ;==>NewWndProc

Also, I didn't actually test it but I'm guessing _GUICtrlTab_GetItemRect is just the same as _WinApi_GetRect which will get the rect of a given handle. Can be used on buttons, edits, etc. And since tab items are really just buttons

Edited by InunoTaishou
Added more messages to switch
Link to post
Share on other sites

Wow. That is incredibly helpful! A great reference too, I like it! I was actually working on a script that when the middle mouse button is pressed, it changes a variable and emulate a L-mouse click if its inside the window. Whenever a tab switched, and if that earlier var was changed to true, it would delete the tab and revert back to the previous tab. A bit hacky, but it probably would have worked. However, this is much better.

Thanks a ton!

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Cengokill
      Hi everyone,
      I have created a ListView that is in a tab, and I want to display an image in that tab, with the ListView on top.
      However, the image still appears on top of my ListView.
      If I remove the tabs everything works. 
      I looked at the autoit documentation and the <GuiListView.au3> documentation , I can't figure out how to display a background image, and put on top a ListView, inside a tab. 😥
      Here is the code:
      Opt("GUIOnEventMode", 1) $Form1 = GUICreate($Titre, 700, 627, $Form1Width, $Form1Height); main window $tabulation = GUICtrlCreateTab(148,0,700,580); creating tabs $tab1=GUICtrlCreateTabItem("Tab 1"); first tab GUICtrlSetState(-1, $GUI_SHOW); this tab is selected by default $Pic1 = GUICtrlCreatePic("image.jpg", 0, 30, 700, 627) GUICtrlSetState(-1, $GUI_DISABLE). $idListview = GUICtrlCreateListView("list 1|list 2|list 3", 200, 50, 390, 200) GUISetState(@SW_SHOW) While 1     Sleep(100) WEnd Thank you in advance.

    • By Jamestay97
      Hello! Thanks you for looking at my post
      **No source code I'm sorry work related can't copy information**
      I've been using autoit for about 1 year. 
      I'm having trouble automating a click on an internet explorer web page and I've tried a lot of examples from help pages and forums already. The object I'm trying to click on isnt always in the same spot so I can't use mouse click or control click, I have tried to use the different get collection options and clickbyname, or index or get object. I'm just struggling. 
      Description of object I'm trying to click -- 
      HTML Code looks like <a ng-click.. "Click Here" it appears it's just a click able object named "click here" that opens a hidden window by running a script inside the web page. I'm not able to grab the information from the window unless it's open so I have to automate this click somehow. 
      I understand it's difficult to assist without having something to look at, I apologize for that sincerely and appreciate and assistance and suggestions. 
    • By nacerbaaziz
      good morning all.
      first lit me give you all a thinks to your help
      you're help me allot thank you all.
      sirs today i've a new problem
      it's not a problem but thing i want to add it to blind accessability.
      the ListBox can send a notification when the user send a double click on it items
      but as we know that the blind users can't use the mouse for that they use the keybord to navigate.
      as we know that the enter replace the double click on the keybord
      for that i need when the user send a inter above any listBox item the list send a double click notification.
      i know some of you tell me that i can use the  GUISetAccelerators function
      but the enter has a other tasks such as leav a blanc line on edits and activate the defaultButton and other tasks.
      that what i need and i hope that you can help me
      this is a simple example.
      #include <GUIConstantsEx.au3> #include <StructureConstants.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <ListBoxConstants.au3> Example() Func Example() Local $sMESSAGE = "The following buttons have been clicked" GUICreate("My GUI list") ; will create a dialog box that when displayed is centered Local $idButton_Add = GUICtrlCreateButton("Add", 64, 32, 75, 25) Local $idButton_Clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25) global $idMylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 121, 97) GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling GUICtrlSetData(-1, $sMESSAGE) global $DummyList = GUICtrlCreateDummy() GUICtrlSendToDummy($DummyList, 1) Local $idButton_Close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25) GUIRegisterMsg($WM_command, "WM_command") GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton_Add GUICtrlSetData($idMylist, "You clicked button No1|") Case $idButton_Clear GUICtrlSetData($idMylist, "") Case $idButton_Close MsgBox($MB_SYSTEMMODAL, "", "the closing button has been clicked", 2) Exit case $DummyList $g_iTemp = GUICtrlRead($DummyList) if $g_iTemp = $LBN_DBLCLK then ;$LBN_DBLCLK then msgBox(64, "", "") endIf GUICtrlSendToDummy($DummyList, 0) EndSwitch WEnd EndFunc ;==>Example Func WM_command($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = $lParam $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case GUICtrlGetHandle($idMylist) Switch $iCode Case $LBN_SELCHANGE, $LBN_DBLCLK, $LBN_SELCANCEL, $LBN_SETFOCUS GUICtrlSendToDummy($DummyList, $iCode) case else ;GUICtrlSendToDummy($DummyTreeview, 1) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc  
    • By _leo_
      Hey there!
      I am having a problem with clicking a button in IE. As you can see in the code, there would be a class name to click it, but since this button exists several times with exactly the same code, I can only use the "Noch nicht veröffentlicht" to separate it from the others. But this part is just pure text without any classification. 
      "<div class="checkmark" data-v-1e5b1f70=""><svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 16 16" data-v-1e5b1f70=""><circle cx="8" cy="8" r="8" data-v-1e5b1f70="" /></svg></div>Noch nicht veröffentlicht"
      I was trying to click it with:
      #include <IE.au3> local $oNNVs = _IEFormGetCollection($oIE2) For $oNNV in $oNNVs If String($oNNV.innertext) = "Noch nicht veröffentlicht" Then _IEAction($oNNV, "click") EndIf Next and:
      $inputs = $oIE2.document.getElementsByTagName("div") For $input In $inputs If $input.innertext == "Noch nicht veröffentlicht" then $input.click() EndIf Next But nothing seems to work. Thanks for the help!
    • By ThePoro
      Hi everyone.
      I want to ask about this : 
      I want it runs from 1 to 100 and It opens 10 firefox profiles then access youtube. After I close a firefox window, the loop runs and wait for another window close until loop ends
      I have a loop like this.
      Func launch() Local $from = Int(GUICtrlRead($input1)) Local $to = Int(GUICtrlRead($input2)) If $to <> "" Then While $from <= $to Local $profile = $to _RunDos("start firefox.exe -p " & $profile & " -no-remote youtube.com") $to=$to+1 WEnd Else Local $profile = $to _RunDos("start firefox.exe -p " & $profile & " -no-remote youtube.com") EndIf EndFunc Is there any solution?
      Thank you!
  • Create New...