Sign in to follow this  
Followers 0
Saddle

Detect window creation using callback hook

9 posts in this topic

Is there a way of detecting the creation of a class of window without looping (with while 1 and sleep).

I'd like to detect the presence of a window immediately (without sleep pauses in a loop). Is there a callback (hook) available that can be used? WINWAIT is another way of doing it, but I'd like to be doing other things at the same time (this is part of another program).

I want to use this to freeze a system prompt window on the screen for at least 5 seconds before allowing the user to answer the question (pressing enter or clicking Yes/No buttons). The prompting dialog is not from of my program, it's from the OpSys.

Something like block input, or disable the button controls on the window for that time period. If I use a loop/sleep, there is a chance of hitting the mouse or keyboard before my program knows it's there.

Thanks,

Saddle (In the land of Oz)

"I don't care whether the news is good or bad, I just need it early"

Share this post


Link to post
Share on other sites



Is there a way of detecting the creation of a class of window without looping (with while 1 and sleep).

I'd like to detect the presence of a window immediately (without sleep pauses in a loop). Is there a callback (hook) available that can be used? WINWAIT is another way of doing it, but I'd like to be doing other things at the same time (this is part of another program).

I want to use this to freeze a system prompt window on the screen for at least 5 seconds before allowing the user to answer the question (pressing enter or clicking Yes/No buttons). The prompting dialog is not from of my program, it's from the OpSys.

Something like block input, or disable the button controls on the window for that time period. If I use a loop/sleep, there is a chance of hitting the mouse or keyboard before my program knows it's there.

Thanks,

Saddle (In the land of Oz)

"I don't care whether the news is good or bad, I just need it early"

you can hook global window or dialog creation events with

SetWinEventHook API

or

RegisterShellHookWindow API

Siao and Rasim have example of each on the forum

works very well, no external dll needed

once the event message occurs you could suspend the target process

that would freeze the dialog until you resumed the process.

good luck


I see fascists...

Share this post


Link to post
Share on other sites

Siao and Rasim have example of each on the forum

works very well, no external dll needed

Thankyou for the reply. I found ShellHookwindow.au3 from Siao, studied and ran it. It seems to hook all the normal windows but does not register any for 32770 class dialogs. Is there some difference for child window creation for this class by the system compared to the others. Example : rename a file extension in Windows explorer causes a dialog to appear, but no message about the dialog window creation is passed on.

I searched for other examples of SetWinEventHook, but the forum search didn't hit these properly (or I'm doing something wrong there).

You offered to demo one up for Stampy on a message box capture here, could you post one here (Yes please)?

Thanks.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Siao and Rasim have example of each on the forum

works very well, no external dll needed

Thankyou for the reply. I found ShellHookwindow.au3 from Siao, studied and ran it. It seems to hook all the normal windows but does not register any for 32770 class dialogs. Is there some difference for child window creation for this class by the system compared to the others. Example : rename a file extension in Windows explorer causes a dialog to appear, but no message about the dialog window creation is passed on.

I searched for other examples of SetWinEventHook, but the forum search didn't hit these properly (or I'm doing something wrong there).

You offered to demo one up for Stampy on a message box capture here, could you post one here (Yes please)?

Thanks.

you missed the Rasim example for SetWinEventHook: WinTray.au3

dialogs can be monitored using a SetWinEventHook event

you can monitor start and end of a dialog

this hook testing example from my snippets collection

is set to monitor for dialogs from a specified process name

Edit: handle and event thread are the only usable params for verifying a dialog close event

removed unused options

#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Process.au3>
#include <Misc.au3>

Opt("MustDeclareVars", 1)

Global $hLasthWnd, $hDLL, $hWinEventProc, $hHook, $sCol = ""
_Singleton("DialogHookDemo", 0)

HotKeySet("{ESC}", "_HotKey") ; Exit
HotKeySet("{F9}", "_HotKey") ; Start/Stop dialog box monitoring

