Jump to content

Recommended Posts

Posted

Looking interesting (as always for all project from you).
I will analyze this later after my vacation.

Thanks.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

I was just reading your  Windows Message Monitor and then I check whats new on the forum, so I jump to this thread,  quick look, thinking, posting :)

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Added new treeview example. See first post.

Minor WMM updates. See WMM thread.

Updated zip-file in bottom of first post.

Posted

@LarsJ ,

I have been busy due to some job related reasons and hence, I didn’t do any programming for some time. Have seen your post in a this forum. Thank you for this UDF. I was using the SetWindowSubclass for such requirements, because the GUIRegMsg had some shortcomings which you mentioned in this post. I will sure leave a comment after testing your UDF.

  Reveal hidden contents

 

Posted

@LarsJ,

WinMsgMon is really Powerful. Thank you for this script. In fact I've had a need for such a script. I often use the program named Control Spy to find out which messages are coming to a control. Messages and notification codes of All common Windows controls, will be displayed in that program. But there is no number for that messages. Lot of messages appear in a list box within a second. We do not know which is the first one or the last one. But your WinMsgMon has filled that shortcoming. I like it. Thanks. :)

 

  Reveal hidden contents

 

Posted

@LarsJ ,

Checked GUIRegisterMsg20() just now. Fantastic !. With this function, AutoIt is now become somewhat like an event driven programming language. Really ! Please tell me what is the reason behind this name "GUIRegisterMsg20(). If i were you, then i will name it something like "RegisterMsgEx". :)

 

  Reveal hidden contents

 

Posted

The name should be interpreted as GUIRegisterMsg() version 2.0. The purpose of GUIRegisterMsg20() is the same as GUIRegisterMsg(). It's used for the same thing, it's used in the same way, and the message handler function is the same. The version 2.0 hint shows that the function can do a little bit more than the original function: It can subclass a control and not just a GUI window.

Posted

Cool stuff LarsJ.  

  On 8/16/2018 at 3:48 PM, LarsJ said:

The purpose of GUIRegisterMsg20() is the same as GUIRegisterMsg().

The version 2.0 hint shows that the function can do a little bit more than the original function...

Expand  

doesn't RegisterMsgEx() do this as well, as kcvinu suggested? 

Posted
Posted

Added new example that shows how to end up performing too much code.

"Message flow" section is updated.

New zip-file in bottom of first post.

  • 1 month later...
Posted

Hi,

I am trying to use this to subclass the SHBrowseForFolderW (add checkboxes, and other stuff).

 

#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPIDlg.au3>
#include <GUIRegisterMsg20.au3>

$sInitDir = @ProgramFilesDir
$sRoot = _WinAPI_PathStripToRoot($sInitDir)

Global $hTV

$hBrowseProc = DllCallbackRegister('_BrowseProc', 'int', 'hwnd;uint;lparam;ptr')
$pBrowseProc = DllCallbackGetPtr($hBrowseProc)

$pText = _WinAPI_CreateString($sInitDir)
$sPath = _WinAPI_BrowseForFolderDlg($sRoot, 'Select a folder from the list below.', BitOR($BIF_RETURNONLYFSDIRS, $BIF_BROWSEINCLUDEFILES, $BIF_VALIDATE, $BIF_USENEWUI), $pBrowseProc, $pText)
_WinAPI_FreeMemory($pText)

If $sPath Then
    ConsoleWrite('--------------------------------------------------' & @CRLF)
    ConsoleWrite($sPath & @CRLF)
EndIf

DllCallbackFree($hBrowseProc)

