Leaderboard
Popular Content
Showing content with the highest reputation on 05/13/2023 in all areas
-
This is a replication of an old game called Bulldozer created by John 'FlyMan' Hattan (The Code Zone). There is another implementation in AutoHotkey made by Weston Campbell so I made one in AutoIt. In Weston's github repository you can check the game objective and all valid movements and objects. The controls are: UP - Move bulldozer up DOWN - Move bulldozer down RIGHT - Move bulldozer right LEFT - Move bulldozer left R - Restart current level U - Undo last move J - Jump to a specific level PAUSE - Pause the game Currently I added just first 30 40 60 levels but the original game have 180 levels (eventually I will add all of them). Since Weston's code is on github I suppose it's under some kind of creative license so I didn't bother to create other sprites but if someone have time and inspiration to create new sprites, I am open to add new sprites. To do: Maybe some music Hall of fame / Score table Add all original game levels Add more custom levels Provide access to settings (fonts, colors, sprites, hotkeys, etc) In the attachment is a compiled executable and also the source code. #NoTrayIcon #include-once #include <GDIPlus.au3> #include <WinAPI.au3> #include <SQLite.au3> If Not FileExists(@ScriptDir & '\Bulldozer.sqlite') Then MsgBox(0x10, 'Error', 'Database could not be located!', 10) Exit EndIf _SQLite_Startup(@ScriptDir & '\sqlite3.dll') Global $hDB = _SQLite_Open(@ScriptDir & '\Bulldozer.sqlite') Global Const $TileSize = Number(ReadProperty('TileSize', 32)) Global Const $XTiles = Number(ReadProperty('XTiles', 35)) Global Const $YTiles = Number(ReadProperty('YTiles', 25)) If @DesktopWidth < $XTiles * $TileSize Or @DesktopHeight < $YTiles * $TileSize Then MsgBox(0x30, 'Warning', 'For a better experience you need a display with a resolution ' & String($XTiles * $TileSize) & 'x' & String($YTiles * $TileSize) & '.', 10) EndIf Global $X, $Y, $Direction Global $mResources[] Global $mTiles[] Global $aTiles = GetTiles() If IsArray($aTiles) Then For $Index = 1 To UBound($aTiles) - 1 If $aTiles[$Index][1] Then $mTiles[$aTiles[$Index][0]] = $aTiles[$Index][1] Next Else _SQLite_Close() _SQLite_Shutdown() MsgBox(0x10, 'Error', 'Cannot retrieve game tiles from database!', 10) Exit EndIf Global $CurrentLevel = 1 Global $MaxLevel = Number(ReadProperty('MaxLevel', 1)) Global $AutoRestart = Number(ReadProperty('AutoRestart', 0)) Global $Font = ReadProperty('Font', 'Segoe UI') Global $FontSize = Number(ReadProperty('FontSize', 40)) Global $SecFontSize = Number(ReadProperty('SMFontSize', 20)) Global $MessageColor = ReadProperty('MessageColor', 0xFFFFFFFF) Global $SecMessageColor = ReadProperty('SMColor', 0xFF00A000) Global $Start, $PlayTime = 0, $Pause = False, $MsgShow = False Global $LastMove = Null, $PrevLevel = Null, $NumOfMoves = 0 Global $hMain, $aLevel[$YTiles][$XTiles] Global $ClearColor = ReadProperty('ClearColor', '0xFF000000') Global $KeyboardEnabled = False _GDIPlus_Startup() $mResources['Bitmap'] = _GDIPlus_BitmapCreateFromScan0($XTiles * $TileSize, $YTiles * $TileSize) $mResources['Graphics'] = _GDIPlus_ImageGetGraphicsContext($mResources['Bitmap']) _GDIPlus_GraphicsSetCompositingMode($mResources['Graphics'], 0) _GDIPlus_GraphicsSetCompositingQuality($mResources['Graphics'], 2) _GDIPlus_GraphicsSetInterpolationMode($mResources['Graphics'], 2) _GDIPlus_GraphicsSetSmoothingMode($mResources['Graphics'], 2) _GDIPlus_GraphicsSetTextRenderingHint($mResources['Graphics'], 3) For $Index = 1 To UBound($aTiles) - 1 If $aTiles[$Index][2] Then $mResources[$aTiles[$Index][0]] = _GDIPlus_BitmapCreateFromMemory(Unpack($aTiles[$Index][2])) Next $hMain = GUICreate('Bulldozer', $XTiles * $TileSize, $YTiles * $TileSize) $hPic = GUICtrlCreatePic('', 0, 0, $XTiles * $TileSize, $YTiles * $TileSize) GUISetState(@SW_SHOW, $hMain) LoadLevel() DrawLevel() DrawBulldozer($mResources['Bulldozer' & $Direction]) PushToScreen() While True If GUIGetMsg() = -3 Then Quit() If LevelDone() Then NextLevel() If WinActive($hMain) Then If $KeyboardEnabled = False Then KeyboardInput(True) Else If $KeyboardEnabled Then KeyboardInput(False) EndIf Sleep(10) WEnd Func Quit() Local $aKeys = MapKeys($mResources) For $Index = 0 To UBound($aKeys) - 1 $aKeys[$Index] = 'Graphics' ? _GDIPlus_GraphicsDispose($mResources[$aKeys[$Index]]) : _GDIPlus_BitmapDispose($mResources[$aKeys[$Index]]) Next _GDIPlus_Shutdown() _SQLite_Close() _SQLite_Shutdown() Exit EndFunc Func KeyboardInput($Set = True) Local $aKeys = GetKeyboard() If IsArray($aKeys) Then For $Index = 1 To UBound($aKeys) - 1 HotKeySet($aKeys[$Index][0], $Set ? $aKeys[$Index][1] : Null) Next EndIf $KeyboardEnabled = $Set EndFunc Func MoveRight() If $Pause Or $MsgShow Then Return $PrevLevel = $aLevel IsMovable($X + 1, $Y) If $X + 1 < $XTiles And IsMovable($X + 1, $Y) Then If IsRock($X + 1, $Y) And (IsEmpty($X + 2, $Y) Or IsEmptySocket($X + 2, $Y)) Then $aLevel[$Y][$X + 1] = IsSocket($X + 1, $Y) ? $mTiles['Socket'] : $mTiles['None'] $aLevel[$Y][$X + 2] = IsEmpty($X + 2, $Y) ? $mTiles['Rock'] : $mTiles['RockSocket'] $X += 1 ElseIf IsRock($X + 1, $Y) And (Not IsMovable($X + 2, $Y) Or IsRock($X + 2, $Y)) Then $X = $X Else $X += 1 EndIf $NumOfMoves += 1 EndIf $LastMove = 'R' DrawLevel() DrawBulldozer($mResources['BulldozerR']) PushToScreen() EndFunc Func MoveLeft() If $Pause Or $MsgShow Then Return $PrevLevel = $aLevel If $X - 1 > 0 And IsMovable($X - 1, $Y) Then If IsRock($X - 1, $Y) And (IsEmpty($X - 2, $Y) Or IsEmptySocket($X - 2, $Y)) Then $aLevel[$Y][$X - 1] = IsSocket($X - 1, $Y) ? $mTiles['Socket'] : $mTiles['None'] $aLevel[$Y][$X - 2] = IsEmpty($X - 2, $Y) ? $mTiles['Rock'] : $mTiles['RockSocket'] $X -= 1 ElseIf IsRock($X - 1, $Y) And (Not IsMovable($X - 2, $Y) Or IsRock($X - 2, $Y)) Then $X = $X Else $X -= 1 EndIf $NumOfMoves += 1 EndIf $LastMove = 'L' DrawLevel() DrawBulldozer($mResources['BulldozerL']) PushToScreen() EndFunc Func MoveUp() If $Pause Or $MsgShow Then Return $PrevLevel = $aLevel If $Y - 1 > 0 And IsMovable($X, $Y - 1) Then If IsRock($X, $Y - 1) And (IsEmpty($X, $Y - 2) Or IsEmptySocket($X, $Y - 2)) Then $aLevel[$Y - 1][$X] = IsSocket($X, $Y - 1) ? $mTiles['Socket'] : $mTiles['None'] $aLevel[$Y - 2][$X] = IsEmpty($X, $Y - 2) ? $mTiles['Rock'] : $mTiles['RockSocket'] $Y -= 1 ElseIf IsRock($X, $Y - 1) And (Not IsMovable($X, $Y - 2) Or IsRock($X, $Y - 2)) Then $Y = $Y Else $Y -= 1 EndIf $NumOfMoves += 1 EndIf $LastMove = 'U' DrawLevel() DrawBulldozer($mResources['BulldozerU']) PushToScreen() EndFunc Func MoveDown() If $Pause Or $MsgShow Then Return $PrevLevel = $aLevel If $Y + 1 < $YTiles And IsMovable($X, $Y + 1) Then If IsRock($X, $Y + 1) And (IsEmpty($X, $Y + 2) Or IsEmptySocket($X, $Y + 2)) Then $aLevel[$Y + 1][$X] = IsSocket($X, $Y + 1) ? $mTiles['Socket'] : $mTiles['None'] $aLevel[$Y + 2][$X] = IsEmpty($X, $Y + 2) ? $mTiles['Rock'] : $mTiles['RockSocket'] $Y += 1 ElseIf IsRock($X, $Y + 1) And (Not IsMovable($X, $Y + 2) Or IsRock($X, $Y + 2)) Then $Y = $Y Else $Y += 1 EndIf $NumOfMoves += 1 EndIf $LastMove = 'D' DrawLevel() DrawBulldozer($mResources['BulldozerD']) PushToScreen() EndFunc Func IsMovable($CX, $CY) If $CX < 0 Or $CX >= $XTiles Then Return False If $CY < 0 Or $CY >= $YTiles Then Return False Switch $aLevel[$CY][$CX] Case $mTiles['None'], $mTiles['Rock'], $mTiles['RockSocket'], $mTiles['Socket'] Return True Case Else Return False EndSwitch EndFunc Func IsRock($CX, $CY) If $CX < 0 Or $CX >= $XTiles Then Return False If $CY < 0 Or $CY >= $YTiles Then Return False Switch $aLevel[$CY][$CX] Case $mTiles['Rock'], $mTiles['RockSocket'] Return True Case Else Return False EndSwitch EndFunc Func IsEmpty($CX, $CY) If $CX < 0 Or $CX >= $XTiles Then Return False If $CY < 0 Or $CY >= $YTiles Then Return False Switch $aLevel[$CY][$CX] Case $mTiles['None'] Return True Case Else Return False EndSwitch EndFunc Func IsEmptySocket($CX, $CY) If $CX < 0 Or $CX >= $XTiles Then Return False If $CY < 0 Or $CY >= $YTiles Then Return False Switch $aLevel[$CY][$CX] Case $mTiles['Socket'] Return True Case Else Return False EndSwitch EndFunc Func IsSocket($CX, $CY) If $CX < 0 Or $CX >= $XTiles Then Return False If $CY < 0 Or $CY >= $YTiles Then Return False Switch $aLevel[$CY][$CX] Case $mTiles['RockSocket'], $mTiles['Socket'] Return True Case Else Return False EndSwitch EndFunc Func JumpToLevel() Local $iLevel = InputBox('Jump to level', 'Please type the level that you want to play') If $iLevel And Int($iLevel) > 0 And Int($iLevel) <= $MaxLevel Then $CurrentLevel = $iLevel LoadLevel() DrawLevel() DrawBulldozer($mResources['Bulldozer' & $Direction]) PushToScreen() EndIf EndFunc Func LevelDone() For $j = 0 To $YTiles - 1 For $i = 0 To $XTiles - 1 If $aLevel[$j][$i] = $mTiles['Socket'] Then Return False Next Next Return True EndFunc Func NextLevel() $PlayTime += Int(TimerDiff($Start) / 1000) ShowMessage('Level ' & $CurrentLevel & ' completed.' & @CRLF & ' ', 'Solved in ' & $NumOfMoves & ' moves.' & @CRLF & 'Time: ' & FormatTime($PlayTime), 4000) If $CurrentLevel + 1 > $MaxLevel Then GameEnd() Else $CurrentLevel += 1 LoadLevel() DrawLevel() DrawBulldozer($mResources['Bulldozer' & $Direction]) PushToScreen() EndIf EndFunc Func LoadLevel() Local $Data = SQLite_Query($hDB, 'SELECT Data FROM levels WHERE Level = ' & $CurrentLevel) If @extended Then $Data = BinaryToString(Unpack($Data[1][0])) $Data = StringSplit($Data, @CRLF, 1) For $Line = 1 To $YTiles Local $Row = StringSplit($Data[$Line], '') For $Index = 1 To $Row[0] $aLevel[$Line - 1][$Index - 1] = $Row[$Index] Next Next $X = $Data[26] $Y = $Data[27] $Direction = $Data[28] ShowMessage('Level ' & $CurrentLevel) $NumOfMoves = 0 $PlayTime = 0 $Start = TimerInit() EndIf EndFunc Func RestartLevel() If $Pause Then Return LoadLevel() DrawLevel() DrawBulldozer($mResources['Bulldozer' & $Direction]) PushToScreen() EndFunc Func GameEnd() ShowMessage('Congratulations!' & @CRLF & @CRLF & 'You have finished the game.', Null, 4000) If $AutoRestart Then $CurrentLevel = 1 RestartLevel() Else Quit() EndIf EndFunc Func FormatTime($Sec) If $Sec < 60 Then Return $Sec & ' seconds' Local $Min = Int($Sec / 60) $Sec -= $Min * 60 If $Min > 60 Then Local $Hours = Int($Sec / 60) $Min -= $Hours * 60 Return $Hours & ' hour' & ($Hours > 1 ? 's' : '') & ($Min <> 0 ? ', ' & $Min & ' minute' & ($Min > 1 ? 's' : '') : '') & ($Sec <> 0 ? ', ' & $Sec & ' second' & ($Sec > 1 ? 's' : '') : '') Else Return $Min & ' minute' & ($Min > 1 ? 's' : '') & ($Sec <> 0 ? ', ' & $Sec & ' second' & ($Sec > 1 ? 's' : '') : '') EndIf EndFunc Func ShowMessage($Message, $SecMessage = Null, $iDelay = 1500) $MsgShow = True Local $hFamily = _GDIPlus_FontFamilyCreate($Font) Local $hFont = _GDIPlus_FontCreate($hFamily, $FontSize, 1) Local $tLayout = _GDIPlus_RectFCreate(0, 0, $XTiles * $TileSize, ($SecMessage ? ($YTiles * $TileSize / 2) : ($YTiles * $TileSize))) Local $hBrush = _GDIPlus_BrushCreateSolid($MessageColor) Local $hFormat = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_StringFormatSetLineAlign($hFormat, ($SecMessage ? 2 : 1)) _GDIPlus_GraphicsClear($mResources['Graphics'], $ClearColor) _GDIPlus_GraphicsDrawStringEx($mResources['Graphics'], $Message, $hFont, $tLayout, $hFormat, $hBrush) If $SecMessage Then _GDIPlus_StringFormatSetLineAlign($hFormat, 0) Local $hSecFont = _GDIPlus_FontCreate($hFamily, $SecFontSize, 1) Local $tSecLayout = _GDIPlus_RectFCreate(0, ($YTiles * $TileSize / 2) , $XTiles * $TileSize, $YTiles * $TileSize / 2) Local $hSecBrush = _GDIPlus_BrushCreateSolid($SecMessageColor) _GDIPlus_GraphicsDrawStringEx($mResources['Graphics'], $SecMessage, $hSecFont, $tSecLayout, $hFormat, $hSecBrush) EndIf PushToScreen() _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_FontDispose($hFont) If $SecMessage Then _GDIPlus_BrushDispose($hSecBrush) _GDIPlus_FontDispose($hSecFont) EndIf _GDIPlus_FontFamilyDispose($hFamily) Local $DelayTimer = TimerInit() Do If GUIGetMsg() = -3 Then Quit() Sleep(10) Until TimerDiff($DelayTimer) >= $iDelay $MsgShow = False EndFunc Func UndoLastMove() If $PrevLevel = Null Then Return If $LastMove = Null Then Return If $Pause Then Return $aLevel = $PrevLevel DrawLevel() Switch $LastMove Case 'R' $X -= 1 DrawBulldozer($mResources['BulldozerR']) Case 'L' $X += 1 DrawBulldozer($mResources['BulldozerL']) Case 'U' $Y += 1 DrawBulldozer($mResources['BulldozerU']) Case 'D' $Y -= 1 DrawBulldozer($mResources['BulldozerD']) EndSwitch PushToScreen() $PrevLevel = Null $NumOfMoves -= 1 EndFunc Func Pause() $Pause = Not $Pause If $Pause Then $PlayTime += Int(TimerDiff($Start) / 1000) ShowMessage('Game is paused.', 'Press {Pause} button to resume your game.', 10) Else DrawLevel() DrawBulldozer($mResources['Bulldozer' & $Direction]) PushToScreen() $Start = TimerInit() EndIf Do Sleep(10) Until $Pause = False EndFunc Func DrawLevel() _GDIPlus_GraphicsClear($mResources['Graphics'], $ClearColor) For $j = 0 To $YTiles - 1 For $i = 0 To $XTiles - 1 Switch $aLevel[$j][$i] Case $mTiles['Wall1'] _GDIPlus_GraphicsDrawImageRect($mResources['Graphics'], $mResources['Wall1'], $i * $TileSize, $j * $TileSize, $TileSize, $TileSize) Case $mTiles['Wall2'] _GDIPlus_GraphicsDrawImageRect($mResources['Graphics'], $mResources['Wall2'], $i * $TileSize, $j * $TileSize, $TileSize, $TileSize) Case $mTiles['Wall3'] _GDIPlus_GraphicsDrawImageRect($mResources['Graphics'], $mResources['Wall3'], $i * $TileSize, $j * $TileSize, $TileSize, $TileSize) Case $mTiles['Wall4'] _GDIPlus_GraphicsDrawImageRect($mResources['Graphics'], $mResources['Wall4'], $i * $TileSize, $j * $TileSize, $TileSize, $TileSize) Case $mTiles['Wall5'] _GDIPlus_GraphicsDrawImageRect($mResources['Graphics'], $mResources['Wall5'], $i * $TileSize, $j * $TileSize, $TileSize, $TileSize) Case $mTiles['Wall6'] _GDIPlus_GraphicsDrawImageRect($mResources['Graphics'], $mResources['Wall6'], $i * $TileSize, $j * $TileSize, $TileSize, $TileSize) Case $mTiles['Wall7'] _GDIPlus_GraphicsDrawImageRect($mResources['Graphics'], $mResources['Wall7'], $i * $TileSize, $j * $TileSize, $TileSize, $TileSize) Case $mTiles['Wall8'] _GDIPlus_GraphicsDrawImageRect($mResources['Graphics'], $mResources['Wall8'], $i * $TileSize, $j * $TileSize, $TileSize, $TileSize) Case $mTiles['Rock'] _GDIPlus_GraphicsDrawImageRect($mResources['Graphics'], $mResources['Rock'], $i * $TileSize, $j * $TileSize, $TileSize, $TileSize) Case $mTiles['RockSocket'] _GDIPlus_GraphicsDrawImageRect($mResources['Graphics'], $mResources['RockSocket'], $i * $TileSize, $j * $TileSize, $TileSize, $TileSize) Case $mTiles['Socket'] _GDIPlus_GraphicsDrawImageRect($mResources['Graphics'], $mResources['Socket'], $i * $TileSize, $j * $TileSize, $TileSize, $TileSize) EndSwitch Next Next EndFunc Func DrawBulldozer($hImage) _GDIPlus_GraphicsDrawImageRect($mResources['Graphics'], $hImage, $X * $TileSize, $Y * $TileSize, $TileSize, $TileSize) EndFunc Func PushToScreen() Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($mResources['Bitmap']) _WinAPI_DeleteObject(GUICtrlSendMsg($hPic, 0x0172, 0, $hHBITMAP)) _WinAPI_DeleteObject($hHBITMAP) EndFunc Func ReadProperty($sProperty, $vFallback = Null) Local $aQuery = SQLite_Query($hDB, "SELECT Value FROM settings WHERE Property = " & _SQLite_FastEscape($sProperty)) If @extended Then Return $aQuery[1][0] Else Return $vFallback EndIf EndFunc Func GetTiles($vFallback = Null) Local $aQuery = SQLite_Query($hDB, 'SELECT Tile, Symbol, Data FROM tiles') If @extended Then Return $aQuery Else Return $vFallback EndIf EndFunc Func GetKeyboard($vFallback = Null) Local $aQuery = SQLite_Query($hDB, 'SELECT Key, Function FROM keyboard') If @extended Then Return $aQuery Else Return $vFallback EndIf EndFunc Func SQLite_Query($hDB, $sQuery) Local $aResult, $iRows, $iColumns _SQLite_GetTable2d($hDB, $sQuery, $aResult, $iRows, $iColumns) If @error Then Return SetError(1, 0, False) Else Return SetError(0, UBound($aResult, 1) - 1, $aResult) EndIf EndFunc Func Unpack($bData) Local $tData = DllStructCreate('byte Data[' & BinaryLen($bData) & ']') Local $bCode = Binary('0x8B7424048B4C2408AC347F8846FF4975F7C20800') Local $iSize = BinaryLen($bCode) Local $tCode = DllStructCreate('byte Code[' & $iSize & ']') DllStructSetData($tCode, 'Code', $bCode) DllStructSetData($tData, 'Data', $bData) DllCallAddress('int', DllStructGetPtr($tCode), 'ptr', DllStructGetPtr($tData), 'int', DllStructGetSize($tData)) Return DllStructGetData($tData, 'Data') EndFunc Have fun! Bulldozer.zip2 points
-
GuiBuilderPlus [updated March 24, 2024]
kurtykurtyboy and one other reacted to Skeletor for a topic
2 points -
The first thought that pops into my head is a question. How am I supposed to have any thoughts about something I haven't seen, namely your script and how you are executing the query? The second thought is why are you using the ADO UDF instead of the MySQL Command-Line Client ?1 point
-
Help combining a mysql query
argumentum reacted to Danp2 for a topic
Have you tried something like this? SELECT A.sku, A.jan, A.isbn, B.cost_amount FROM roottesCart_product AS A LEFT JOIN roottesCart_product_cost AS B ON A.product_id = B.product_id WHERE a.product_id IN (SELECT product_id FROM roottesCart_product_attribute WHERE text='Neutral')1 point -
Assign a window handle value to an application
Danp2 reacted to mistersquirrle for a topic
That is true, the handle will be different. So you're saying that you need to use AutoIt to get the window handle for another program and feed that window handle back into itself? Why can't this program get its OWN window handle??? Please, if you want more help, tell us more about what you're looking to do. What is the program that you're trying to pass the window handle to. Why does it need it. Why can't it manage or get its own window handle. What are you trying to do. Show us your current code. Screenshots. The XML. Something.1 point -
GuiBuilderPlus [updated March 24, 2024]
argumentum reacted to Skeletor for a topic
1 point -
RichEdit toggle wrap/unwrap - how?
Saad reacted to InunoTaishou for a topic
I know this is an old post but I figured it out after @orbs requested I look at this from another topic. Initially I couldn't figure it out either. I thought the $WS_HSCROLL was word wrap, and it very well may be for a regular edit control, but for richedit there is an actual word wrap option. using EM_SETTARGETDEVICE you can enable/disable word wrap #include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <Constants.au3> #include <WinAPI.au3> ; build GUI Global Const $nGUI_MaxW = 500, $nGUI_MaxH = 100 Global $nGUI_W = 720, $nGUI_H = 500, $nRichEditOffset = 10, $nRichEditOffsetTop = 30 Global $nToolbarHeight = $nRichEditOffsetTop Global $hGui = GUICreate('RichEdit wrap/unwrap test', $nGUI_W, $nGUI_H, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_SYSMENU)) GUISetBkColor(0xCCDDEE) ; - toolbar ; ** requires an extra lower contour if main rich edit is not docked to edges Global $gToolbarBackground = GUICtrlCreateLabel('', 0, 0, $nGUI_W, $nToolbarHeight) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKRIGHT, $GUI_DOCKHEIGHT)) GUICtrlSetBkColor(-1, 0xFFFFFF) GUICtrlSetState(-1, $GUI_DISABLE) Global $gToolbarBackgroundContour = GUICtrlCreateLabel('', 0, $nToolbarHeight+1, $nGUI_W, 1) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKRIGHT, $GUI_DOCKHEIGHT)) GUICtrlSetBkColor(-1, 0) GUICtrlSetState(-1, $GUI_DISABLE) ; -- wrap/unwrap Global $bWrap = False Global $gWrap = GUICtrlCreateCheckbox('Wrap', 3, 3, 48, 24, $BS_PUSHLIKE) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE)) ; - main Global $hRichEdit = _GUICtrlRichEdit_Create($hGui, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz', $nRichEditOffset, $nRichEditOffset + $nRichEditOffsetTop, $nGUI_W - $nRichEditOffset * 2, $nGUI_H - $nRichEditOffset * 2 - $nRichEditOffsetTop - 24, BitOR($ES_MULTILINE, $WS_HSCROLL, $WS_VSCROLL)) _GUICtrlRichEdit_SetSel($hRichEdit, 0, -1, True) _GUICtrlRichEdit_SetFont($hRichEdit, Default, 'Courier New') GUISetState() GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") GUIRegisterMsg($WM_SIZE, "_WM_SIZE") ; work with GUI Global $iMsg = 0 While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) Exit Case $gWrap $bWrap = Not $bWrap ConsoleWrite(_GUICtrlRichEdit_WordWrap($hRichEdit, $bWrap) & @LF) EndSwitch WEnd Func _GUICtrlRichEdit_WordWrap($hWnd, $bEnable = True) If (IsHWnd($hWnd) = False) Then Return SetError(1, 0, False) DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $EM_SETTARGETDEVICE, "wparam", 0, "lparam", Not $bEnable) If (@Error) Then Return SetError(2, @extended, False) Return True EndFunc This topic gave me the answer.1 point -
I have made some tests with event handler interfaces. For a start just to verify whether I could get some events at all. I succeeded to get events for IUIAutomationEventHandler, IUIAutomationFocusChangedEventHandler and UIAutomationStructureChangedEventHandler but not for IUIAutomationPropertyChangedEventHandler. Update 2014-01-13 Added the proper function to create custom interface methods to all 4 examples. See post #115. This means that all examples are working including the example with IUIAutomationPropertyChangedEventHandler. IUIAutomationEventHandler Run this code in Scite and you'll see window and menu open/close events in the console when you open/close a program e.g. Calculator and when you open/close a menu. #include "CUIAutomation2.au3" Opt( "MustDeclareVars", 1 ) Global Const $S_OK = 0x00000000 Global Const $E_NOINTERFACE = 0x80004002 Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}" Global $tIUIAutomationEventHandler, $oIUIAutomationEventHandler Global $oUIAutomation MainFunc() Func MainFunc() $oIUIAutomationEventHandler = ObjectFromTag( "oIUIAutomationEventHandler_", $dtagIUIAutomationEventHandler, $tIUIAutomationEventHandler, True ) If Not IsObj( $oIUIAutomationEventHandler ) Then Return $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return Local $pUIElement $oUIAutomation.GetRootElement( $pUIElement ) ; Desktop If Not $pUIElement Then Return ; Window open/close events If $oUIAutomation.AddAutomationEventHandler( $UIA_Window_WindowOpenedEventId, $pUIElement, $TreeScope_Subtree, 0, $oIUIAutomationEventHandler ) Then Exit If $oUIAutomation.AddAutomationEventHandler( $UIA_Window_WindowClosedEventId, $pUIElement, $TreeScope_Subtree, 0, $oIUIAutomationEventHandler ) Then Exit ; Menu open/close events If $oUIAutomation.AddAutomationEventHandler( $UIA_MenuOpenedEventId, $pUIElement, $TreeScope_Subtree, 0, $oIUIAutomationEventHandler ) Then Exit If $oUIAutomation.AddAutomationEventHandler( $UIA_MenuClosedEventId, $pUIElement, $TreeScope_Subtree, 0, $oIUIAutomationEventHandler ) Then Exit HotKeySet( "{ESC}", "Quit" ) While Sleep(10) WEnd EndFunc Func Quit() $oIUIAutomationEventHandler = 0 DeleteObjectFromTag( $tIUIAutomationEventHandler ) Exit EndFunc Func _UIA_getPropertyValue( $obj, $id ) Local $tVal $obj.GetCurrentPropertyValue( $id, $tVal ) Return $tVal EndFunc Func oIUIAutomationEventHandler_HandleAutomationEvent( $pSelf, $pSender, $iEventId ) ; Ret: long Par: ptr;int ConsoleWrite( "oIUIAutomationEventHandler_HandleAutomationEvent: " & $iEventId & @CRLF ) If $iEventId <> $UIA_Window_WindowClosedEventId Then Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) $oSender.AddRef() ConsoleWrite( "Title = " & _UIA_getPropertyValue( $oSender, $UIA_NamePropertyId ) & @CRLF & _ "Class = " & _UIA_getPropertyValue( $oSender, $UIA_ClassNamePropertyId ) & @CRLF & _ "Ctrl type = " & _UIA_getPropertyValue( $oSender, $UIA_ControlTypePropertyId ) & @CRLF & _ "Ctrl name = " & _UIA_getPropertyValue( $oSender, $UIA_LocalizedControlTypePropertyId ) & @CRLF & _ "Value = " & _UIA_getPropertyValue( $oSender, $UIA_LegacyIAccessibleValuePropertyId ) & @CRLF & _ "Handle = " & Hex( _UIA_getPropertyValue( $oSender, $UIA_NativeWindowHandlePropertyId ) ) & @CRLF & @CRLF ) EndIf Return $S_OK EndFunc Func oIUIAutomationEventHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* Local $sIID = StringFromGUID( $pRIID ) If $sIID = $sIID_IUnknown Then ConsoleWrite( "oIUIAutomationEventHandler_QueryInterface: IUnknown" & @CRLF ) DllStructSetData( DllStructCreate( "ptr", $pObj ), 1, $pSelf ) oIUIAutomationEventHandler_AddRef( $pSelf ) Return $S_OK ElseIf $sIID = $sIID_IUIAutomationEventHandler Then ConsoleWrite( "oIUIAutomationEventHandler_QueryInterface: IUIAutomationEventHandler" & @CRLF ) DllStructSetData( DllStructCreate( "ptr", $pObj ), 1, $pSelf ) oIUIAutomationEventHandler_AddRef( $pSelf ) Return $S_OK Else ConsoleWrite( "oIUIAutomationEventHandler_QueryInterface: " & $sIID & @CRLF ) Return $E_NOINTERFACE EndIf EndFunc Func oIUIAutomationEventHandler_AddRef( $pSelf ) ; Ret: ulong ConsoleWrite( "oIUIAutomationEventHandler_AddRef" & @CRLF ) Return 1 EndFunc Func oIUIAutomationEventHandler_Release( $pSelf ) ; Ret: ulong ConsoleWrite( "oIUIAutomationEventHandler_Release" & @CRLF ) Return 1 EndFunc Func StringFromGUID( $pGUID ) Local $aResult = DllCall( "ole32.dll", "int", "StringFromGUID2", "struct*", $pGUID, "wstr", "", "int", 40 ) If @error Then Return SetError( @error, @extended, "" ) Return SetExtended( $aResult[0], $aResult[2] ) EndFunc Func ObjectFromTag($sFunctionPrefix, $tagInterface, ByRef $tInterface, $fPrint = False, $bIsUnknown = Default, $sIID = "{00000000-0000-0000-C000-000000000046}") ; last param is IID_IUnknown by default If $bIsUnknown = Default Then $bIsUnknown = True Local $sInterface = $tagInterface ; copy interface description Local $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _ "AddRef dword();" & _ "Release dword();" ; Adding IUnknown methods If $bIsUnknown Then $tagInterface = $tagIUnknown & $tagInterface ; Below line is really simple even though it looks super complex. It's just written weird to fit in one line, not to steal your attention Local $aMethods = StringSplit(StringReplace(StringReplace(StringReplace(StringReplace(StringTrimRight(StringReplace(StringRegExpReplace(StringRegExpReplace($tagInterface, "\w+\*", "ptr"), "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF), 1), "object", "idispatch"), "hresult", "long"), "bstr", "ptr"), "variant", "ptr"), @LF, 3) Local $iUbound = UBound($aMethods) Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams, $hCallback ; Allocation $tInterface = DllStructCreate("int RefCount;int Size;ptr Object;ptr Methods[" & $iUbound & "];int_ptr Callbacks[" & $iUbound & "];ulong_ptr Slots[16]") ; 16 pointer sized elements more to create space for possible private props If @error Then Return SetError(1, 0, 0) For $i = 0 To $iUbound - 1 $aSplit = StringSplit($aMethods[$i], "|", 2) If UBound($aSplit) <> 2 Then ReDim $aSplit[2] $sNamePart = $aSplit[0] $sTagPart = $aSplit[1] $sMethod = $sFunctionPrefix & $sNamePart If $fPrint Then Local $iPar = StringInStr( $sTagPart, ";", 2 ), $t If $iPar Then $t = "Ret: " & StringLeft( $sTagPart, $iPar - 1 ) & " " & _ "Par: " & StringRight( $sTagPart, StringLen( $sTagPart ) - $iPar ) Else $t = "Ret: " & $sTagPart EndIf Local $s = "Func " & $sMethod & _ "( $pSelf ) ; " & $t & @CRLF & _ "EndFunc" & @CRLF ConsoleWrite( $s ) EndIf $aTagPart = StringSplit($sTagPart, ";", 2) $sRet = $aTagPart[0] $sParams = StringReplace($sTagPart, $sRet, "", 1) $sParams = "ptr" & $sParams $hCallback = DllCallbackRegister($sMethod, $sRet, $sParams) ConsoleWrite(@error & @CRLF & @CRLF) DllStructSetData($tInterface, "Methods", DllCallbackGetPtr($hCallback), $i + 1) ; save callback pointer DllStructSetData($tInterface, "Callbacks", $hCallback, $i + 1) ; save callback handle Next DllStructSetData($tInterface, "RefCount", 1) ; initial ref count is 1 DllStructSetData($tInterface, "Size", $iUbound) ; number of interface methods DllStructSetData($tInterface, "Object", DllStructGetPtr($tInterface, "Methods")) ; Interface method pointers Return ObjCreateInterface(DllStructGetPtr($tInterface, "Object"), $sIID, $sInterface, $bIsUnknown) ; pointer that's wrapped into object EndFunc Func DeleteObjectFromTag(ByRef $tInterface) For $i = 1 To DllStructGetData($tInterface, "Size") DllCallbackFree(DllStructGetData($tInterface, "Callbacks", $i)) Next $tInterface = 0 EndFunc IUIAutomationFocusChangedEventHandler If you test with Calculator you'll get events when you click a number button and the focus changes between the button and the edit box. #include "CUIAutomation2.au3" Opt( "MustDeclareVars", 1 ) Global Const $S_OK = 0x00000000 Global Const $E_NOINTERFACE = 0x80004002 Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}" Global $tIUIAutomationFocusChangedEventHandler, $oIUIAutomationFocusChangedEventHandler Global $oUIAutomation MainFunc() Func MainFunc() $oIUIAutomationFocusChangedEventHandler = ObjectFromTag( "oIUIAutomationFocusChangedEventHandler_", $dtagIUIAutomationFocusChangedEventHandler, $tIUIAutomationFocusChangedEventHandler, True ) If Not IsObj( $oIUIAutomationFocusChangedEventHandler ) Then Return $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return Local $pUIElement $oUIAutomation.GetRootElement( $pUIElement ) ; Desktop If Not $pUIElement Then Return If $oUIAutomation.AddFocusChangedEventHandler( 0, $oIUIAutomationFocusChangedEventHandler ) Then Exit HotKeySet( "{ESC}", "Quit" ) While Sleep(10) WEnd EndFunc Func Quit() $oIUIAutomationFocusChangedEventHandler = 0 DeleteObjectFromTag( $tIUIAutomationFocusChangedEventHandler ) Exit EndFunc Func _UIA_getPropertyValue( $obj, $id ) Local $tVal $obj.GetCurrentPropertyValue( $id, $tVal ) Return $tVal EndFunc Func oIUIAutomationFocusChangedEventHandler_HandleFocusChangedEvent( $pSelf, $pSender ) ; Ret: long Par: ptr ConsoleWrite( "oIUIAutomationFocusChangedEventHandler_HandleFocusChangedEvent: " & $pSender & @CRLF ) Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) $oSender.AddRef() ConsoleWrite( "Title = " & _UIA_getPropertyValue( $oSender, $UIA_NamePropertyId ) & @CRLF & _ "Class = " & _UIA_getPropertyValue( $oSender, $UIA_ClassNamePropertyId ) & @CRLF & _ "Ctrl type = " & _UIA_getPropertyValue( $oSender, $UIA_ControlTypePropertyId ) & @CRLF & _ "Ctrl name = " & _UIA_getPropertyValue( $oSender, $UIA_LocalizedControlTypePropertyId ) & @CRLF & _ "Value = " & _UIA_getPropertyValue( $oSender, $UIA_LegacyIAccessibleValuePropertyId ) & @CRLF & _ "Handle = " & Hex( _UIA_getPropertyValue( $oSender, $UIA_NativeWindowHandlePropertyId ) ) & @CRLF & @CRLF ) Return $S_OK EndFunc Func oIUIAutomationFocusChangedEventHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* Local $sIID = StringFromGUID( $pRIID ) If $sIID = $sIID_IUnknown Then ConsoleWrite( "oIUIAutomationFocusChangedEventHandler_QueryInterface: IUnknown" & @CRLF ) DllStructSetData( DllStructCreate( "ptr", $pObj ), 1, $pSelf ) oIUIAutomationFocusChangedEventHandler_AddRef( $pSelf ) Return $S_OK ElseIf $sIID = $sIID_IUIAutomationFocusChangedEventHandler Then ConsoleWrite( "oIUIAutomationFocusChangedEventHandler_QueryInterface: IUIAutomationFocusChangedEventHandler" & @CRLF ) DllStructSetData( DllStructCreate( "ptr", $pObj ), 1, $pSelf ) oIUIAutomationFocusChangedEventHandler_AddRef( $pSelf ) Return $S_OK Else ConsoleWrite( "oIUIAutomationFocusChangedEventHandler_QueryInterface: " & $sIID & @CRLF ) Return $E_NOINTERFACE EndIf EndFunc Func oIUIAutomationFocusChangedEventHandler_AddRef( $pSelf ) ; Ret: ulong ConsoleWrite( "oIUIAutomationFocusChangedEventHandler_AddRef" & @CRLF ) Return 1 EndFunc Func oIUIAutomationFocusChangedEventHandler_Release( $pSelf ) ; Ret: ulong ConsoleWrite( "oIUIAutomationFocusChangedEventHandler_Release" & @CRLF ) Return 1 EndFunc Func StringFromGUID( $pGUID ) Local $aResult = DllCall( "ole32.dll", "int", "StringFromGUID2", "struct*", $pGUID, "wstr", "", "int", 40 ) If @error Then Return SetError( @error, @extended, "" ) Return SetExtended( $aResult[0], $aResult[2] ) EndFunc Func ObjectFromTag($sFunctionPrefix, $tagInterface, ByRef $tInterface, $fPrint = False, $bIsUnknown = Default, $sIID = "{00000000-0000-0000-C000-000000000046}") ; last param is IID_IUnknown by default If $bIsUnknown = Default Then $bIsUnknown = True Local $sInterface = $tagInterface ; copy interface description Local $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _ "AddRef dword();" & _ "Release dword();" ; Adding IUnknown methods If $bIsUnknown Then $tagInterface = $tagIUnknown & $tagInterface ; Below line is really simple even though it looks super complex. It's just written weird to fit in one line, not to steal your attention Local $aMethods = StringSplit(StringReplace(StringReplace(StringReplace(StringReplace(StringTrimRight(StringReplace(StringRegExpReplace(StringRegExpReplace($tagInterface, "\w+\*", "ptr"), "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF), 1), "object", "idispatch"), "hresult", "long"), "bstr", "ptr"), "variant", "ptr"), @LF, 3) Local $iUbound = UBound($aMethods) Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams, $hCallback ; Allocation $tInterface = DllStructCreate("int RefCount;int Size;ptr Object;ptr Methods[" & $iUbound & "];int_ptr Callbacks[" & $iUbound & "];ulong_ptr Slots[16]") ; 16 pointer sized elements more to create space for possible private props If @error Then Return SetError(1, 0, 0) For $i = 0 To $iUbound - 1 $aSplit = StringSplit($aMethods[$i], "|", 2) If UBound($aSplit) <> 2 Then ReDim $aSplit[2] $sNamePart = $aSplit[0] $sTagPart = $aSplit[1] $sMethod = $sFunctionPrefix & $sNamePart If $fPrint Then Local $iPar = StringInStr( $sTagPart, ";", 2 ), $t If $iPar Then $t = "Ret: " & StringLeft( $sTagPart, $iPar - 1 ) & " " & _ "Par: " & StringRight( $sTagPart, StringLen( $sTagPart ) - $iPar ) Else $t = "Ret: " & $sTagPart EndIf Local $s = "Func " & $sMethod & _ "( $pSelf ) ; " & $t & @CRLF & _ "EndFunc" & @CRLF ConsoleWrite( $s ) EndIf $aTagPart = StringSplit($sTagPart, ";", 2) $sRet = $aTagPart[0] $sParams = StringReplace($sTagPart, $sRet, "", 1) $sParams = "ptr" & $sParams $hCallback = DllCallbackRegister($sMethod, $sRet, $sParams) ConsoleWrite(@error & @CRLF & @CRLF) DllStructSetData($tInterface, "Methods", DllCallbackGetPtr($hCallback), $i + 1) ; save callback pointer DllStructSetData($tInterface, "Callbacks", $hCallback, $i + 1) ; save callback handle Next DllStructSetData($tInterface, "RefCount", 1) ; initial ref count is 1 DllStructSetData($tInterface, "Size", $iUbound) ; number of interface methods DllStructSetData($tInterface, "Object", DllStructGetPtr($tInterface, "Methods")) ; Interface method pointers Return ObjCreateInterface(DllStructGetPtr($tInterface, "Object"), $sIID, $sInterface, $bIsUnknown) ; pointer that's wrapped into object EndFunc Func DeleteObjectFromTag(ByRef $tInterface) For $i = 1 To DllStructGetData($tInterface, "Size") DllCallbackFree(DllStructGetData($tInterface, "Callbacks", $i)) Next $tInterface = 0 EndFunc IUIAutomationStructureChangedEventHandler Switch between Standard and Scientific view in Calculator or switch folder in Windows Explorer and you'll get lots of events. #include "CUIAutomation2.au3" Opt( "MustDeclareVars", 1 ) Global Const $S_OK = 0x00000000 Global Const $E_NOINTERFACE = 0x80004002 Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}" Global $tIUIAutomationStructureChangedEventHandler, $oIUIAutomationStructureChangedEventHandler Global $oUIAutomation MainFunc() Func MainFunc() $oIUIAutomationStructureChangedEventHandler = ObjectFromTag( "oIUIAutomationStructureChangedEventHandler_", $dtagIUIAutomationStructureChangedEventHandler, $tIUIAutomationStructureChangedEventHandler, True ) If Not IsObj( $oIUIAutomationStructureChangedEventHandler ) Then Return $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return Local $pUIElement $oUIAutomation.GetRootElement( $pUIElement ) ; Desktop If Not $pUIElement Then Return If $oUIAutomation.AddStructureChangedEventHandler( $pUIElement, $TreeScope_Subtree, 0, $oIUIAutomationStructureChangedEventHandler ) Then Exit HotKeySet( "{ESC}", "Quit" ) While Sleep(10) WEnd EndFunc Func Quit() $oIUIAutomationStructureChangedEventHandler = 0 DeleteObjectFromTag( $tIUIAutomationStructureChangedEventHandler ) Exit EndFunc Func _UIA_getPropertyValue( $obj, $id ) Local $tVal $obj.GetCurrentPropertyValue( $id, $tVal ) Return $tVal EndFunc Func oIUIAutomationStructureChangedEventHandler_HandleStructureChangedEvent( $pSelf, $pSender, $iChangeType, $pRuntimeId ) ; Ret: long Par: ptr;long;ptr ConsoleWrite( "oIUIAutomationStructureChangedEventHandler_HandleStructureChangedEvent: " & $pSender & " " & $iChangeType & @CRLF ) Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) $oSender.AddRef() ConsoleWrite( "Title = " & _UIA_getPropertyValue( $oSender, $UIA_NamePropertyId ) & @CRLF & _ "Class = " & _UIA_getPropertyValue( $oSender, $UIA_ClassNamePropertyId ) & @CRLF & _ "Ctrl type = " & _UIA_getPropertyValue( $oSender, $UIA_ControlTypePropertyId ) & @CRLF & _ "Ctrl name = " & _UIA_getPropertyValue( $oSender, $UIA_LocalizedControlTypePropertyId ) & @CRLF & _ "Value = " & _UIA_getPropertyValue( $oSender, $UIA_LegacyIAccessibleValuePropertyId ) & @CRLF & _ "Handle = " & Hex( _UIA_getPropertyValue( $oSender, $UIA_NativeWindowHandlePropertyId ) ) & @CRLF & @CRLF ) Return $S_OK EndFunc Func oIUIAutomationStructureChangedEventHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* Local $sIID = StringFromGUID( $pRIID ) If $sIID = $sIID_IUnknown Then ConsoleWrite( "oIUIAutomationStructureChangedEventHandler_QueryInterface: IUnknown" & @CRLF ) DllStructSetData( DllStructCreate( "ptr", $pObj ), 1, $pSelf ) oIUIAutomationStructureChangedEventHandler_AddRef( $pSelf ) Return $S_OK ElseIf $sIID = $sIID_IUIAutomationStructureChangedEventHandler Then ConsoleWrite( "oIUIAutomationStructureChangedEventHandler_QueryInterface: IUIAutomationStructureChangedEventHandler" & @CRLF ) DllStructSetData( DllStructCreate( "ptr", $pObj ), 1, $pSelf ) oIUIAutomationStructureChangedEventHandler_AddRef( $pSelf ) Return $S_OK Else ConsoleWrite( "oIUIAutomationStructureChangedEventHandler_QueryInterface: " & $sIID & @CRLF ) Return $E_NOINTERFACE EndIf EndFunc Func oIUIAutomationStructureChangedEventHandler_AddRef( $pSelf ) ; Ret: ulong ConsoleWrite( "oIUIAutomationStructureChangedEventHandler_AddRef" & @CRLF ) Return 1 EndFunc Func oIUIAutomationStructureChangedEventHandler_Release( $pSelf ) ; Ret: ulong ConsoleWrite( "oIUIAutomationStructureChangedEventHandler_Release" & @CRLF ) Return 1 EndFunc Func StringFromGUID( $pGUID ) Local $aResult = DllCall( "ole32.dll", "int", "StringFromGUID2", "struct*", $pGUID, "wstr", "", "int", 40 ) If @error Then Return SetError( @error, @extended, "" ) Return SetExtended( $aResult[0], $aResult[2] ) EndFunc Func ObjectFromTag($sFunctionPrefix, $tagInterface, ByRef $tInterface, $fPrint = False, $bIsUnknown = Default, $sIID = "{00000000-0000-0000-C000-000000000046}") ; last param is IID_IUnknown by default If $bIsUnknown = Default Then $bIsUnknown = True Local $sInterface = $tagInterface ; copy interface description Local $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _ "AddRef dword();" & _ "Release dword();" ; Adding IUnknown methods If $bIsUnknown Then $tagInterface = $tagIUnknown & $tagInterface ; Below line is really simple even though it looks super complex. It's just written weird to fit in one line, not to steal your attention Local $aMethods = StringSplit(StringReplace(StringReplace(StringReplace(StringReplace(StringTrimRight(StringReplace(StringRegExpReplace(StringRegExpReplace($tagInterface, "\w+\*", "ptr"), "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF), 1), "object", "idispatch"), "hresult", "long"), "bstr", "ptr"), "variant", "ptr"), @LF, 3) Local $iUbound = UBound($aMethods) Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams, $hCallback ; Allocation $tInterface = DllStructCreate("int RefCount;int Size;ptr Object;ptr Methods[" & $iUbound & "];int_ptr Callbacks[" & $iUbound & "];ulong_ptr Slots[16]") ; 16 pointer sized elements more to create space for possible private props If @error Then Return SetError(1, 0, 0) For $i = 0 To $iUbound - 1 $aSplit = StringSplit($aMethods[$i], "|", 2) If UBound($aSplit) <> 2 Then ReDim $aSplit[2] $sNamePart = $aSplit[0] $sTagPart = $aSplit[1] $sMethod = $sFunctionPrefix & $sNamePart If $fPrint Then Local $iPar = StringInStr( $sTagPart, ";", 2 ), $t If $iPar Then $t = "Ret: " & StringLeft( $sTagPart, $iPar - 1 ) & " " & _ "Par: " & StringRight( $sTagPart, StringLen( $sTagPart ) - $iPar ) Else $t = "Ret: " & $sTagPart EndIf Local $s = "Func " & $sMethod & _ "( $pSelf ) ; " & $t & @CRLF & _ "EndFunc" & @CRLF ConsoleWrite( $s ) EndIf $aTagPart = StringSplit($sTagPart, ";", 2) $sRet = $aTagPart[0] $sParams = StringReplace($sTagPart, $sRet, "", 1) $sParams = "ptr" & $sParams $hCallback = DllCallbackRegister($sMethod, $sRet, $sParams) ConsoleWrite(@error & @CRLF & @CRLF) DllStructSetData($tInterface, "Methods", DllCallbackGetPtr($hCallback), $i + 1) ; save callback pointer DllStructSetData($tInterface, "Callbacks", $hCallback, $i + 1) ; save callback handle Next DllStructSetData($tInterface, "RefCount", 1) ; initial ref count is 1 DllStructSetData($tInterface, "Size", $iUbound) ; number of interface methods DllStructSetData($tInterface, "Object", DllStructGetPtr($tInterface, "Methods")) ; Interface method pointers Return ObjCreateInterface(DllStructGetPtr($tInterface, "Object"), $sIID, $sInterface, $bIsUnknown) ; pointer that's wrapped into object EndFunc Func DeleteObjectFromTag(ByRef $tInterface) For $i = 1 To DllStructGetData($tInterface, "Size") DllCallbackFree(DllStructGetData($tInterface, "Callbacks", $i)) Next $tInterface = 0 EndFunc IUIAutomationPropertyChangedEventHandler I have tested the code below with Internet Explorer and I have expected to get $UIA_ValueValuePropertyId change events when I switch between different URLs. But I get no events. I have tried with several other programs but I simply get no events. Is there anyone who has managed to record these events? In that case, I'd like to see the code. To test the code you must change the description for AddPropertyChangedEventHandlerNativeArray in CUIAutomation2.au3 to this: "AddPropertyChangedEventHandlerNativeArray hresult(ptr;long;ptr;ptr;struct*;int);" #include "CUIAutomation2.au3" Opt( "MustDeclareVars", 1 ) Global Const $S_OK = 0x00000000 Global Const $E_NOINTERFACE = 0x80004002 Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}" Global $tIUIAutomationPropertyChangedEventHandler, $oIUIAutomationPropertyChangedEventHandler Global $oUIAutomation MainFunc() Func MainFunc() $oIUIAutomationPropertyChangedEventHandler = ObjectFromTag( "oIUIAutomationPropertyChangedEventHandler_", $dtagIUIAutomationPropertyChangedEventHandler, $tIUIAutomationPropertyChangedEventHandler, True ) If Not IsObj( $oIUIAutomationPropertyChangedEventHandler ) Then Return $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return Local $pUIElement $oUIAutomation.GetRootElement( $pUIElement ) ; Desktop If Not $pUIElement Then Return Local $tPropertyArray = DllStructCreate( "int[2]" ) DllStructSetData( $tPropertyArray, 1, $UIA_ValueValuePropertyId, 1 ) DllStructSetData( $tPropertyArray, 1, $UIA_ToggleToggleStatePropertyId, 2 ) $oUIAutomation.AddPropertyChangedEventHandlerNativeArray( $pUIElement, $TreeScope_Descendants, 0, $oIUIAutomationPropertyChangedEventHandler, $tPropertyArray, 2 ) HotKeySet( "{ESC}", "Quit" ) While Sleep(100) WEnd EndFunc Func Quit() $oIUIAutomationPropertyChangedEventHandler = 0 DeleteObjectFromTag( $tIUIAutomationPropertyChangedEventHandler ) Exit EndFunc Func _UIA_getPropertyValue( $obj, $id ) Local $vVal $obj.GetCurrentPropertyValue( $id, $vVal ) Return $vVal EndFunc Func oIUIAutomationPropertyChangedEventHandler_HandlePropertyChangedEvent( $pSelf, $pSender, $iPropertyId, $newValue ) ; Ret: long Par: ptr;int;variant ConsoleWrite( @CRLF & "oIUIAutomationPropertyChangedEventHandler_HandlePropertyChangedEvent: $iPropertyId = " & $iPropertyId & ", $newValue = " & $newValue & @CRLF ) Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) $oSender.AddRef( ) ConsoleWrite( "Handle " & _UIA_getPropertyValue( $oSender, $UIA_NativeWindowHandlePropertyId ) & @CRLF ) ConsoleWrite( "Name " & _UIA_getPropertyValue( $oSender, $UIA_NamePropertyId ) & @CRLF ) ConsoleWrite( "Class " & _UIA_getPropertyValue( $oSender, $UIA_ClassNamePropertyId ) & @CRLF ) ConsoleWrite( "Ctrl type " & _UIA_getPropertyValue( $oSender, $UIA_ControlTypePropertyId ) & @CRLF ) ConsoleWrite( "Ctrl name " & _UIA_getPropertyValue( $oSender, $UIA_LocalizedControlTypePropertyId ) & @CRLF ) ConsoleWrite( "Value " & _UIA_getPropertyValue( $oSender, $UIA_LegacyIAccessibleValuePropertyId ) & @CRLF ) Return $S_OK EndFunc Func oIUIAutomationPropertyChangedEventHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long Par: ptr;ptr* Local $sIID = StringFromGUID( $pRIID ) If $sIID = $sIID_IUnknown Then ConsoleWrite( "oIUIAutomationPropertyChangedEventHandler_QueryInterface: IUnknown" & @CRLF ) DllStructSetData( DllStructCreate( "ptr", $pObj ), 1, $pSelf ) Return $S_OK ElseIf $sIID = $sIID_IUIAutomationPropertyChangedEventHandler Then ConsoleWrite( "oIUIAutomationPropertyChangedEventHandler_QueryInterface: IUIAutomationPropertyChangedEventHandler" & @CRLF ) DllStructSetData( DllStructCreate( "ptr", $pObj ), 1, $pSelf ) Return $S_OK Else ConsoleWrite( "oIUIAutomationPropertyChangedEventHandler_QueryInterface: " & $sIID & @CRLF ) Return $E_NOINTERFACE EndIf EndFunc Func oIUIAutomationPropertyChangedEventHandler_AddRef( $pSelf ) ; Ret: ulong ConsoleWrite( "oIUIAutomationPropertyChangedEventHandler_AddRef" & @CRLF ) Return 1 EndFunc Func oIUIAutomationPropertyChangedEventHandler_Release( $pSelf ) ; Ret: ulong ConsoleWrite( "oIUIAutomationPropertyChangedEventHandler_Release" & @CRLF ) Return 1 EndFunc Func StringFromGUID( $pGUID ) Local $aResult = DllCall( "ole32.dll", "int", "StringFromGUID2", "struct*", $pGUID, "wstr", "", "int", 40 ) If @error Then Return SetError( @error, @extended, "" ) Return SetExtended( $aResult[0], $aResult[2] ) EndFunc Func ObjectFromTag($sFunctionPrefix, $tagInterface, ByRef $tInterface, $fPrint = False, $bIsUnknown = Default, $sIID = "{00000000-0000-0000-C000-000000000046}") ; last param is IID_IUnknown by default If $bIsUnknown = Default Then $bIsUnknown = True Local $sInterface = $tagInterface ; copy interface description Local $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _ "AddRef dword();" & _ "Release dword();" ; Adding IUnknown methods If $bIsUnknown Then $tagInterface = $tagIUnknown & $tagInterface ; Below line is really simple even though it looks super complex. It's just written weird to fit in one line, not to steal your attention Local $aMethods = StringSplit(StringReplace(StringReplace(StringReplace(StringReplace(StringTrimRight(StringReplace(StringRegExpReplace(StringRegExpReplace($tagInterface, "\w+\*", "ptr"), "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF), 1), "object", "idispatch"), "hresult", "long"), "bstr", "ptr"), "variant", "ptr"), @LF, 3) Local $iUbound = UBound($aMethods) Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams, $hCallback ; Allocation $tInterface = DllStructCreate("int RefCount;int Size;ptr Object;ptr Methods[" & $iUbound & "];int_ptr Callbacks[" & $iUbound & "];ulong_ptr Slots[16]") ; 16 pointer sized elements more to create space for possible private props If @error Then Return SetError(1, 0, 0) For $i = 0 To $iUbound - 1 $aSplit = StringSplit($aMethods[$i], "|", 2) If UBound($aSplit) <> 2 Then ReDim $aSplit[2] $sNamePart = $aSplit[0] $sTagPart = $aSplit[1] $sMethod = $sFunctionPrefix & $sNamePart If $fPrint Then Local $iPar = StringInStr( $sTagPart, ";", 2 ), $t If $iPar Then $t = "Ret: " & StringLeft( $sTagPart, $iPar - 1 ) & " " & _ "Par: " & StringRight( $sTagPart, StringLen( $sTagPart ) - $iPar ) Else $t = "Ret: " & $sTagPart EndIf Local $s = "Func " & $sMethod & _ "( $pSelf ) ; " & $t & @CRLF & _ "EndFunc" & @CRLF ConsoleWrite( $s ) EndIf $aTagPart = StringSplit($sTagPart, ";", 2) $sRet = $aTagPart[0] $sParams = StringReplace($sTagPart, $sRet, "", 1) $sParams = "ptr" & $sParams $hCallback = DllCallbackRegister($sMethod, $sRet, $sParams) ConsoleWrite(@error & @CRLF & @CRLF) DllStructSetData($tInterface, "Methods", DllCallbackGetPtr($hCallback), $i + 1) ; save callback pointer DllStructSetData($tInterface, "Callbacks", $hCallback, $i + 1) ; save callback handle Next DllStructSetData($tInterface, "RefCount", 1) ; initial ref count is 1 DllStructSetData($tInterface, "Size", $iUbound) ; number of interface methods DllStructSetData($tInterface, "Object", DllStructGetPtr($tInterface, "Methods")) ; Interface method pointers Return ObjCreateInterface(DllStructGetPtr($tInterface, "Object"), $sIID, $sInterface, $bIsUnknown) ; pointer that's wrapped into object EndFunc Func DeleteObjectFromTag(ByRef $tInterface) For $i = 1 To DllStructGetData($tInterface, "Size") DllCallbackFree(DllStructGetData($tInterface, "Callbacks", $i)) Next $tInterface = 0 EndFunc Update 2014-01-13 Added the proper function to create custom interface methods to all 4 examples. See post #115. This means that all examples are working including the example with IUIAutomationPropertyChangedEventHandler.1 point