Jump to content

Event based new message box opening detection


Go to solution Solved by Danyfirex,

Recommended Posts

I'm trying detect when a new message box opened (a modal window) by a specific application. (example the type that shows when you try close notepad with modified but not saved file in it on Windows 10)

I'm currently using something like this:

Local $hwndPrev
While 1
  local $hwnd = WinGetHandle("[CLASS:#32770; TITLE:Notepad]") ; file not saved dialog promt
  If $hwnd And $hwnd <> $hwndPrev Then
    $hwndPrev = $hwnd
    ; process popup
    WinClose($hwnd)
  EndIf
  sleep(10)
WEnd

It works fine, however my script uses 1-2% CPU at all times. I can increase sleep time, but I need to detect new window as soon as possible so it can be closed before appearing on screen for too long.

I've tried SHELLHOOK, but it doesn't trigger on this type of windows (modal windows?)

#include <WinAPISysWin.au3>

OnAutoItExitRegister(OnAutoItExit)

Global $hGUI = GUICreate('')
GUIRegisterMsg(_WinAPI_RegisterWindowMessage('SHELLHOOK'), WM_SHELLHOOK)
_WinAPI_RegisterShellHookWindow($hGUI)

While 1
  Sleep(1000)
WEnd

Func WM_SHELLHOOK($hWnd, $iMsg, $wParam, $lParam)
  #forceref $iMsg
  if WinGetTitle($lParam) = "Notepad" Then
    ; process popup
    WinClose($lParam)
  EndIf
EndFunc   ;==>WM_SHELLHOOK

Func OnAutoItExit()
        _WinAPI_DeregisterShellHookWindow($hGUI)
EndFunc   ;==>OnAutoItExit

Is there an event based method to detect modal windows?


Thank you.

Edited by VAN0
Link to comment
Share on other sites

4 minutes ago, VAN0 said:

I've tried SHELLHOOK, but it doesn't trigger on this type of windows (modal windows?)

Can you say exactly what type of windows are you talking about?

When the words fail... music speaks.

Link to comment
Share on other sites

#include <WinAPISys.au3>

Global $hEventProc = DllCallbackRegister(_EventProc, 'none', 'ptr;dword;hwnd;long;long;dword;dword')
OnAutoItExitRegister(OnAutoItExit)
HotKeySet("{ESC}", Terminate)
Local $iPID = Run("Notepad")
Global $hEventHook = _WinAPI_SetWinEventHook($EVENT_SYSTEM_DIALOGSTART, $EVENT_SYSTEM_DIALOGSTART, DllCallbackGetPtr($hEventProc), $iPID)

Local $hWnd = WinWaitActive("[CLASS:Notepad]")
ControlSend($hWnd, "", "Edit1", "Test")
ControlSend($hWnd, "", "", "!{F4}")   ; simulate a msgbox

While 1
  Sleep(1000)
WEnd

Func Terminate()
  Exit
EndFunc   ;==>Terminate

Func OnAutoItExit()
  _WinAPI_UnhookWinEvent($hEventHook)
  DllCallbackFree($hEventProc)
EndFunc   ;==>OnAutoItExit

Func _EventProc($hEventHook, $iEvent, $hWnd, $iObjectID, $iChildID, $iThreadId, $iEventTime)
  WinMove($hWnd, "", @DesktopWidth, @DesktopHeight)
  WinKill($hWnd)
  ConsoleWrite("Closed" & @CRLF)
EndFunc   ;==>_EventProc

 

Edited by Nine
Link to comment
Share on other sites

Don't think so.  If I remember correctly you cannot set a CBT hook globally unless you provide a valid DLL to manage the callback.  OP wants to intercept popups from external process.  Not his.

Edited by Nine
Link to comment
Share on other sites

Because I am on windows 11 and I can't test how notepad works on other versions of windows. As far as I can see your solution doesn't work also. Anyway, what's your problem with my posts? Get a life. :bonk:

When the words fail... music speaks.

Link to comment
Share on other sites

"Windows Notepad 11.2401.26.0
© 2023 Microsoft. All rights reserved"

This version works with tabs and is a different beast altogether. Even if "Open in a new window" is set instead of  "Open in a new tab".