Func _BrowseProc($hWnd, $iMsg, $wParam, $lParam)
    Local $sPath
    
    Switch $iMsg
        Case $BFFM_INITIALIZED
            $hTV = ControlGetHandle($hWnd, '', 'SysTreeView321')
            
            _WinAPI_SetWindowLong($hTV, $GWL_STYLE, BitOR(_WinAPI_GetWindowLong($hTV, $GWL_STYLE), $TVS_CHECKBOXES))
            _WinAPI_SetWindowText($hWnd, 'MyTitle')
            _SendMessage($hWnd, $BFFM_SETSELECTIONW, 1, $lParam)
            
            ;GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
            GUIRegisterMsg20($hTV, $WM_NOTIFY, WM_NOTIFY)
        Case $BFFM_SELCHANGED
            $sPath = _WinAPI_ShellGetPathFromIDList($wParam)
            
            If Not @error Then
                ConsoleWrite($sPath & @CRLF)
            EndIf
    EndSwitch
    
    Return 0
EndFunc   ;==>_BrowseProc

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $lParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $hWndFrom
        Case $hTV
            Switch $iCode
                Case $NM_CLICK ; The user has clicked the left mouse button within the control
                    ConsoleWrite('Clicked' & @CRLF)
                    ; Return 1 ; nonzero to not allow the default processing
                    Return 0 ; zero to allow the default processing
                Case Else
                    ConsoleWrite(1 & @CRLF)
            EndSwitch
    EndSwitch
    
    Return 'GUI_RUNDEFMSG'
EndFunc

But no success, any ideas?

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted
Posted

Why? it's working fine on my Win10.

  On 4/15/2020 at 3:12 PM, LarsJ said:

you should use New style FileSelectFolder.

Expand  

It seems that it's much more complicated to do what i want with this method.

The question is why the subclassing does not work with BrowseForFolderDlg?

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

Because WM_NOTIFY messages are sent to the parent window. So use

GUIRegisterMsg20(_WinAPI_GetParent($hTV), $WM_NOTIFY, WM_NOTIFY)

 

Posted
  On 4/15/2020 at 4:46 PM, LarsJ said:

Because WM_NOTIFY messages are sent to the parent window. So use

Expand  

Thanks, now it works!

Strange, but i though that $hWnd passed to _BrowseProc it's the parent, apparently not.

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted (edited)

UI Automation code can reveal the structure of the controls in the window:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#AutoIt3Wrapper_UseX64=y

Opt( "MustDeclareVars", 1 )

#include "UIA_Constants.au3"

; Array index offset relative to UIA_ControlTypeIds = -50000
Global Const $aUIControls = [ _
  "Button",       "Calendar",     "CheckBox",     "ComboBox",     "Edit",         "Hyperlink",    "Image",        "ListItem",     "List", _
  "Menu",         "MenuBar",      "MenuItem",     "ProgressBar",  "RadioButton",  "ScrollBar",    "Slider",       "Spinner",      "StatusBar", _
  "Tab",          "TabItem",      "Text",         "ToolBar",      "ToolTip",      "Tree",         "TreeItem",     "Custom",       "Group", _
  "Thumb",        "DataGrid",     "DataItem",     "Document",     "SplitButton",  "Window",       "Pane",         "Header",       "HeaderItem", _
  "Table",        "TitleBar",     "Separator",    "SemanticZoom", "AppBar" ]

Global $oUIAutomation

Example()

Func Example()
  ; Create UI Automation object
  $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation )
  If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF )
  ConsoleWrite( "$oUIAutomation OK" & @CRLF )

  ; Get Desktop element
  Local $pDesktop, $oDesktop
  $oUIAutomation.GetRootElement( $pDesktop )
  $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement )
  If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF )
  ConsoleWrite( "$oDesktop OK" & @CRLF )

  Local $pCondition0, $pCondition1, $pAndCondition1
  $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "#32770", $pCondition0 )
  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "MyTitle", $pCondition1 )
  $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 )
  If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF )
  ConsoleWrite( "$pAndCondition1 OK" & @CRLF )

  Local $pWindow1, $oWindow1
  $oDesktop.FindFirst( $TreeScope_Children, $pAndCondition1, $pWindow1 )
  $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement )
  If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF )
  ConsoleWrite( "$oWindow1 OK" & @CRLF & @CRLF )

  ; List all automation elements of a window
  ; in a hierarchical structure like a treeview.
  Local $iControl, $sElement
  $oWindow1.GetCurrentPropertyValue( $UIA_ControlTypePropertyId, $iControl )
  $oWindow1.GetCurrentPropertyValue( $UIA_NamePropertyId, $sElement )
  ConsoleWrite( $aUIControls[$iControl-50000] & ( $sElement ? ": " & $sElement : "" ) & @CRLF )
  ListDescendants( $oWindow1 )
  ;ListDescendants( $oWindow1, 2 ) ; Only two levels