Global Const $DWL_DLGPROC = 4
Global Const $DWL_MSGRESULT = 0
Global Const $DWL_USER = 8

Global Const $EVENT_SYSTEM_DIALOGSTART = 0x10 ; 16 - #32770 dialog box class
Global Const $EVENT_SYSTEM_DIALOGEND = 0x11 ; 17

;limit monitoring to specific process
Global $sProcessName = "explorer.exe"

MsgPrint("Press F9 to start/stop monitoring, ESC to exit" & @CRLF)

While 1
    Sleep(1000) ; if using GuiOnEventMode or replace with your GuiGetMsg() handler
WEnd

Func _WinEventProc($hHook, $iEvent, $hWnd, $idObject, $idChild, $iEventThread, $iEventTime)
    Local $PID = WinGetProcess($hWnd), $sEventProcName = _ProcessGetName($PID)

    If ($sEventProcName = $sProcessName) And ($iEvent = $EVENT_SYSTEM_DIALOGSTART) Then $hLasthWnd = $hWnd ;if my process then set $hLasthWnd
    If $sEventProcName <> $sProcessName And Number($hLasthWnd) <> Number($hWnd) Then Return
    If Number($hLasthWnd) = Number($hWnd) And $iEvent = $EVENT_SYSTEM_DIALOGEND Then
        $sCol = "-"
        MsgPrint("Dialog Closed for process: " & $sProcessName)
    EndIf
    
    Local $h_ROOTOWNER = _WinAPI_GetAncestor($hWnd, $GA_ROOTOWNER)
    If $iEvent = 16 Then
        $sCol = "+"
        MsgPrint("DIALOGSTART")
    Else
        $sCol = "!"
        MsgPrint("DIALOGEND")
    EndIf
    
    ;MsgPrint("GWL_STYLE...............: " & "0x" & Hex(_WinAPI_GetWindowLong($hWnd, $GWL_STYLE )))   ; dialog styles
    ;MsgPrint("GWL_EXSTYLE.............: " & "0x" & Hex(_WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE)))  ; dialog extended styles
    ;MsgPrint("GWL_ID..................: " & _WinAPI_GetWindowLong($hWnd, $GWL_ID)) ; not used
    ;MsgPrint("GWL_USERDATA............: " & "0x" & Hex(_WinAPI_GetWindowLong($hWnd, $GWL_USERDATA)))
    MsgPrint("DWL_DLGPROC..............: " & "0x" & Hex(_WinAPI_GetWindowLong($hWnd, $DWL_DLGPROC)))
    MsgPrint("DWL_MSGRESULT............: " & "0x" & Hex(_WinAPI_GetWindowLong($hWnd, $DWL_MSGRESULT)))
    MsgPrint("DWL_USER.................: " & "0x" & Hex(_WinAPI_GetWindowLong($hWnd, $DWL_USER)))
    
    MsgPrint("")
    MsgPrint("$hWnd...................: " & $hWnd)
    MsgPrint("Class ..................: " & _WinAPI_GetClassName($hWnd))
    MsgPrint("Title...................: " & WinGetTitle($hWnd) & @CRLF)
    
    MsgPrint("$hWnd RootOwner.........: " & $h_ROOTOWNER)
    MsgPrint("Parent Class ...........: " & _WinAPI_GetClassName($h_ROOTOWNER))
    MsgPrint("TitleRootOwner .........: " & WinGetTitle($h_ROOTOWNER) & @CRLF)

    MsgPrint("$iEventThread...........: " & $iEventThread)
    MsgPrint("OwnerThreadProcessPID ..: " & $PID)
    MsgPrint("OwnerThreadProcessName .: " & $sEventProcName)
    MsgPrint("$iEvent.................: " & $iEvent & @CRLF)
EndFunc   ;==>_WinEventProc