Am giving away Hyper-V use right to anyone with Windows Pro and above. :P
Today only. Hurry. :frantics:

Y'all should start using VMs. Just to see if it works. Welcome to the future ? :(  

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

I have VirtualBox but I don't test all scripts on each version of windows, I leave a chance for the noobie to do his show otherwise he will bark around because he cannot post. :frantics:

When the words fail... music speaks.

Link to comment
Share on other sites

Posted (edited)

@Nine Your example works great on W10, even when notepad started manually, I just changed it to this:

Local $hWnd = WinWaitActive("[CLASS:Notepad]")
Local $iPID = WinGetProcess($hWnd)

However, it doesn't work with VCarve Pro application. I made sure it gets proper pid (it's the same as in task manager shown), but popups don't trigger the event handler.

The popup it opens:

image.png.8659ac659ba45ce5e5f0bfa2a29332e7.pngimage.png.ea13668943b9635c1240a34e2d2cc49b.png

Quote

>>>> Window <<<<
Title:    VCarve Pro
Class:    #32770
Position:    4236, -830
Size:    488, 226
Style:    0x94C80884
ExStyle:    0x00010101
Handle:    0x050E230A

>>>> Control <<<<
Class:    
Instance:    
ClassnameNN:    
Name:    
Advanced (Class):    
ID:    
Text:    
Position:    
Size:    
ControlClick Coords:    
Style:    
ExStyle:    
Handle:    

>>>> Mouse <<<<
Position:    4441, -811
Cursor ID:    0
Color:    0xFFFFFF

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
OK


>>>> Hidden Text <<<<
 

 

Edited by VAN0
Link to comment
Share on other sites

  • Moderators

Both of you need to either learn to scroll or walk away from the thread; the bickering is tiresome already.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

That's an interesting monitor setup you have, looking at "Position: 4236, -830" you must have a multimonitor setup where the primary monitor is bottom monitor and the secondary on top, and  you either have a huge 49" monitor with a smaller on top or a triple/quad monitor setup.

That might interfere with something, have you tried with notepad starting at the same position/monitor as VCarve and see if that still work?. 

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

29 minutes ago, argumentum said:

Just thinking. If UI Automation don't work either, then maybe OCR the screen ?

UI Automation didn't reveal anything new; it is definitely a dialog, not a window. I'm not sure how OCR could help in this case...

Spoiler

Treeview Element                                    Window: VCarve Pro
                                                    
Element Properties (identification)                 
$UIA_ClassNamePropertyId                            #32770
$UIA_ControlTypePropertyId                          $UIA_WindowControlTypeId
$UIA_NamePropertyId                                 VCarve Pro
                                                    
Element Properties (session unique)                 
$UIA_NativeWindowHandlePropertyId                   0x00072FA0
$UIA_ProcessIdPropertyId                            42896
$UIA_RuntimeIdPropertyId                            42,470944
                                                    
Element Properties (information)                    
$UIA_BoundingRectanglePropertyId                    l=4355,t=-771,w=250,h=109
$UIA_FrameworkIdPropertyId                          Win32
$UIA_LocalizedControlTypePropertyId                 dialog
$UIA_ProviderDescriptionPropertyId                  [pid:32424,providerId:0x72FA0 Main:Microsoft: Container Proxy (unmanaged:uiautomationcore.dll); Nonclient:Microsoft: Non-Client Proxy (unmanaged:uiautomationcore.dll); Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)]
                                                    
Element Properties (has/is info)                    
$UIA_HasKeyboardFocusPropertyId                     False
$UIA_IsContentElementPropertyId                     True
$UIA_IsControlElementPropertyId                     True
$UIA_IsDataValidForFormPropertyId                   False
$UIA_IsEnabledPropertyId                            True
$UIA_IsKeyboardFocusablePropertyId                  True
$UIA_IsOffscreenPropertyId                          False
$UIA_IsPasswordPropertyId                           False
$UIA_IsRequiredForFormPropertyId                    False
                                                    
Control Patterns (element actions)                  
$UIA_IsLegacyIAccessiblePatternAvailablePropertyId  True (LegacyIAccessiblePattern)
$UIA_IsTransformPatternAvailablePropertyId          True (TransformPattern)
$UIA_IsWindowPatternAvailablePropertyId             True (WindowPattern)
                                                    
