EjnarH Posted October 15, 2007 Share Posted October 15, 2007 Hi, Is there some smart way to create a tray-icon program, which will only react whenever a new window is created ? The program must use no or little CPU while not active. Have a nice day! Ejnar. Link to comment Share on other sites More sharing options...
ValeryVal Posted October 15, 2007 Share Posted October 15, 2007 You can take this code as basic to hook window creation #include <GUIConstantsEx.au3> #include "DllCallBack.au3" Global Const $WH_MOUSE = 0x7 Global $hMouseHook, $pStub_MouseProc, $hWnd_ui $dwThread = DllCall("kernel32.dll", "dword", "GetCurrentThreadId") $dwThread = $dwThread[0] $pStub_MouseProc = _DllCallBack ("_MouseProc", "int;ptr;ptr") $hMouseHook = DllCall("user32.dll", "ptr", "SetWindowsHookEx", "int", $WH_MOUSE, "ptr", $pStub_MouseProc, "ptr", 0, "dword", $dwThread) $hMouseHook = $hMouseHook[0] $hWnd_ui = GUICreate("") GUISetState() While 1 If $GUI_EVENT_CLOSE = GUIGetMsg() Then DllCall("user32.dll", "int", "UnhookWindowsHookEx", "ptr", $hMouseHook) _DllCallBack_Free ($pStub_MouseProc) Exit EndIf Sleep(10) WEnd Func _MouseProc($nCode, $wParam, $lParam) If $nCode < 0 Then Return _CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) $vMHS = DllStructCreate("long;long;hwnd;uint;dword;dword", $lParam) WinSetTitle($hWnd_ui, "", "X: " & DllStructGetData($vMHS, 1) & " Y: " & DllStructGetData($vMHS, 2) & " HitTest: " & DllStructGetData($vMHS, 4)) Return 0 EndFunc ;==>_MouseProc Func _CallNextHookEx($hhk, $nCode, $wParam, $lParam) Local $aTmp = DllCall("user32.dll", "long", "CallNextHookEx", "ptr", $hhk, "int", $nCode, "ptr", $wParam, "ptr", $lParam) Return $aTmp[0] EndFunc ;==>_CallNextHookEx However you need $WH_CBT = 5 instead of $WH_MOUSE. And your hook procedure have to have the filter for HCBT_CREATEWND = 3 code. The point of world view Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now