Func _SetWinEventHook($iEventMin, $iEventMax, $hDLLUser32 = -1)
    ;http://msdn.microsoft.com/en-us/library/ms696160.aspx
    ;Author: rasim (from WinTray.au3)
    Local $aRet
    Local Const $WINEVENT_OUTOFCONTEXT = 0x0
    Local Const $WINEVENT_SKIPOWNPROCESS = 0x2
    If Not $hDLLUser32 Or $hDLLUser32 = -1 Then $hDLLUser32 = "User32.dll"
    $aRet = DllCall($hDLLUser32, "hwnd", "SetWinEventHook", _
            "uint", $iEventMin, "uint", $iEventMax, "hwnd", 0, _
            "ptr", DllCallbackGetPtr($hWinEventProc), "int", 0, _
            "int", 0, "uint", BitOR($WINEVENT_OUTOFCONTEXT, $WINEVENT_SKIPOWNPROCESS))
    If @error Then Return SetError(@error, 0, 0)
    Return $aRet[0]
EndFunc   ;==>_SetWinEventHook

Func MsgPrint($sText);, $sCol = ">"
    ConsoleWrite($sCol & " " & $sText & @CRLF)
EndFunc   ;==>MsgPrint

Func _HotKey()
    Switch @HotKeyPressed
        Case "{F9}"
            If Not $hDLL Then ;; Start dialog monitoring
                $hDLL = DllOpen("User32.dll")
                If Not $hDLL Then Return ConsoleWrite("DllOpen('User32.dll') failed - Error: " & @error & @CRLF)
                $hWinEventProc = DllCallbackRegister("_WinEventProc", "none", "hwnd;int;hwnd;long;long;int;int")
                If Not $hWinEventProc Then
                    ConsoleWrite("DllCallbackRegister() failed - Error: " & @error & @CRLF)
                    DllClose($hDLL)
                    $hDLL = 0
                    Return 0
                EndIf
                $hHook = _SetWinEventHook($EVENT_SYSTEM_DIALOGSTART, $EVENT_SYSTEM_DIALOGEND, $hDLL)
                If Not $hHook Then
                    ConsoleWrite("_SetWinEventHook failed - Error: " & @error & @CRLF)
                    DllCallbackFree($hWinEventProc)
                    DllClose($hDLL)
                    $hDLL = 0
                EndIf
                $sCol = "+"
                MsgPrint("Dialog Monitoring - Started" & @CRLF)
                Beep(2000, 5)
            Else ;; Stop dialog monitoring
                DllCallbackFree($hWinEventProc)
                DllCall($hDLL, "int", "UnhookWinEvent", "hwnd", $hHook)
                DllClose($hDLL)
                $hDLL = 0
                Beep(1000, 5)
                $sCol = "!"
                MsgPrint("Dialog Monitoring - Stopped" & @CRLF)
            EndIf
        Case "{ESC}"
            Exit
    EndSwitch
EndFunc   ;==>_HotKey

Func OnAutoItExit()
    If $hWinEventProc Then
        Beep(3000, 5)
        DllCallbackFree($hWinEventProc)
        MsgPrint("Dialog Monitoring - Stopped")
    EndIf
    If $hHook Then DllCall("User32.dll", "int", "UnhookWinEvent", "hwnd", $hHook)
    If $hDLL Then DllClose($hDLL)
EndFunc   ;==>OnAutoItExit
Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites

Is there a way of detecting the creation of a class of window without looping (with while 1 and sleep).

Hi Saddle

Maybe You are thinking too complicated. What about AdlibEnable? See example in Helpfile.

dowido

Share this post


Link to post
Share on other sites

Hi Saddle

Maybe You are thinking too complicated. What about AdlibEnable? See example in Helpfile.

dowido

Thanks for the reply. I have thought about it and I was hesitant becuase I do not know how fast (or CPU load) a window search takes when a particular class is hunted for. About what % of 250msec for CPUs. Are you able to change the millisec timeout originally set in AdLibEnable from within the callback routine?