Control Pattern Properties                          
$UIA_LegacyIAccessibleChildIdPropertyId             0
$UIA_LegacyIAccessibleDefaultActionPropertyId       OK
$UIA_LegacyIAccessibleDescriptionPropertyId         
$UIA_LegacyIAccessibleHelpPropertyId                
$UIA_LegacyIAccessibleKeyboardShortcutPropertyId    
$UIA_LegacyIAccessibleNamePropertyId                VCarve Pro
$UIA_LegacyIAccessibleRolePropertyId                18 = $ROLE_SYSTEM_DIALOG
$UIA_LegacyIAccessibleStatePropertyId               1048576 = $STATE_SYSTEM_FOCUSABLE
$UIA_LegacyIAccessibleValuePropertyId               
$UIA_TransformCanMovePropertyId                     True
$UIA_TransformCanResizePropertyId                   False
$UIA_TransformCanRotatePropertyId                   False
$UIA_WindowCanMaximizePropertyId                    False
$UIA_WindowCanMinimizePropertyId                    False
$UIA_WindowIsModalPropertyId                        True
$UIA_WindowIsTopmostPropertyId                      False
$UIA_WindowWindowInteractionStatePropertyId         $WindowInteractionState_ReadyForUserInteraction
$UIA_WindowWindowVisualStatePropertyId              $WindowVisualState_Normal
                                                    
Control Pattern Methods                             
LegacyIAccessible Pattern Methods                   
                                                    DoDefaultAction()
                                                    Select(long)
                                                    SetValue(wstr)
                                                    GetIAccessible(idispatch*)
                                                    CurrentChildId(int*)
                                                    CurrentDefaultAction(bstr*)
                                                    CurrentDescription(bstr*)
                                                    CurrentHelp(bstr*)
                                                    CurrentKeyboardShortcut(bstr*)
                                                    CurrentName(bstr*)
                                                    CurrentRole(uint*)
                                                    CurrentState(uint*)
                                                    CurrentValue(bstr*)
                                                    GetCurrentSelection(ptr*)
Transform Pattern Methods                           
                                                    Move($fXPos,$fYPos)
                                                    Resize($fWidth,$fHeight)
                                                    Rotate($fDegrees)
                                                    CurrentCanMove($bCanMove*)
                                                    CurrentCanResize($bCanResize*)
                                                    CurrentCanRotate($bCanRotate*)
Window Pattern Methods                              
                                                    Close()
                                                    SetWindowVisualState($iWindowVisualState)
                                                    WaitForInputIdle($iMilliSeconds,$bSuccess*)
                                                    CurrentCanMaximize($bCanMaximize*)
                                                    CurrentCanMinimize($bCanMinimize*)
                                                    CurrentIsModal($bIsModal*)
                                                    CurrentIsTopmost($bIsTopmost*)
                                                    CurrentWindowVisualState($iWindowVisualState*)
                                                    CurrentWindowInteractionState($iWindowInteractionState*)
                                                    
Parents from Desktop                                Pane: Desktop 1
                                                    Window: VCarve Pro 10.514 - {Zamueco[TPC]} - [New]
                                                    
Parent to child index                               0
 

 

28 minutes ago, Werty said:

That's an interesting monitor setup you have, looking at "Position: 4236, -830" you must have a multimonitor setup where the primary monitor is bottom monitor and the secondary on top, and  you either have a huge 49" monitor with a smaller on top or a triple/quad monitor setup.

That might interfere with something, have you tried with notepad starting at the same position/monitor as VCarve and see if that still work?. 

It's triple monitor setup, 2 side-by-side and one on top. I've tried move it to primary monitor, nothing changed.

Link to comment
Share on other sites

Posted (edited)

Yes, some events are going through, such as mouse movement, mouse over highlight, switching panels, showing/hiding tooltips:

Spoiler
07:38:25.469 PID: 1600
07:38:26.870 $EVENT_OBJECT_LOCATIONCHANGE | -9 | 0 | 20300 | 29530531    <--- mouse started moving over window
...
07:38:26.926 $EVENT_OBJECT_LOCATIONCHANGE | -9 | 0 | 20300 | 29530593
07:38:26.926 $EVENT_OBJECT_REORDER | -4 | 0 | 20300 | 29530593
07:38:26.937 $EVENT_OBJECT_LOCATIONCHANGE | -9 | 0 | 20300 | 29530593
07:38:26.937 $EVENT_OBJECT_NAMECHANGE | -9 | 0 | 20300 | 29530593
07:38:26.991 $EVENT_OBJECT_LOCATIONCHANGE | -9 | 0 | 20300 | 29530640
...
07:38:27.110 $EVENT_OBJECT_LOCATIONCHANGE | -9 | 0 | 20300 | 29530765
07:38:27.440 $EVENT_OBJECT_LOCATIONCHANGE | 0 | 0 | 20300 | 29531093
07:38:27.440 $EVENT_OBJECT_REORDER | -4 | 0 | 20300 | 29531093
07:38:27.440 $EVENT_OBJECT_LOCATIONCHANGE | 0 | 0 | 20300 | 29531093
07:38:27.440 $EVENT_OBJECT_SHOW | 0 | 0 | 20300 | 29531093                             <--- tooltip shown
07:38:27.440 $EVENT_OBJECT_CREATE | 0 | 0 | 20300 | 29531093
07:38:27.440 $EVENT_OBJECT_LOCATIONCHANGE | 0 | 0 | 20300 | 29531093
07:38:27.440 $EVENT_OBJECT_SHOW | 0 | 0 | 20300 | 29531093
07:38:27.440 $EVENT_OBJECT_REORDER | -4 | 0 | 20300 | 29531093
07:38:27.451 $EVENT_OBJECT_LOCATIONCHANGE | -9 | 0 | 20300 | 29531093
...
07:38:27.643 $EVENT_OBJECT_LOCATIONCHANGE | 0 | 0 | 20300 | 29531312
07:38:32.430 $EVENT_OBJECT_HIDE | 0 | 0 | 20300 | 29536093
07:38:32.430 $EVENT_OBJECT_HIDE | 0 | 0 | 20300 | 29536093
07:38:32.430 $EVENT_OBJECT_DESTROY | 0 | 0 | 20300 | 29536093                          <--- tooltip removed
07:38:37.600 $EVENT_SYSTEM_CAPTURESTART | 0 | 0 | 20300 | 29541250              <--- icon to open popup pressed
07:38:43.750 $EVENT_SYSTEM_CAPTUREEND | 0 | 0 | 20300 | 29547406                 <--- icon released
07:38:43.762 $EVENT_OBJECT_STATECHANGE | 0 | 0 | 20300 | 29547406
...
07:38:43.762 $EVENT_OBJECT_STATECHANGE | 0 | 0 | 20300 | 29547421
07:38:43.762 $EVENT_OBJECT_CREATE | 0 | 0 | 20300 | 29547421
07:38:43.762 $EVENT_OBJECT_SHOW | 0 | 0 | 20300 | 29547421
07:38:43.774 $EVENT_OBJECT_CREATE | 0 | 0 | 20300 | 29547421
07:38:43.774 $EVENT_OBJECT_SHOW | 0 | 0 | 20300 | 29547421
07:38:43.774 $EVENT_OBJECT_LOCATIONCHANGE | 0 | 0 | 20300 | 29547421
07:38:43.774 $EVENT_OBJECT_LOCATIONCHANGE | 0 | 0 | 20300 | 29547421
07:38:43.774 $EVENT_OBJECT_NAMECHANGE | -4 | 1 | 20300 | 29547421
07:38:43.774 $EVENT_OBJECT_NAMECHANGE | -9 | 0 | 20300 | 29547421
07:38:43.786 $EVENT_OBJECT_NAMECHANGE | -4 | 280 | 20300 | 29547437
07:38:43.786 $EVENT_OBJECT_NAMECHANGE | 0 | 0 | 20300 | 29547437
07:38:43.786 $EVENT_OBJECT_DESTROY | -4 | 0 | 20300 | 29547437
07:38:43.786 $EVENT_OBJECT_DESTROY | -4 | 280 | 20300 | 29547437
07:38:43.786 $EVENT_OBJECT_DESTROY | -4 | 281 | 20300 | 29547437
07:38:43.786 $EVENT_OBJECT_CREATE | -4 | 282 | 20300 | 29547437
07:38:43.786 $EVENT_OBJECT_STATECHANGE | -4 | 282 | 20300 | 29547437
07:38:43.786 $EVENT_OBJECT_CREATE | -4 | 283 | 20300 | 29547437
07:38:43.786 $EVENT_OBJECT_STATECHANGE | -4 | 283 | 20300 | 29547437
07:38:43.798 $EVENT_OBJECT_DESTROY | -4 | 0 | 20300 | 29547437
07:38:43.798 $EVENT_OBJECT_DESTROY | -4 | 282 | 20300 | 29547437
07:38:43.798 $EVENT_OBJECT_DESTROY | -4 | 283 | 20300 | 29547437
07:38:43.798 $EVENT_OBJECT_CREATE | -4 | 284 | 20300 | 29547437
07:38:43.798 $EVENT_OBJECT_STATECHANGE | -4 | 284 | 20300 | 29547437
07:38:43.798 $EVENT_OBJECT_CREATE | -4 | 285 | 20300 | 29547437
07:38:43.798 $EVENT_OBJECT_STATECHANGE | -4 | 285 | 20300 | 29547437
07:38:43.798 $EVENT_OBJECT_NAMECHANGE | 0 | 0 | 20300 | 29547437
07:38:43.809 $EVENT_OBJECT_NAMECHANGE | -4 | 285 | 20300 | 29547453
07:38:43.809 $EVENT_OBJECT_NAMECHANGE | 0 | 0 | 20300 | 29547453
07:38:43.809 $EVENT_OBJECT_DESTROY | -4 | 0 | 20300 | 29547468
07:38:43.809 $EVENT_OBJECT_DESTROY | -4 | 284 | 20300 | 29547468
07:38:43.809 $EVENT_OBJECT_DESTROY | -4 | 285 | 20300 | 29547468
07:38:43.809 $EVENT_OBJECT_CREATE | -4 | 286 | 20300 | 29547468
07:38:43.809 $EVENT_OBJECT_STATECHANGE | -4 | 286 | 20300 | 29547468
07:38:43.809 $EVENT_OBJECT_CREATE | -4 | 287 | 20300 | 29547468
07:38:43.809 $EVENT_OBJECT_STATECHANGE | -4 | 287 | 20300 | 29547468
07:38:43.809 $EVENT_OBJECT_DESTROY | -4 | 0 | 20300 | 29547468
07:38:43.809 $EVENT_OBJECT_DESTROY | -4 | 286 | 20300 | 29547468
07:38:43.809 $EVENT_OBJECT_DESTROY | -4 | 287 | 20300 | 29547468
07:38:43.809 $EVENT_OBJECT_CREATE | -4 | 288 | 20300 | 29547468
07:38:43.809 $EVENT_OBJECT_STATECHANGE | -4 | 288 | 20300 | 29547468
07:38:43.809 $EVENT_OBJECT_CREATE | -4 | 289 | 20300 | 29547468
07:38:43.809 $EVENT_OBJECT_STATECHANGE | -4 | 289 | 20300 | 29547468
07:38:43.809 $EVENT_OBJECT_NAMECHANGE | 0 | 0 | 20300 | 29547468
07:38:43.821 $EVENT_OBJECT_DESTROY | 0 | 0 | 20300 | 29547468
07:38:43.821 $EVENT_OBJECT_NAMECHANGE | -4 | 1 | 20300 | 29547468
07:38:43.821 $EVENT_OBJECT_HIDE | 0 | 0 | 20300 | 29547468
07:38:43.821 $EVENT_OBJECT_DESTROY | 0 | 0 | 20300 | 29547468
07:38:43.821 $EVENT_OBJECT_STATECHANGE | 0 | 0 | 20300 | 29547468
...
07:38:43.821 $EVENT_OBJECT_STATECHANGE | 0 | 0 | 20300 | 29547468
07:38:43.821 $EVENT_OBJECT_NAMECHANGE | -9 | 0 | 20300 | 29547468
07:38:43.821 $EVENT_OBJECT_CREATE | 0 | 0 | 20300 | 29547484
07:38:43.831 $EVENT_OBJECT_CREATE | 0 | 0 | 20300 | 29547484
07:38:43.831 $EVENT_SYSTEM_FOREGROUND | 0 | 0 | 20300 | 29547484
07:38:43.831 $EVENT_OBJECT_REORDER | -4 | 0 | 20300 | 29547484
07:38:43.831 $EVENT_OBJECT_FOCUS | -4 | 0 | 20300 | 29547484
07:38:43.831 0x7FFFFF30 | 3 | 1073758216 | 20300 | 29547484                               <--- this shows every time a panel switched, or a popup opened
07:38:43.831 $EVENT_OBJECT_NAMECHANGE | 0 | 0 | 20300 | 29547484
07:38:43.831 $EVENT_OBJECT_LOCATIONCHANGE | 0 | 0 | 20300 | 29547484
07:38:43.831 $EVENT_OBJECT_LOCATIONCHANGE | 0 | 0 | 20300 | 29547484
07:38:43.831 $EVENT_OBJECT_SHOW | 0 | 0 | 20300 | 29547484
07:38:43.843 $EVENT_OBJECT_NAMECHANGE | -9 | 0 | 20300 | 29547500