EndFunc

; List all child elements of parent
Func ListDescendants( $oParent, $iLevels = 0, $iLevel = 0 )
  If Not IsObj( $oParent ) Then Return
  If $iLevels And $iLevel = $iLevels Then Return

  ; Create RawViewWalker object
  Local $pRawViewWalker, $oRawViewWalker
  $oUIAutomation.RawViewWalker( $pRawViewWalker )
  $oRawViewWalker = ObjCreateInterface( $pRawViewWalker, $sIID_IUIAutomationTreeWalker, $dtag_IUIAutomationTreeWalker )
  If Not IsObj( $oRawViewWalker ) Then Return ConsoleWrite( "$oRawViewWalker ERR" & @CRLF )

  ; Get first child element
  Local $pUIElement, $oUIElement
  $oRawViewWalker.GetFirstChildElement( $oParent, $pUIElement )
  $oUIElement = ObjCreateInterface( $pUIElement, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement )

  Local $sIndent = ""
  For $i = 0 To $iLevel
    $sIndent &= "    "
  Next

  Local $iControl, $sElement
  While IsObj( $oUIElement )
    $oUIElement.GetCurrentPropertyValue( $UIA_ControlTypePropertyId, $iControl )
    $oUIElement.GetCurrentPropertyValue( $UIA_NamePropertyId, $sElement )
    ConsoleWrite( $sIndent & $aUIControls[$iControl-50000] & ( $sElement ? ": " & $sElement : "" ) & @CRLF )

    ListDescendants( $oUIElement, $iLevels, $iLevel + 1 )

    $oRawViewWalker.GetNextSiblingElement( $oUIElement, $pUIElement )
    $oUIElement = ObjCreateInterface( $pUIElement, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement )
  WEnd
EndFunc
$oUIAutomation OK
$oDesktop OK
$pAndCondition1 OK
$oWindow1 OK

Window: MyTitle
    Text: Select a folder from the list below.
    Pane: Select a folder from the list below.
        Tree: Select a folder from the list below.
            ScrollBar: Vertical
                Button: Line up
                Thumb: Position
                Button: Page down
                Button: Line down
            TreeItem: System (C:)
                TreeItem: $Recycle.Bin
                TreeItem: Documents and Settings
                TreeItem: Intel
                TreeItem: MSOCache
                TreeItem: PerfLogs
                TreeItem: Program Files
                TreeItem: Program Files (x86)
                TreeItem: ProgramData
                TreeItem: Recovery
                TreeItem: System
                TreeItem: System Volume Information
                TreeItem: Users
                TreeItem: Windows
                TreeItem: hiberfil.sys
                TreeItem: Install.log
                TreeItem: pagefile.sys
                TreeItem: SYSTAG.BIN
    Text: Folder:
    Edit: Folder:
    Button: Make New Folder
    Button: OK
    Button: Cancel
    Thumb
    TitleBar
        Button: Close

The control, which in UI Automation code is registered as a pane control, is the parent of the tree view.

The code is copied from this post but is slightly updated to show the top window as the first level.

UIA_Constants.au3 can be copied from UI Automation UDFs.

Edited by LarsJ
Posted

Couple Questions 

First

Why is it limited to windows messages 0- WM_USER (32767)

is that a design decision or a hard limit?

Second

have you done any performance testing to see how much extra overhead (if any) with filtering the message loop in AutoIt script versus versus the interpreter?

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.
×
×
  • Create New...