Also,

The above hook example doesn't find new modal windows (I hope I'm using that term correctly here) from the OpSys. Eg : Dialog that pops up asking whether you want to change a file extension to a different type, does not trigger the window hook.

Under Vista, the OpSys dialog text is also not visible. Is there a way of reading it without trying to stuff it into the clipboard first?

Thanks,

Saddle (In the land of Oz)

"Whoohoo, now there's a belly full of instant sunshine!" - Tourist in Melbourne watching film of B1.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thanks for the reply. I have thought about it and I was hesitant becuase I do not know how fast (or CPU load) a window search takes when a particular class is hunted for. About what % of 250msec for CPUs. Are you able to change the millisec timeout originally set in AdLibEnable from within the callback routine?

Also,

The above hook example doesn't find new modal windows (I hope I'm using that term correctly here) from the OpSys. Eg : Dialog that pops up asking whether you want to change a file extension to a different type, does not trigger the window hook.

Under Vista, the OpSys dialog text is also not visible. Is there a way of reading it without trying to stuff it into the clipboard first?

Thanks,

Saddle (In the land of Oz)

"Whoohoo, now there's a belly full of instant sunshine!" - Tourist in Melbourne watching film of B1.

Saddle

can you elaborate further on "OpSys dialog text is also not visible"

what dialog?, what text?

the example was tested on Win2K, XP and Vista

the example writes to console only and does detect the above mentioned rename dialog and the start menu Run dialog etc.

start with F9 and run in SciTE or another IDE with a console window or compiled as a CUI app

don't know what problem you have with it, OS? AutoIt version?

I found a problem with other #32770 dialogs that are consistently not detected (add a printer, etc).

I use foreground and object events so haven't put dialog event through any testing

and its been awhile since I read the events constants MSDN page

From MSDN

http://msdn.microsoft.com/en-us/library/ms697187.aspx

http://msdn.microsoft.com/en-us/library/dd318066(VS.85).aspx

EVENT_SYSTEM_DIALOGSTART, EVENT_SYSTEM_DIALOGEND

"This event is not sent consistently by the system. This is a known issue and is being addressed."

so it's as good as useless, still doesn't detect some #32770 dialogs in Vista either

I switched the example to object or foreground window detect

foreground event only occurs once with a window becoming topmost

disables Run or Rename dialogs for 5 seconds with control graying, title renaming and window flash

try this

;Detect foreground windows with SetWinEventHook
;Author; rover 04/17/09
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Process.au3>
#include <Misc.au3>

Opt("MustDeclareVars", 1)

Global $hLasthWnd, $hDLL, $hWinEventProc, $hHook
_Singleton("DialogHookDemo", 0)

HotKeySet("{ESC}", "_HotKey") ; Exit
HotKeySet("{F9}", "_HotKey")  ; Start/Stop dialog box monitoring

Global Const $DWL_DLGPROC = 4
Global Const $DWL_MSGRESULT = 0
Global Const $DWL_USER = 8

;Event Constants
;http://msdn.microsoft.com/en-us/library/ms697187.aspx
;http://msdn.microsoft.com/en-us/library/dd318066(VS.85).aspx
;http://mwinapi.sourceforge.net/doc/html/T_ManagedWinapi_Accessibility_AccessibleEventType.htm
Global Const $EVENT_SYSTEM_FOREGROUND = 0x3
Global Const $EVENT_SYSTEM_MENUSTART = 0x4
Global Const $EVENT_SYSTEM_MENUEND = 0x5
Global Const $EVENT_SYSTEM_MENUPOPUPSTART = 0x6
Global Const $EVENT_SYSTEM_MENUPOPUPEND = 0x7
Global Const $EVENT_SYSTEM_DIALOGEND = 0x11 ; #32770 dialog box class
Global Const $EVENT_SYSTEM_DIALOGSTART = 0x10 ; #32770 dialog box class
Global Const $EVENT_OBJECT_CREATE = 0x8000
Global Const $EVENT_OBJECT_DESTROY = 0x8001
Global Const $EVENT_OBJECT_SHOW = 0x8002