There is one event I might be able work with is: 0x7FFFFF30 It seems to only be triggered when something major happened, such as panel switched, or popup opened.

 

Spoiler
#include <WinAPISys.au3>

Global $hEventProc = DllCallbackRegister(_EventProc, 'none', 'ptr;dword;hwnd;long;long;dword;dword')
OnAutoItExitRegister(OnAutoItExit)
HotKeySet("{ESC}", Terminate)
Local $hWnd = WinWaitActive("[TITLE:VCarve Pro]")
Local $iPID = WinGetProcess($hWnd)
ConsoleWrite("PID: " & $iPID & @CRLF)
Global $hEventHook = _WinAPI_SetWinEventHook( $EVENT_MIN, $EVENT_MAX, DllCallbackGetPtr($hEventProc), $iPID)
Global $map[]
$map[0x00000001] = "$EVENT_MIN"
$map[0x00000001] = "$EVENT_SYSTEM_SOUND"
$map[0x00000002] = "$EVENT_SYSTEM_ALERT"
$map[0x00000003] = "$EVENT_SYSTEM_FOREGROUND"
$map[0x00000004] = "$EVENT_SYSTEM_MENUSTART"
$map[0x00000005] = "$EVENT_SYSTEM_MENUEND"
$map[0x00000006] = "$EVENT_SYSTEM_MENUPOPUPSTART"
$map[0x00000007] = "$EVENT_SYSTEM_MENUPOPUPEND"
$map[0x00000008] = "$EVENT_SYSTEM_CAPTURESTART"
$map[0x00000009] = "$EVENT_SYSTEM_CAPTUREEND"
$map[0x0000000A] = "$EVENT_SYSTEM_MOVESIZESTART"
$map[0x0000000B] = "$EVENT_SYSTEM_MOVESIZEEND"
$map[0x0000000C] = "$EVENT_SYSTEM_CONTEXTHELPSTART"
$map[0x0000000D] = "$EVENT_SYSTEM_CONTEXTHELPEND"
$map[0x0000000E] = "$EVENT_SYSTEM_DRAGDROPSTART"
$map[0x0000000F] = "$EVENT_SYSTEM_DRAGDROPEND"
$map[0x00000010] = "$EVENT_SYSTEM_DIALOGSTART"
$map[0x00000011] = "$EVENT_SYSTEM_DIALOGEND"
$map[0x00000012] = "$EVENT_SYSTEM_SCROLLINGSTART"
$map[0x00000013] = "$EVENT_SYSTEM_SCROLLINGEND"
$map[0x00000014] = "$EVENT_SYSTEM_SWITCHSTART"
$map[0x00000015] = "$EVENT_SYSTEM_SWITCHEND"
$map[0x00000016] = "$EVENT_SYSTEM_MINIMIZESTART"
$map[0x00000017] = "$EVENT_SYSTEM_MINIMIZEEND"
$map[0x00000020] = "$EVENT_SYSTEM_DESKTOPSWITCH"
$map[0x00008000] = "$EVENT_OBJECT_CREATE"
$map[0x00008001] = "$EVENT_OBJECT_DESTROY"
$map[0x00008002] = "$EVENT_OBJECT_SHOW"
$map[0x00008003] = "$EVENT_OBJECT_HIDE"
$map[0x00008004] = "$EVENT_OBJECT_REORDER"
$map[0x00008005] = "$EVENT_OBJECT_FOCUS"
$map[0x00008006] = "$EVENT_OBJECT_SELECTION"
$map[0x00008007] = "$EVENT_OBJECT_SELECTIONADD"
$map[0x00008008] = "$EVENT_OBJECT_SELECTIONREMOVE"
$map[0x00008009] = "$EVENT_OBJECT_SELECTIONWITHIN"
$map[0x0000800A] = "$EVENT_OBJECT_STATECHANGE"
$map[0x0000800B] = "$EVENT_OBJECT_LOCATIONCHANGE"
$map[0x0000800C] = "$EVENT_OBJECT_NAMECHANGE"
$map[0x0000800D] = "$EVENT_OBJECT_DESCRIPTIONCHANGE"
$map[0x0000800E] = "$EVENT_OBJECT_VALUECHANGE"
$map[0x0000800F] = "$EVENT_OBJECT_PARENTCHANGE"
$map[0x00008010] = "$EVENT_OBJECT_HELPCHANGE"
$map[0x00008011] = "$EVENT_OBJECT_DEFACTIONCHANGE"
$map[0x00008012] = "$EVENT_OBJECT_ACCELERATORCHANGE"
$map[0x00008013] = "$EVENT_OBJECT_INVOKED"
$map[0x00008014] = "$EVENT_OBJECT_TEXTSELECTIONCHANGED"
$map[0x00008015] = "$EVENT_OBJECT_CONTENTSCROLLED"
$map[0x7FFFFFFF] = "$EVENT_MAX"

While 1
  Sleep(1000)
WEnd

Func Terminate()
  Exit
EndFunc   ;==>Terminate

Func OnAutoItExit()
  _WinAPI_UnhookWinEvent($hEventHook)
  DllCallbackFree($hEventProc)
EndFunc   ;==>OnAutoItExit

Func _EventProc($hEventHook, $iEvent, $hWnd, $iObjectID, $iChildID, $iThreadId, $iEventTime)
    ConsoleWrite(($map[$iEvent] ? $map[$iEvent] : "0x" & hex($iEvent, 8)) & " | " & $iObjectID & " | " & $iChildID & " | " & $iThreadId & " | " & $iEventTime & @CRLF)
EndFunc   ;==>_EventProc

 

 

Edited by VAN0
Link to comment
Share on other sites

  • Solution

This should work.

#include <WinAPI.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <ScreenCapture.au3>

HotKeySet("{ESC}", "_Exit") ; Exit


Global $hHookFunc = DllCallbackRegister('_WinEventProc', 'none', 'ptr;uint;hwnd;int;int;uint;uint')
Global $hWinHook = _WinAPI_SetWinEventHook($EVENT_OBJECT_CREATE, $EVENT_OBJECT_CREATE, DllCallbackGetPtr($hHookFunc))


While Sleep(30)

WEnd


Func _Exit()
    _Free()
    Exit
EndFunc   ;==>_Exit

Func _Free()
    If $hWinHook Then _WinAPI_UnhookWinEvent($hWinHook)
    If $hHookFunc Then DllCallbackFree($hHookFunc)
EndFunc   ;==>_Free


Func _WinEventProc($hHook, $iEvent, $hWnd, $iObjectID, $iChildID, $iEventThread, $imsEventTime)

    If WinGetTitle($hWnd) = "VCarve Pro" Then
        ConsoleWrite(WinGetTitle($hWnd) & @CRLF)
        ConsoleWrite(_WinAPI_GetWindowFileName($hWnd) & @CRLF)
    EndIf

EndFunc   ;==>_WinEventProc

 

 

Saludos

Link to comment
Share on other sites

1 hour ago, VAN0 said:

0x7FFFFF30 It seems to only be triggered when something major happened

Interesting.  And the value of $hWnd, does it correspond to the popup windows ?  If so, you got yourself a winner.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...