;probably best to use SYSTEM_FOREGROUND as OBJECT_CREATE will trigger far more frequently
;even with additional filtering in _WinEventProc

;minimum and maximum events
;to monitor one event type only use same event for min/max
Global $Event_Min = $EVENT_SYSTEM_FOREGROUND ; $EVENT_OBJECT_CREATE
Global $Event_Max = $EVENT_SYSTEM_FOREGROUND ; $EVENT_OBJECT_CREATE ; $EVENT_OBJECT_DESTROY

;disables Yes/No buttons on Rename file extension dialog for 5 seconds
;or disable Run dialog
;Global $sWinTitle = "Run"
Global $sWinTitle = "Rename"

ConsoleWrite("! Press F9 to start/stop monitoring, ESC to exit" & @CRLF)

While 1
    Sleep(1000)
WEnd

Func _WinEventProc($hHook, $iEvent, $hWnd, $idObject, $idChild, $iEventThread, $iEventTime)
    ;If $idObject <> 0 Or $iEvent <> $Event_Min Then Return ;Global Const $OBJID_WINDOW = 0x0
    If StringCompare(WinGetTitle($hWnd), $sWinTitle) <> 0 Then Return
    Local $sTitle = WinGetTitle($hWnd)
    WinSetTitle($hWnd, "", $sTitle & " - Disabled for 5 Seconds")
    WinSetState($hWnd, "", @SW_DISABLE) ; will disable dialog and titlebar close button
    ControlDisable($hWnd, "", "[CLASS:Button; INSTANCE:1]") ;show change in dialog by greying buttons
    ControlDisable($hWnd, "", "[CLASS:Button; INSTANCE:2]")
    WinFlash($hWnd, "", 5, 500) ;further indication by flashing title and titlebar close button
    ;Sleep(5000)
    ControlEnable($hWnd, "", "[CLASS:Button; INSTANCE:1]")
    ControlEnable($hWnd, "", "[CLASS:Button; INSTANCE:2]")
    WinSetTitle($hWnd, "", $sTitle)
    WinSetState($hWnd, "", @SW_ENABLE)
EndFunc   ;==>_WinEventProc

Func _SetWinEventHook($iEventMin, $iEventMax, $hDLLUser32 = -1)
    ;http://msdn.microsoft.com/en-us/library/ms696160.aspx
    ;Author: rasim (from WinTray.au3)
    Local $aRet
    Local Const $WINEVENT_OUTOFCONTEXT = 0x0
    Local Const $WINEVENT_SKIPOWNPROCESS = 0x2
    If Not $hDLLUser32 Or $hDLLUser32 = -1 Then $hDLLUser32 = "User32.dll"
    $aRet = DllCall($hDLLUser32, "hwnd", "SetWinEventHook", _
            "uint", $iEventMin, "uint", $iEventMax, "hwnd", 0, _
            "ptr", DllCallbackGetPtr($hWinEventProc), "int", 0, _
            "int", 0, "uint", BitOR($WINEVENT_OUTOFCONTEXT, $WINEVENT_SKIPOWNPROCESS))
    If @error Then Return SetError(@error, 0, 0)
    Return $aRet[0]
EndFunc   ;==>_SetWinEventHook

Func _HotKey()
    Switch @HotKeyPressed
        Case "{F9}"
            If Not $hDLL Then ;; Start dialog monitoring
                $hDLL = DllOpen("User32.dll")
                If Not $hDLL Then Return ConsoleWrite("DllOpen('User32.dll') failed - Error: " & @error & @CRLF)
                $hWinEventProc = DllCallbackRegister("_WinEventProc", "none", "hwnd;int;hwnd;long;long;int;int")
                If Not $hWinEventProc Then
                    ConsoleWrite("DllCallbackRegister() failed - Error: " & @error & @CRLF)
                    DllClose($hDLL)
                    $hDLL = 0
                    Return 0
                EndIf
                $hHook = _SetWinEventHook($Event_Min, $Event_Max, $hDLL)
                If Not $hHook Then
                    ConsoleWrite("_SetWinEventHook failed - Error: " & @error & @CRLF)
                    DllCallbackFree($hWinEventProc)
                    DllClose($hDLL)
                    $hDLL = 0
                EndIf
                ConsoleWrite("+ Dialog Monitoring - Started" & @CRLF)
                Beep(2000, 5)
            Else ;; Stop dialog monitoring
                DllCallbackFree($hWinEventProc)
                DllCall($hDLL, "int", "UnhookWinEvent", "hwnd", $hHook)
                DllClose($hDLL)
                $hDLL = 0
                Beep(1000, 5)
                ConsoleWrite("! Dialog Monitoring - Stopped" & @CRLF)
            EndIf
        Case "{ESC}"
            Exit
    EndSwitch
EndFunc   ;==>_HotKey

Func OnAutoItExit()
    If $hWinEventProc Then
        Beep(3000, 5)
        DllCallbackFree($hWinEventProc)
        ConsoleWrite("! Dialog Monitoring - Stopped")
    EndIf
    If $hHook Then DllCall("User32.dll", "int", "UnhookWinEvent", "hwnd", $hHook)
    If $hDLL Then DllClose($hDLL)
EndFunc   ;==>OnAutoItExit
Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites

Saddle

can you elaborate further on "OpSys dialog text is also not visible"

what dialog?, what text?

the example was tested on Win2K, XP and Vista

the example writes to console only and does detect the above mentioned rename dialog and the start menu Run dialog etc.

start with F9 and run in SciTE or another IDE with a console window or compiled as a CUI app

don't know what problem you have with it, OS? AutoIt version?

I found a problem with other #32770 dialogs that are consistently not detected (add a printer, etc).

I use foreground and object events so haven't put dialog event through any testing

and its been awhile since I read the events constants MSDN page

From MSDN

http://msdn.microsoft.com/en-us/library/ms697187.aspx

http://msdn.microsoft.com/en-us/library/dd318066(VS.85).aspx

EVENT_SYSTEM_DIALOGSTART, EVENT_SYSTEM_DIALOGEND

"This event is not sent consistently by the system. This is a known issue and is being addressed."

so it's as good as useless, still doesn't detect some #32770 dialogs in Vista either

I switched the example to object or foreground window detect

foreground event only occurs once with a window becoming topmost

disables Run or Rename dialogs for 5 seconds with control graying, title renaming and window flash

Thankyou for the reply. I am off to study it now, looks exactly what I've been hunting for/trying to write for the detection side, but still not sure regards dialog text.

Answers to questions asked:

OpSys - Vista Ultimate.

AutoIt version 2 days old (not sure where to get version from as it runs in Scite ide).

Rename any file and study the rename dialog with Auto Window Info V3 and it does not report any visible text in the Rename dialog poped up by explorer.

post-12203-1240032852_thumb.jpg

=========================================

>>>> Window <<<<

Title: Rename

Class: #32770

Position: 288, 280

Size: 432, 152

Style: 0x96C00284

ExStyle: 0x00010101

Handle: 0x00050360

>>>> Control <<<<

Class: DirectUIHWND

Instance: 1

ClassnameNN: DirectUIHWND1

Advanced (Class): [CLASS:DirectUIHWND; INSTANCE:1]

ID:

Text:

Position: 0, 0

Size: 416, 116

ControlClick Coords: 304, 47

Style: 0x56000000

ExStyle: 0x00000000

Handle: 0x00050376

>>>> Mouse <<<<

Position: 600, 355

Cursor ID: 2

Color: 0xFFFFFF

>>>> StatusBar <<<<

>>>> Visible Text <<<<

&Yes

&No

>>>> Hidden Text <<<<

=========================================

Share this post


Link to post
Share on other sites

o.k., so that dialog in Vista uses windowless controls class DirectUIHWND like MSN chat does

I use XP and only visit Vista (nice place, wouldn't want to live there) so that issue didn't click with me

now I get the reference in your previous post to the clipboard (using Send ctrl-c to copy text to clipboard)

IE functions were mentioned in this thread as a solution

http://www.autoitscript.com/forum/index.php?showtopic=90569

another method for reading text from DirectUIHWND involves MSAA - Microsoft Active Accessibility

the hook event function has support for COM accessibility

months ago I tested the CoInitializeEx/AccessibleObjectFromEvent APIs in an event hook

and had returned pointers for window events, but I don't think its possible to proceed any further with that

as you can't return an IAccessible object with DllCall here in AutoIt 'Flat API Land' (apologies to Edwin A. Abbott http://en.wikipedia.org/wiki/Flatland)

as the managed code examples I found through Google show.

I have no idea how to work with this.

maybe someone else does.

excluding the constants and CoUinitialize on exit

these are the functions

Func AccessibleObjectFromEvent($hWnd, $dwObjectID, $dwChildID)
    ;Local Const $E_INVALIDARG = 0x80070057
    Local $aRet = DllCall("Oleacc.dll", "int", "AccessibleObjectFromEvent", _
                                        "hwnd", $hWnd, _
                                        "long", $dwObjectID, _
                                        "long", $dwChildID, _
                                        "ptr*", 0, _ ;$ppacc
                                        "int*", 0) ;$ivarChild
    Return $aRet
EndFunc

Func _SetWinEventHook($iEventMin, $iEventMax, $Debug = False)
    ;http://msdn.microsoft.com/en-us/library/ms696160.aspx
    ;Author: rasim (from WinTray.au3)
    Local $aRet
    Local Const $WINEVENT_OUTOFCONTEXT   = 0x0
    Local Const $WINEVENT_SKIPOWNPROCESS = 0x2

    $aRet = DllCall('ole32.dll', 'long', 'CoInitializeEx', 'int', 0, 'long', $COINIT_APARTMENTTHREADED)
    Switch $aRet[0]
        Case $S_OK
            If $Debug Then MsgPrint("The COM library was initialized successfully on the calling thread.")
        Case $S_FALSE
            If $Debug Then MsgPrint("The COM library is already initialized on the calling thread.")
        Case $RPC_E_CHANGED_MODE
            If $Debug Then MsgPrint("A previous call to CoInitializeEx specified a different concurrency model for the calling thread," & @LF & _
                    "-->or the thread that called CoInitializeEx currently belongs to the neutral threaded apartment.")
        Case $E_INVALIDARG
            If $Debug Then MsgPrint("Invalid Arg")
        Case $E_OUTOFMEMORY
            If $Debug Then MsgPrint("Out of memory")
        Case $E_UNEXPECTED
            If $Debug Then MsgPrint("Unexpected error")
    EndSwitch
    
    $aRet = DllCall("User32.dll", "hwnd", "SetWinEventHook", _ ;639
                                    "uint", $iEventMin, _
                                    "uint", $iEventMax, _
                                    "hwnd", 0, _
                                    "ptr", DllCallbackGetPtr($hWinEventProc), _
                                    "int", 0, _
                                    "int", 0, _
                                    "uint", BitOR($WINEVENT_OUTOFCONTEXT, $WINEVENT_SKIPOWNPROCESS))
    Return $aRet[0]
EndFunc   ;==>_SetWinEventHook

I see fascists...

Share this post


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
Sign in to follow this  
Followers 0