
Seminko
-
Posts
371 -
Joined
-
Last visited
Reputation Activity
-
Seminko reacted to Andreik in Hold down Hotkey without repeating assigned function
#include <WindowsConstants.au3> #include <WinAPISys.au3> #include <WinAPIConstants.au3> Global $KeyDown = False ; Register a hotkey to exit the program HotKeySet('{ESC}', 'Quit') ; Set a low level keyboard hook ; KeyboardProc it's a callback function that it's called when keyboard events occurs $hKeyboardProc = DllCallbackRegister('KeyboardProc', 'long', 'int;wparam;lparam') $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hKeyboardProc), _WinAPI_GetModuleHandle(0)) Do ; We process the messsage here because it's a good practice to return from ; the callback function as soon as possible and without using any blocking functions If $KeyDown Then ConsoleWrite('= was pressed' & @CRLF) Do ConsoleWrite('= is still pressed' & @CRLF) Sleep(10) Until Not $KeyDown ConsoleWrite('= was released' & @CRLF) EndIf Sleep(10) Until $bExit ; Unset the keyboard hook _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hKeyboardProc) Func KeyboardProc($nCode, $wParam, $lParam) ; If nCode is less than zero just call the next hook procedure in the current hook chain If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) ; Create a structure that will contain info about the keyboard event ; (lParam it's the pointer to the KBDLLHOOKSTRUCT structure) Local $tKEYHOOKS = DllStructCreate('dword vkCode;dword scanCode;dword flags;dword time;ulong_ptr dwExtraInfo', $lParam) ; wParam contains the identifier of the keyboard message Switch $wParam Case $WM_KEYDOWN ; When = key it's pressed ; set $KeyDown to true, so you don't have to process anything else in the callback function If $tKEYHOOKS.vkCode = 0xBB Then $KeyDown = True ; Return nonzero value to prevent the system from passing the ; message to the rest of the hook chain or the target window procedure Return 1 EndIf Case $WM_KEYUP ; When = key it's released ; set $KeyDown to false, so you don't have to process anything else in the callback function If $tKEYHOOKS.vkCode = 0xBB Then $KeyDown = False ; Return nonzero value to prevent the system from passing the ; message to the rest of the hook chain or the target window procedure Return 1 EndIf EndSwitch ; Call the next hook procedure in the current hook chain Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc Func Quit() $bExit = True EndFunc You can read all this stuff in more details here, here and here.
-
Seminko reacted to Nine in ControlClick tray icon context menu
Here how you can do it (used Bluetooth as an example):
#NoTrayIcon #include <Constants.au3> #Include <GuiToolBar.au3> _Systray_Hidden () ConsoleWrite ("Error = " & @error & @CRLF) Func _Systray_Hidden () Local $hWnd = WinGetHandle ('[Class:Shell_TrayWnd]') If Not $hWnd Then Return SetError (1) Local $hCtrl = ControlGetHandle($hWnd, "", "Button2") If Not $hCtrl Then Return SetError (2) ControlClick ($hWnd, "", $hCtrl) Sleep (600) $hWnd = WinGetHandle ('[Class:NotifyIconOverflowWindow]') Local $hSysTray = ControlGetHandle($hWnd, '', "ToolbarWindow321") If Not $hSysTray Then Return SetError (3) Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray) If Not $iSystray_ButCount Then Return SetError (4) For $i = 0 To $iSystray_ButCount-1 ConsoleWrite (_GUICtrlToolbar_GetButtonText($hSysTray, $i) & @CRLF) If StringInStr (_GUICtrlToolbar_GetButtonText($hSysTray, $i), "BlueTooth") Then _GUICtrlToolbar_ClickButton($hSysTray, $i, "left") Sleep (850) ControlSend("[CLASS:#32768]","","","{UP 2}{ENTER}") Return 1 EndIf Next Return SetError (5) EndFunc There shouldn't be more than 1 button without text.
If you need more control, use UIAutomation.
-
Seminko reacted to Jos in #AutoIt3Wrapper_UseX64=Y not working when running script outside SciTE - SQLite3_x64
Let me guess: The .au3 file extension defaults to AutoIt3.exe in stead of the required AutoIt3_x64.exe?
A Shortcut does contain a commandline, which in this case should point to the proper AutoIt3 version executable.
Jos
-
Seminko reacted to KaFu in SSD - Set Sound Device [Updated 2017-Sep-16]
SSD - Set Sound Device
Current Version: v4 (2017-Sep-15)
Windows XP allows you to output sound to more than one audio device... Vista and newer Windows versions do not. To overcome this "Failure by Design", (IMHO somehow related to DRM, preventing user to make digital copies of analog sources), I have coded SSD - Set Sound Device.
SSD enables you to change the default Sound Device by shortcut or command line.
It works fine on my Win10-1703 64bit machine. If you find bugs please let me know.
The source and executable can be downloaded from my site: http://www.funk.eu
Kudos to Ascend4nt and NerdFencer for parts of the code, and Yashied for his most excellent WinAPIEx UDF.
Enjoy ...
-
Seminko reacted to jchd in _INetGetSource returns only a three character string despite StringLen saying otherwise
I've no idea. Maybe compressed content or a picture or ... who knows?
Browsers know how to handle that but only web gurus can tell.
-
Seminko got a reaction from faustf in regexp help
Not sure if I understood correctly, but from what I gathered you wanted a regex that would return the following, correct?
If that's so, and provided that 'Contenuto del pacco:' string will be on every page you're using the regex for, you can try this:
https://regex101.com/r/JA2SXj/1/
If not, just let me know. I'll look more into it tomorrow. It all depends on the consistency of the inputs.
-
Seminko got a reaction from Earthshine in Set monitor as primary
I love people like you. Going into threads you have no idea about, demanding answers like it's some sort of communist deposition while providing ZERO input, throwing a little fit when called on it, and I'm almost sure, feeling like the other person is the d...
If you don't want to help or you're frustrated by people asking for help, that's absolutely fine --> don't join a thread and jog along.
-
Seminko reacted to Danp2 in ControlSend sends czech characters instead of number
Basically, it's trial & error. I examined the element for attached events. Reviewed these and manually triggered them until I achieved the desired effect. Then implemented that in Autoit.
P.S. I believe in this case that the "change" event would also have worked.
-
Seminko reacted to Danp2 in ControlSend sends czech characters instead of number
The site uses jQuery and it only enables the button under certain conditions. The condition check is called on a keyup event, so the following will trigger the event for you --
$oIE.document.parentwindow.execScript('jQuery("#pass").trigger("keyup");')
-
Seminko got a reaction from edpoguatemala in RGB imgs to CMYK to TIFF
Well, you can always ShellExecute.
$ImageMagickExePath = "C:\Program Files\ImageMagick-6.9.3-Q16\convert.exe" $ImageToReadPath = @ScriptDir & "\message.jpg" $ImageToReadPathResult = @ScriptDir & "\message_result.jpg" ShellExecuteWait($ImageMagickExePath, '"' & $ImageToReadPath & '" -fuzz ' & $Percentage & '% -fill black +opaque "#' & $Coloer & '" -threshold 20% -negate "' & $ImageToReadPathResult & '"', "", "", @SW_HIDE)
-
Seminko got a reaction from edpoguatemala in RGB imgs to CMYK to TIFF
When it comes to image manipulation, I'm a fan of ImageMagick.
-
Seminko got a reaction from svenjatzu in Getting table data from a webpage
Hey fellas,
the time has come to seek your help once more .
#FluffOn
Our company recently had an attendance system build but the developers forgot to add one critical thing - the value of your current overtime.
And as the fiddler that I am I decided to make a tool that would make it possible. I already made and excel version that does that but it requires the user to export an excel file from the site, then open it and then activate the calculation. Which is two steps more than I would like and hence I'm turning to you.
#FluffOff
Basically, there is data in a table on the site which I want to grab. I checked the forums and found this:
#include <IE.au3> #include <Array.au3> $oIE = _IECreate("<a href='http://www.bts.gov/publications/national_transportation_statistics/html/table_01_37.html' class='bbc_url' title='External link' rel='nofollow external'>http://www.bts.gov/publications/national_transportation_statistics/html/table_01_37.html</a>", 0, 0) $oTable = _IETableGetCollection ($oIE) ; Get number of tables $iNumTables = @extended MsgBox(0, "Table Info", "There are " & $iNumTables & " tables on the page") $oTable = _IETableGetCollection ($oIE, $iNumTables-1) ; Get last table $aTableData = _IETableWriteToArray ($oTable) _ArrayDisplay($aTableData) It works great, it shows me how many tables there are and the shows me the contents of the table.
But, my site is a https site ending aspx so I cannot just _IECreate it. So I tried _IEAttach("partial name", "URL").
Now it tells me there is 397 tables on the site :-D How do I find the one I'm looking for?
OK got it:
$oIE = _IEAttach("bpowebtarget", "URL") $oTable = _IETableGetCollection ($oIE) ; Get number of tables $iNumTables = @extended MsgBox(0, "Table Info", "There are " & $iNumTables & " tables on the page") For $i = 1 To $iNumTables+1 $oTable = _IETableGetCollection ($oIE, $i) ; Get last table $aTableData = _IETableWriteToArray ($oTable) _ArrayDisplay($aTableData) Next I'm fine for now, will report back once I get stuck again.
-
-
-
-
Seminko got a reaction from mikell in INetGetSource - login only sometimes
Indeed, here it is:
Global Const $WorkDir = 'C:\curl-7.60.0-win64-mingw\bin' ; PATH TO CURL.EXE ; "FIRST YOU CALL 'CurlInitiate' TO LOG IN AND THEN YOU USE 'CurlThat' THE SAME WAY YOU WOULD USE _INetGetSource" Func CurlInitiate($login, $pass) ; "NAVIGATE TO SIGNIN, SAVE THE COOKIE AND GET THE VERIFICATION TOKEN" $Search = 'curl -c cookie-jar.txt https://www.geocaching.com/account/signin' $iPID = Run(@ComSpec & " /c " & $Search, $WorkDir, @SW_HIDE, 2) ProcessWaitClose($iPID) $sOutput = StdoutRead($iPID) $aToken = StringRegExp($sOutput, '__RequestVerificationToken\s*" type="hidden" value="([^"]+)', 3) If @error Then MsgBox(16, "Error", "Token regex error.") EndIf ; "PASS TOKEN, COOKIE AND YOUR LOGIN INFORMATION TO LOG IN TO THE SITE" $SearchPre = '__RequestVerificationToken=' & $aToken[0] & '&ReturnUrl=/play/search&UsernameOrEmail=' & $login & '&Password=' & $pass ; $Search = 'curl -b cookie-jar.txt -c cookie-jar.txt "https://www.geocaching.com/account/signin" -d "' & $SearchPre & '"' $iPID = Run(@ComSpec & " /c " & $Search, $WorkDir, @SW_HIDE, 2) ProcessWaitClose($iPID) $sOutput = StdoutRead($iPID) ; "READ $sOutput TO CHECK WHETHER LOGIN SUCCEEDED" EndFunc Func CurlThat($sURL) $Search = 'curl -b cookie-jar.txt "' & $sURL & '"' $iPID = Run(@ComSpec & " /c " & $Search, $WorkDir, @SW_HIDE, 2) ProcessWaitClose($iPID) $sOutput = StdoutRead($iPID) Return $sOutput EndFunc
-
Seminko reacted to mikell in INetGetSource - login only sometimes
You also might use Curl (command line way) to authenticate, manage the cookie if needed and get the infos
-
Seminko reacted to Danp2 in [SOLVED] IE - element with an existing ID can't be found
Have you checked to see the the site uses frames?
-
Seminko got a reaction from Skysnake in [SOLVED] --> [SQLite] Load extension
UPDATE:
The issue got solved. I incorrectly compiled the median.dll. It seems that despite me using MinGQ-W64, I somehow messed up the install and the compiled DLL ended up being 32bit (I'm using a 64bit SQLite DLL).
I re-installed MinGQ-W64, recompiled the DLL and it works now.
For all of you having issues with JCHD's SQLiteExtLoad.au3, replace '$g_hDll_SQLite' with '$__g_hDll_SQLite'.
Thanks for you help mr. @user4157124
-
Seminko reacted to AdamUL in [Solved] SQLite - SQLite3.dll Can't be Loaded
You are getting the error due to running 32-bit AutoIt. It needs to be run in as 64-bit. Add the following to the top of your script, and it will work, at least for me it does.
#AutoIt3Wrapper_UseX64=Y ;(Y/N) Use AutoIt3_x64 or Aut2Exe_x64. Default=N #include <SQLite.au3> #include <SQLite.dll.au3> _SQLite_Startup(@ScriptDir & "\Config\sqlite3_x64.dll", False, 1) If @error Then MsgBox(16, "SQLite Error", "SQLite3.dll Can't be Loaded! - " & $__g_hPrintCallback_SQLite & @CRLF & @CRLF & "Exiting application / Zavolej Honzovi") Exit -1 EndIf
Adam
-
Seminko reacted to Danyfirex in Microphone sound enable / disable
Hello. It's Code work correcly for me. anyway here is a mod. let me know if it works for you.
Opt("MustDeclareVars", 1) ; *** SEMINKO ADDED THIS ****** HotKeySet("{F9}", "Mute") ; ***************************** Global Enum $eRender, $eCapture, $eAll, $EDataFlow_enum_count Global Enum $eConsole, $eMultimedia, $eCommunications, $ERole_enum_count Global Const $CLSCTX_INPROC_SERVER = 1 Global Const $E_NOTFOUND = 0x80070490 Global Const $S_OK = 0 Global Const $CLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}" Global Const $IID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}" Global Const $tagIMMDeviceEnumerator = _ "EnumAudioEndpoints hresult(int;dword;ptr*);" & _ "GetDefaultAudioEndpoint hresult(int;int;ptr*);" & _ "GetDevice hresult(wstr;ptr*);" & _ "RegisterEndpointNotificationCallback hresult(ptr);" & _ "UnregisterEndpointNotificationCallback hresult(ptr)" Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}" Global Const $tagIMMDevice = _ "Activate hresult(struct*;dword;ptr;ptr*);" & _ "OpenPropertyStore hresult(dword;ptr*);" & _ "GetId hresult(wstr*);" & _ "GetState hresult(dword*)" Global Const $IID_IDeviceTopology = "{2A07407E-6497-4A18-9787-32F79BD0D98F}" Global Const $tagIDeviceTopology = "GetConnectorCount hresult(int*);GetConnector hresult(int;ptr*);" & _ "GetSubunitCount hresult(int*);GetSubunit hresult(int;ptr*);GetPartById hresult(int,ptr*);GetDeviceId hresult(ptr*);GetSignalPath hresult(ptr;ptr;bool;ptr*)" Global Const $IID_IConnector = "{9c2c4058-23f5-41de-877a-df3af236a09e}" Global Const $tagIConnector = "GetType hresult(ptr*);GetDataFlow hresult(ptr*);ConnectTo hresult(ptr);Disconnect hresult(none);IsConnected hresult(int*);" & _ "GetConnectedTo hresult(ptr*);GetConnectorIdConnectedTo hresult(wstr*);GetDeviceIdConnectedTo hresult(wstr*)" Global Const $IID_IPart = "{AE2DE0E4-5BCA-4F2D-AA46-5D13F8FDB3A9}" Global Const $tagIPart = "GetName hresult(wstr*);GetLocalId hresult(uint*);GetGlobalId hresult(wstr*);GetPartType hresult(ptr);GetSubType hresult(ptr);" & _ "GetControlInterfaceCount hresult(uint*);GetControlInterface hresult(int;ptr*);EnumPartsIncoming hresult(ptr*);EnumPartsOutgoing hresult(ptr*);" & _ "GetTopologyObject hresult(ptr*);Activate hresult(dword;struct*;ptr*);RegisterControlChangeCallback hresult(ptr);UnregisterControlChangeCallback hresult(ptr)" Global Const $IID_IPartsList = "{6DAA848C-5EB0-45CC-AEA5-998A2CDA1FFB}" Global Const $tagIPartsList = "GetCount hresult(uint*);GetPart hreuslt(uint;ptr*)" Global Const $IID_IAudioMute = "{DF45AEEA-B74A-4B6B-AFAD-2366B6AA012E}" Global Const $tagIAudioMute = "SetMute hresult(bool;ptr);GetMute hresult(int*)" ; *** SEMINKO ADDED THIS ****** While 1 Sleep(250) WEnd ; ***************************** Func MUTE() Local $hr = -1 Local $oMMDeviceEnumerator = ObjCreateInterface($CLSID_MMDeviceEnumerator, $IID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator) If @error Then ConsoleWrite("!Error Creating IMMDeviceEnumerator Interface" & @CRLF) Exit EndIf Local $pDevice = 0 $hr = $oMMDeviceEnumerator.GetDefaultAudioEndpoint($eRender, $eConsole, $pDevice) If FAILED($hr) Then ConsoleWrite("!Error Getting Default Render Endpoint Device" & @CRLF) $oMMDeviceEnumerator = 0 Exit EndIf Local $oMMDevice = ObjCreateInterface($pDevice, $IID_IMMDevice, $tagIMMDevice) If @error Then ConsoleWrite("!Error Creating IMMDevice Interface" & @CRLF) $oMMDeviceEnumerator = 0 Exit EndIf Local $pDeviceTopology = 0 $hr = $oMMDevice.Activate(__uuidof($IID_IDeviceTopology), $CLSCTX_INPROC_SERVER, 0, $pDeviceTopology) If FAILED($hr) Then ConsoleWrite("!Error Getting Device Topology" & @CRLF) $oMMDeviceEnumerator = 0 $oMMDevice = 0 Exit EndIf Local $oDeviceTopology = ObjCreateInterface($pDeviceTopology, $IID_IDeviceTopology, $tagIDeviceTopology) If @error Then ConsoleWrite("!Error Creating IDeviceTopology Interface" & @CRLF) $oMMDeviceEnumerator = 0 $oMMDevice = 0 Exit EndIf Local $pConnEndpoint = 0 $hr = $oDeviceTopology.GetConnector(0, $pConnEndpoint) If FAILED($hr) Then ConsoleWrite("!Error Getting endpoint Connector" & @CRLF) $oMMDeviceEnumerator = 0 $oMMDevice = 0 $oDeviceTopology = 0 Exit EndIf Local $oIConnector = ObjCreateInterface($pConnEndpoint, $IID_IConnector, $tagIConnector) If @error Then ConsoleWrite("!Error Creating IConnector Interface" & @CRLF) $oMMDeviceEnumerator = 0 $oMMDevice = 0 $oDeviceTopology = 0 Exit EndIf Local $pConnDevice = 0 $hr = $oIConnector.GetConnectedTo($pConnDevice) If FAILED($hr) Then ConsoleWrite("!Error GetConnectedTo Device" & @CRLF) $oMMDeviceEnumerator = 0 $oMMDevice = 0 $oDeviceTopology = 0 Exit EndIf Local $oConnDevice = ObjCreateInterface($pConnDevice, $IID_IConnector, $tagIConnector) If @error Then ConsoleWrite("!Error Creation oConnDevice(IConnector) Interface" & @CRLF) $oMMDeviceEnumerator = 0 $oMMDevice = 0 $oDeviceTopology = 0 Exit EndIf Local $pPart = 0 $hr = $oConnDevice.QueryInterface($IID_IPart, $pPart) If FAILED($hr) Then ConsoleWrite("!Error Getting Part" & @CRLF) $oMMDeviceEnumerator = 0 $oMMDevice = 0 $oDeviceTopology = 0 $oConnDevice = 0 Exit EndIf Local $oIPart = ObjCreateInterface($pPart, $IID_IPart, $tagIPart) If @error Then ConsoleWrite("!Error Creating IPart Interface" & @CRLF) $oMMDeviceEnumerator = 0 $oMMDevice = 0 $oDeviceTopology = 0 Exit EndIf ConsoleWrite(">>>>>>>>>>>>>>>>>BEGIN<<<<<<<<<<<<<<<<<<<<" & @CRLF) GetPart($oIPart) $oIPart = 0 EndFunc ;==>MUTE Func GetPart(ByRef $oIPart) Local Static $bNextIsMute = False Local $sPartName = "" Local $PartLocalId = "" Local $hr = -1 ConsoleWrite("+Part" & @CRLF) $hr = $oIPart.GetName($sPartName) If FAILED($hr) Then ConsoleWrite("Not Part Name" & @CRLF) Return $hr EndIf $oIPart.GetLocalId($PartLocalId) If FAILED($hr) Then ConsoleWrite("Not Part ID" & @CRLF) Return $hr EndIf ConsoleWrite(">" & $sPartName) ConsoleWrite(" ID: " & $PartLocalId & @CRLF) If $bNextIsMute=False Then $bNextIsMute = StringInStr($sPartName, 'Front Pink In') ? True : False EndIf If $bNextIsMute Then Local $pIAudioMute = 0 Local $bMute = 0 Local $oIAudioMute = 0 $hr = $oIPart.Activate($CLSCTX_INPROC_SERVER, __uuidof($IID_IAudioMute), $pIAudioMute) If SUCCEEDED($hr) Then $bNextIsMute = False $oIAudioMute = ObjCreateInterface($pIAudioMute, $IID_IAudioMute, $tagIAudioMute) If @error Then ConsoleWrite("!Error Creating IAudioMute Interface") EndIf $hr = $oIAudioMute.GetMute($bMute) If FAILED($hr) Then ConsoleWrite("!Error Getting Mute State" & @CRLF) EndIf $hr = $oIAudioMute.SetMute(Not ($bMute), Null) If SUCCEEDED($hr) Then ConsoleWrite("!MUTE: " & (($bMute = False) ? "ON!" : "OFF!") & @CRLF) TrayTip("!MUTE: " & (($bMute = False) ? "ON!" : "OFF!"), "Danyfirex", 2, 1) Sleep(2000) EndIf EndIf EndIf Local $pIncomingParts = 0 $hr = $oIPart.EnumPartsIncoming($pIncomingParts) If ($hr = $E_NOTFOUND) Then ConsoleWrite("Not incoming Parts in Part" & @CRLF) Return $S_OK EndIf If FAILED($hr) Then ConsoleWrite("!ERROR Enumerating incoming Parts" & @CRLF) Return $hr EndIf Local $oIPartsList = ObjCreateInterface($pIncomingParts, $IID_IPartsList, $tagIPartsList) If @error Then ConsoleWrite("!Error Creating IPartsList Interface") EndIf Local $iNParts = 0 $oIPartsList.GetCount($iNParts) If FAILED($hr) Then ConsoleWrite("Couldn't get count of incoming parts") Return $hr EndIf Local $pIncomingPart = 0 Local $oIPart2 = 0 For $i = $iNParts - 1 To 0 Step -1 $hr = $oIPartsList.GetPart($i, $pIncomingPart) If (FAILED($hr)) Then ConsoleWrite("Not Got Part" & @CRLF) $oIPartsList = 0 Return $hr EndIf Local $oIPart2 = ObjCreateInterface($pIncomingPart, $IID_IPart, $tagIPart) If @error Then ConsoleWrite("!Error Creating IPartsList(2) Interface") $oIPartsList = 0 Return $hr EndIf $hr = GetPart($oIPart2) If FAILED($hr) Then $oIPartsList = 0 $oIPart2 = 0 Return $hr EndIf Next $oIPart2 = 0 Return $S_OK EndFunc ;==>GetPart Func __uuidof($sGUID) Local $tGUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]") DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID) If @error Then Return SetError(@error, @extended, 0) Return $tGUID EndFunc ;==>__uuidof Func SUCCEEDED($hr) Return ($hr >= 0) EndFunc ;==>SUCCEEDED Func FAILED($hr) Return ($hr < 0) EndFunc ;==>FAILED Saludos
-
Seminko reacted to Danyfirex in Microphone sound enable / disable
Seems to be Windows 10 enumerates in a diferent way...
I think this should work:
Opt("MustDeclareVars", 1) Global Enum $eRender, $eCapture, $eAll, $EDataFlow_enum_count Global Enum $eConsole, $eMultimedia, $eCommunications, $ERole_enum_count Global Const $CLSCTX_INPROC_SERVER = 1 Global Const $E_NOTFOUND = 0x80070490 Global Const $S_OK = 0 Global Const $CLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}" Global Const $IID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}" Global Const $tagIMMDeviceEnumerator = _ "EnumAudioEndpoints hresult(int;dword;ptr*);" & _ "GetDefaultAudioEndpoint hresult(int;int;ptr*);" & _ "GetDevice hresult(wstr;ptr*);" & _ "RegisterEndpointNotificationCallback hresult(ptr);" & _ "UnregisterEndpointNotificationCallback hresult(ptr)" Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}" Global Const $tagIMMDevice = _ "Activate hresult(struct*;dword;ptr;ptr*);" & _ "OpenPropertyStore hresult(dword;ptr*);" & _ "GetId hresult(wstr*);" & _ "GetState hresult(dword*)" Global Const $IID_IDeviceTopology = "{2A07407E-6497-4A18-9787-32F79BD0D98F}" Global Const $tagIDeviceTopology = "GetConnectorCount hresult(int*);GetConnector hresult(int;ptr*);" & _ "GetSubunitCount hresult(int*);GetSubunit hresult(int;ptr*);GetPartById hresult(int,ptr*);GetDeviceId hresult(ptr*);GetSignalPath hresult(ptr;ptr;bool;ptr*)" Global Const $IID_IConnector = "{9c2c4058-23f5-41de-877a-df3af236a09e}" Global Const $tagIConnector = "GetType hresult(ptr*);GetDataFlow hresult(ptr*);ConnectTo hresult(ptr);Disconnect hresult(none);IsConnected hresult(int*);" & _ "GetConnectedTo hresult(ptr*);GetConnectorIdConnectedTo hresult(wstr*);GetDeviceIdConnectedTo hresult(wstr*)" Global Const $IID_IPart = "{AE2DE0E4-5BCA-4F2D-AA46-5D13F8FDB3A9}" Global Const $tagIPart = "GetName hresult(wstr*);GetLocalId hresult(uint*);GetGlobalId hresult(wstr*);GetPartType hresult(ptr);GetSubType hresult(ptr);" & _ "GetControlInterfaceCount hresult(uint*);GetControlInterface hresult(int;ptr*);EnumPartsIncoming hresult(ptr*);EnumPartsOutgoing hresult(ptr*);" & _ "GetTopologyObject hresult(ptr*);Activate hresult(dword;struct*;ptr*);RegisterControlChangeCallback hresult(ptr);UnregisterControlChangeCallback hresult(ptr)" Global Const $IID_IPartsList = "{6DAA848C-5EB0-45CC-AEA5-998A2CDA1FFB}" Global Const $tagIPartsList = "GetCount hresult(uint*);GetPart hreuslt(uint;ptr*)" Global Const $IID_IAudioMute = "{DF45AEEA-B74A-4B6B-AFAD-2366B6AA012E}" Global Const $tagIAudioMute = "SetMute hresult(bool;ptr);GetMute hresult(int*)" MUTE() Func MUTE() Local $hr = -1 Local $oMMDeviceEnumerator = ObjCreateInterface($CLSID_MMDeviceEnumerator, $IID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator) If @error Then ConsoleWrite("!Error Creating IMMDeviceEnumerator Interface" & @CRLF) Exit EndIf Local $pDevice = 0 $hr = $oMMDeviceEnumerator.GetDefaultAudioEndpoint($eRender, $eConsole, $pDevice) If FAILED($hr) Then ConsoleWrite("!Error Getting Default Render Endpoint Device" & @CRLF) $oMMDeviceEnumerator = 0 Exit EndIf Local $oMMDevice = ObjCreateInterface($pDevice, $IID_IMMDevice, $tagIMMDevice) If @error Then ConsoleWrite("!Error Creating IMMDevice Interface" & @CRLF) $oMMDeviceEnumerator = 0 Exit EndIf Local $pDeviceTopology = 0 $hr = $oMMDevice.Activate(__uuidof($IID_IDeviceTopology), $CLSCTX_INPROC_SERVER, 0, $pDeviceTopology) If FAILED($hr) Then ConsoleWrite("!Error Getting Device Topology" & @CRLF) $oMMDeviceEnumerator = 0 $oMMDevice = 0 Exit EndIf Local $oDeviceTopology = ObjCreateInterface($pDeviceTopology, $IID_IDeviceTopology, $tagIDeviceTopology) If @error Then ConsoleWrite("!Error Creating IDeviceTopology Interface" & @CRLF) $oMMDeviceEnumerator = 0 $oMMDevice = 0 Exit EndIf Local $pConnEndpoint = 0 $hr = $oDeviceTopology.GetConnector(0, $pConnEndpoint) If FAILED($hr) Then ConsoleWrite("!Error Getting endpoint Connector" & @CRLF) $oMMDeviceEnumerator = 0 $oMMDevice = 0 $oDeviceTopology = 0 Exit EndIf Local $oIConnector = ObjCreateInterface($pConnEndpoint, $IID_IConnector, $tagIConnector) If @error Then ConsoleWrite("!Error Creating IConnector Interface" & @CRLF) $oMMDeviceEnumerator = 0 $oMMDevice = 0 $oDeviceTopology = 0 Exit EndIf Local $pConnDevice = 0 $hr = $oIConnector.GetConnectedTo($pConnDevice) If FAILED($hr) Then ConsoleWrite("!Error GetConnectedTo Device" & @CRLF) $oMMDeviceEnumerator = 0 $oMMDevice = 0 $oDeviceTopology = 0 Exit EndIf Local $oConnDevice = ObjCreateInterface($pConnDevice, $IID_IConnector, $tagIConnector) If @error Then ConsoleWrite("!Error Creation oConnDevice(IConnector) Interface" & @CRLF) $oMMDeviceEnumerator = 0 $oMMDevice = 0 $oDeviceTopology = 0 Exit EndIf Local $pPart = 0 $hr = $oConnDevice.QueryInterface($IID_IPart, $pPart) If FAILED($hr) Then ConsoleWrite("!Error Getting Part" & @CRLF) $oMMDeviceEnumerator = 0 $oMMDevice = 0 $oDeviceTopology = 0 $oConnDevice = 0 Exit EndIf Local $oIPart = ObjCreateInterface($pPart, $IID_IPart, $tagIPart) If @error Then ConsoleWrite("!Error Creating IPart Interface" & @CRLF) $oMMDeviceEnumerator = 0 $oMMDevice = 0 $oDeviceTopology = 0 Exit EndIf ConsoleWrite(">>>>>>>>>>>>>>>>>BEGIN<<<<<<<<<<<<<<<<<<<<" & @CRLF) GetPart($oIPart) $oIPart = 0 EndFunc Func GetPart(ByRef $oIPart) Local Static $iIndex=0 Local $sPartName = "" Local $PartLocalId = "" Local $hr = -1 ConsoleWrite("+Part" & @CRLF) $hr = $oIPart.GetName($sPartName) If FAILED($hr) Then ConsoleWrite("Not Part Name" & @CRLF) Return $hr EndIf $oIPart.GetLocalId($PartLocalId) If FAILED($hr) Then ConsoleWrite("Not Part ID" & @CRLF) Return $hr EndIf ConsoleWrite(">" & $sPartName) ConsoleWrite(" ID: " & $PartLocalId & @CRLF) If True Then Local $pIAudioMute = 0 Local $bMute = 0 Local $oIAudioMute = 0 $hr = $oIPart.Activate($CLSCTX_INPROC_SERVER, __uuidof($IID_IAudioMute), $pIAudioMute) If SUCCEEDED($hr) Then $iIndex+=1 If SUCCEEDED($hr) And $iIndex=4 Then $iIndex=0 $oIAudioMute = ObjCreateInterface($pIAudioMute, $IID_IAudioMute, $tagIAudioMute) If @error Then ConsoleWrite("!Error Creating IAudioMute Interface") EndIf $hr = $oIAudioMute.GetMute($bMute) If FAILED($hr) Then ConsoleWrite("!Error Getting Mute State" & @CRLF) EndIf $hr = $oIAudioMute.SetMute(Not ($bMute), Null) If SUCCEEDED($hr) Then ConsoleWrite("!MUTE: " & (($bMute = False) ? "ON!" : "OFF!") & @CRLF) TrayTip("!MUTE: " & (($bMute = False) ? "ON!" : "OFF!"), "Danyfirex", 2, 1) Sleep(2000) EndIf EndIf EndIf Local $pIncomingParts = 0 $hr = $oIPart.EnumPartsIncoming($pIncomingParts) If ($hr = $E_NOTFOUND) Then ConsoleWrite("Not incoming Parts in Part" & @CRLF) Return $S_OK EndIf If FAILED($hr) Then ConsoleWrite("!ERROR Enumerating incoming Parts" & @CRLF) Return $hr EndIf Local $oIPartsList = ObjCreateInterface($pIncomingParts, $IID_IPartsList, $tagIPartsList) If @error Then ConsoleWrite("!Error Creating IPartsList Interface") EndIf Local $iNParts = 0 $oIPartsList.GetCount($iNParts) If FAILED($hr) Then ConsoleWrite("Couldn't get count of incoming parts") Return $hr EndIf Local $pIncomingPart = 0 Local $oIPart2 = 0 For $i = 0 To $iNParts - 1 $hr = $oIPartsList.GetPart($i, $pIncomingPart) If (FAILED($hr)) Then ConsoleWrite("Not Got Part" & @CRLF) $oIPartsList = 0 Return $hr EndIf Local $oIPart2 = ObjCreateInterface($pIncomingPart, $IID_IPart, $tagIPart) If @error Then ConsoleWrite("!Error Creating IPartsList(2) Interface") $oIPartsList = 0 Return $hr EndIf $hr = GetPart($oIPart2) If FAILED($hr) Then $oIPartsList = 0 $oIPart2 = 0 Return $hr EndIf Next $oIPart2=0 Return $S_OK EndFunc ;==>GetPart Func __uuidof($sGUID) Local $tGUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]") DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID) If @error Then Return SetError(@error, @extended, 0) Return $tGUID EndFunc ;==>__uuidof Func SUCCEEDED($hr) Return ($hr >= 0) EndFunc ;==>SUCCEEDED Func FAILED($hr) Return ($hr < 0) EndFunc ;==>FAILED Saludos
-
Seminko reacted to Danyfirex in Microphone sound enable / disable
As I was thinking the issue is that the IAudioMute interface can't be created. I'll look deep on this later.
Saludos
-
Seminko reacted to Danp2 in How to grab javascript generated data?
@Seminko You should investigate using the "--headless" option with the ChromeDriver.
-
Seminko reacted to wraithdu in _SysTray UDF
Here is my highly modified version of Tuape's UDF. The example shows how to get different info and how to remove dead icons (no mouse move required). I've included support for the Windows 7 NotifyIconOverflowWindow icons as well, however I recommend using my _OsVersionInfo UDF to determine the OS instead of @OSVersion. This should work on Win2000+, but some testers on XP and Vista would be appreciated.
_SysTray
#include-once ; ---------------------------------------------------------------------------- ; ; Author: Tuape ; Modified: Erik Pilsits ; ; Script Function: ; Systray UDF - Functions for reading icon info from system tray / removing ; any icon. ; ; Last Update: 5/13/2013 ; ; ---------------------------------------------------------------------------- ;=============================================================================== ; ; Function Name: _SysTrayIconCount($iWin = 1) ; Description: Returns number of icons on systray ; Note: Hidden icons are also reported ; Parameter(s): $iWin ; | 1 - ToolbarWindow32, Win2000+ ; | 2 - NotifyIconOverflowWindow, Win7+ ; ; Requirement(s): ; Return Value(s): On Success - Returns number of icons found ; On Failure - Returns -1 ; ; Author(s): Tuape, Erik Pilsits ; ;=============================================================================== Func _SysTrayIconCount($iWin = 1) Local Const $TB_BUTTONCOUNT = 1048 Local $hWnd = _FindTrayToolbarWindow($iWin) If $hWnd = -1 Then Return -1 Local $count = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $TB_BUTTONCOUNT, "wparam", 0, "lparam", 0) If @error Then Return -1 Return $count[0] EndFunc ;==>_SysTrayIconCount ;=============================================================================== ; ; Function Name: _SysTrayIconTitles($iWin = 1) ; Description: Get list of all window titles that have systray icon ; Parameter(s): $iWin ; | 1 - ToolbarWindow32, Win2000+ ; | 2 - NotifyIconOverflowWindow, Win7+ ; Requirement(s): ; Return Value(s): On Success - Returns an array with all window titles ; On Failure - Returns -1 ; ; Author(s): Tuape, Erik Pilsits ; ;=============================================================================== Func _SysTrayIconTitles($iWin = 1) Local $count = _SysTrayIconCount($iWin) If $count <= 0 Then Return -1 Local $titles[$count] ; Get icon owner window"s title For $i = 0 To $count - 1 $titles[$i] = WinGetTitle(_SysTrayIconHandle($i, $iWin)) Next Return $titles EndFunc ;==>_SysTrayIconTitles ;=============================================================================== ; ; Function Name: _SysTrayIconPids($iWin = 1) ; Description: Get list of all processes id's that have systray icon ; Parameter(s): $iWin ; | 1 - ToolbarWindow32, Win2000+ ; | 2 - NotifyIconOverflowWindow, Win7+ ; Requirement(s): ; Return Value(s): On Success - Returns an array with all process id's ; On Failure - Returns -1 ; ; Author(s): Tuape, Erik Pilsits ; ;=============================================================================== Func _SysTrayIconPids($iWin = 1) Local $count = _SysTrayIconCount($iWin) If $count <= 0 Then Return -1 Local $processes[$count] For $i = 0 To $count - 1 $processes[$i] = WinGetProcess(_SysTrayIconHandle($i, $iWin)) Next Return $processes EndFunc ;==>_SysTrayIconPids ;=============================================================================== ; ; Function Name: _SysTrayIconProcesses($iWin = 1) ; Description: Get list of all processes that have systray icon ; Parameter(s): $iWin ; | 1 - ToolbarWindow32, Win2000+ ; | 2 - NotifyIconOverflowWindow, Win7+ ; Requirement(s): ; Return Value(s): On Success - Returns an array with all process names ; On Failure - Returns -1 ; ; Author(s): Tuape, Erik Pilsits ; ;=============================================================================== Func _SysTrayIconProcesses($iWin = 1) Local $pids = _SysTrayIconPids($iWin) If Not IsArray($pids) Then Return -1 Local $processes[UBound($pids)] ; List all processes Local $list = ProcessList() For $i = 0 To UBound($pids) - 1 For $j = 1 To $list[0][0] If $pids[$i] = $list[$j][1] Then $processes[$i] = $list[$j][0] ExitLoop EndIf Next Next Return $processes EndFunc ;==>_SysTrayIconProcesses ;=============================================================================== ; ; Function Name: _SysTrayIconIndex($test, $mode = 0, $iWin = 1) ; Description: Get list of all processes id"s that have systray icon ; Parameter(s): $test - process name / window title text / process PID ; $mode ; | 0 - get index by process name (default) ; | 1 - get index by window title ; | 2 - get index by process PID ; $iWin ; | 1 - ToolbarWindow32, Win2000+ ; | 2 - NotifyIconOverflowWindow, Win7+ ; Requirement(s): ; Return Value(s): On Success - Returns index of found icon ; On Failure - Returns -1 ; ; Author(s): Tuape, Erik Pilsits ; ;=============================================================================== Func _SysTrayIconIndex($test, $mode = 0, $iWin = 1) Local $ret = -1, $compare = -1 If $mode < 0 Or $mode > 2 Or Not IsInt($mode) Then Return -1 Switch $mode Case 0 $compare = _SysTrayIconProcesses($iWin) Case 1 $compare = _SysTrayIconTitles($iWin) Case 2 $compare = _SysTrayIconPids($iWin) EndSwitch If Not IsArray($compare) Then Return -1 For $i = 0 To UBound($compare) - 1 If $compare[$i] = $test Then $ret = $i ExitLoop EndIf Next Return $ret EndFunc ;==>_SysTrayIconIndex ; INTERNAL ===================================================================== ; ; Function Name: _SysTrayGetButtonInfo($iIndex, $iWin = 1, $iInfo = 0) ; Description: Gets Tray Button Info ; Parameter(s): $iIndex - icon index (Note: starting from 0) ; $iWin ; | 1 - ToolbarWindow32, Win2000+ ; | 2 - NotifyIconOverflowWindow, Win7+ ; $iInfo - Info to return ; | 1 - TBBUTTON structure ; | 2 - TRAYDATA structure ; | 3 - tooltip ; | 4 - icon position ; Requirement(s): ; Return Value(s): On Success - Returns requested info ; On Failure - Sets @error and returns -1 ; | 1 - Failed to find tray window ; | 2 - Failed to get tray window PID ; | 3 - Failed to open process ; | 4 - Failed to allocate memory ; | 5 - Failed to get TBBUTTON info ; ; Author(s): Erik Pilsits, Tuape ; ;=============================================================================== Func _SysTrayGetButtonInfo($iIndex, $iWin = 1, $iInfo = 1) Local Const $TB_GETBUTTON = 1047 ;~ Local Const $TB_GETBUTTONTEXT = 1099 ;~ Local Const $TB_GETBUTTONINFO = 1089 Local Const $TB_GETITEMRECT = 1053 Local Const $ACCESS = BitOR(0x0008, 0x0010, 0x0400) ; VM_OPERATION, VM_READ, QUERY_INFORMATION Local $TBBUTTON If @OSArch = "X86" Then $TBBUTTON = DllStructCreate("int iBitmap;int idCommand;byte fsState;byte fsStyle;byte bReserved[2];dword dwData;int iString") Else ; X64 $TBBUTTON = DllStructCreate("int iBitmap;int idCommand;byte fsState;byte fsStyle;byte bReserved[6];uint64 dwData;int64 iString") EndIf Local $TRAYDATA If @OSArch = "X86" Then $TRAYDATA = DllStructCreate("hwnd hwnd;uint uID;uint uCallbackMessage;dword Reserved[2];handle hIcon") Else $TRAYDATA = DllStructCreate("uint64 hwnd;uint uID;uint uCallbackMessage;dword Reserved[2];uint64 hIcon") EndIf Local $trayHwnd = _FindTrayToolbarWindow($iWin) If $trayHwnd = -1 Then Return SetError(1, 0, -1) Local $return, $err = 0 Local $ret = DllCall("user32.dll", "dword", "GetWindowThreadProcessId", "hwnd", $trayHwnd, "dword*", 0) If @error Or Not $ret[2] Then SetError(2, 0, -1) Local $pId = $ret[2] Local $procHandle = DllCall("kernel32.dll", "handle", "OpenProcess", "dword", $ACCESS, "bool", False, "dword", $pId) If @error Or Not $procHandle[0] Then Return SetError(3, 0, -1) Local $lpData = DllCall("kernel32.dll", "ptr", "VirtualAllocEx", "handle", $procHandle[0], "ptr", 0, "ulong", DllStructGetSize($TBBUTTON), "dword", 0x1000, "dword", 0x04) If Not @error And $lpData[0] Then $ret = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $trayHwnd, "uint", $TB_GETBUTTON, "wparam", $iIndex, "lparam", $lpData[0]) If Not @error And $ret[0] Then DllCall("kernel32.dll", "bool", "ReadProcessMemory", "handle", $procHandle[0], "ptr", $lpData[0], "struct*", $TBBUTTON, "ulong", DllStructGetSize($TBBUTTON), "ulong*", 0) Switch $iInfo Case 2 ; TRAYDATA structure DllCall("kernel32.dll", "bool", "ReadProcessMemory", "handle", $procHandle[0], "ptr", DllStructGetData($TBBUTTON, 6), "struct*", $TRAYDATA, "ulong", DllStructGetSize($TRAYDATA), "ulong*", 0) $return = $TRAYDATA Case 3 ; tooltip $return = "" If BitShift(DllStructGetData($TBBUTTON, 7), 16) <> 0 Then Local $intTip = DllStructCreate("wchar[1024]") ; we have a pointer to a string, otherwise it is an internal resource identifier DllCall("kernel32.dll", "bool", "ReadProcessMemory", "handle", $procHandle[0], "ptr", DllStructGetData($TBBUTTON, 7), "struct*", $intTip, "ulong", DllStructGetSize($intTip), "ulong*", 0) $return = DllStructGetData($intTip, 1) ;else internal resource EndIf Case 4 ; icon position If Not BitAND(DllStructGetData($TBBUTTON, 3), 8) Then ; 8 = TBSTATE_HIDDEN Local $pos[2], $RECT = DllStructCreate("int;int;int;int") DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $trayHwnd, "uint", $TB_GETITEMRECT, "wparam", $iIndex, "lparam", $lpData[0]) DllCall("kernel32.dll", "bool", "ReadProcessMemory", "handle", $procHandle[0], "ptr", $lpData[0], "struct*", $RECT, "ulong", DllStructGetSize($RECT), "ulong*", 0) $ret = DllCall("user32.dll", "int", "MapWindowPoints", "hwnd", $trayHwnd, "ptr", 0, "struct*", $RECT, "uint", 2) $pos[0] = DllStructGetData($RECT, 1) $pos[1] = DllStructGetData($RECT, 2) $return = $pos Else $return = -1 EndIf Case Else ; TBBUTTON $return = $TBBUTTON EndSwitch Else $err = 5 EndIf DllCall("kernel32.dll", "bool", "VirtualFreeEx", "handle", $procHandle[0], "ptr", $lpData[0], "ulong", 0, "dword", 0x8000) Else $err = 4 EndIf DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $procHandle[0]) If $err Then Return SetError($err, 0, -1) Else Return $return EndIf EndFunc ;==>_SysTrayGetButtonInfo ;=============================================================================== ; ; Function Name: _SysTrayIconHandle($iIndex, $iWin = 1) ; Description: Gets hwnd of window associated with systray icon of given index ; Parameter(s): $iIndex - icon index (Note: starting from 0) ; $iWin ; | 1 - ToolbarWindow32, Win2000+ ; | 2 - NotifyIconOverflowWindow, Win7+ ; ; Requirement(s): ; Return Value(s): On Success - Returns hwnd of found icon ; On Failure - Sets @error and returns -1 ; | See _SysTrayGetButtonInfo for @error returns ; ; Author(s): Tuape, Erik Pilsits ; ;=============================================================================== Func _SysTrayIconHandle($iIndex, $iWin = 1) Local $TRAYDATA = _SysTrayGetButtonInfo($iIndex, $iWin, 2) If @error Then Return SetError(@error, 0, -1) Else Return Ptr(DllStructGetData($TRAYDATA, 1)) EndIf EndFunc ;==>_SysTrayIconHandle ;=============================================================================== ; ; Function Name: _SysTrayIconTooltip($iIndex, $iWin = 1) ; Description: Gets the tooltip text of systray icon of given index ; Parameter(s): $iIndex - icon index (Note: starting from 0) ; $iWin ; | 1 - ToolbarWindow32, Win2000+ ; | 2 - NotifyIconOverflowWindow, Win7+ ; ; Requirement(s): ; Return Value(s): On Success - Returns tooltip text of icon ; On Failure - Sets @error and returns -1 ; | See _SysTrayGetButtonInfo for @error returns ; ; Author(s): Tuape, Erik Pilsits ; ;=============================================================================== Func _SysTrayIconTooltip($iIndex, $iWin = 1) Local $ret = _SysTrayGetButtonInfo($iIndex, $iWin, 3) If @error Then Return SetError(@error, 0, -1) Else Return $ret EndIf EndFunc ;==>_SysTrayIconTooltip ;=============================================================================== ; ; Function Name: _SysTrayIconPos($iIndex, $iWin = 1) ; Description: Gets x & y position of systray icon ; Parameter(s): $iIndex - icon index (Note: starting from 0) ; $iWin ; | 1 - ToolbarWindow32, Win2000+ ; | 2 - NotifyIconOverflowWindow, Win7+ ; ; Requirement(s): ; Return Value(s): On Success - Returns array, x [0] and y [1] position of icon ; On Failure - Sets @error and returns -1 ; | -1 - Icon is hidden (Autohide on XP, etc) ; | See _SysTrayGetButtonInfo for additional @error returns ; ; Author(s): Tuape, Erik Pilsits ; ;=============================================================================== Func _SysTrayIconPos($iIndex, $iWin = 1) Local $ret = _SysTrayGetButtonInfo($iIndex, $iWin, 4) If @error Then Return SetError(@error, 0, -1) Else If $ret = -1 Then Return SetError(-1, 0, -1) Else Return $ret EndIf EndIf EndFunc ;==>_SysTrayIconPos ;=============================================================================== ; ; Function Name: _SysTrayIconVisible($iIndex, $iWin = 1) ; Description: Gets the visibility of a systray icon ; Parameter(s): $iIndex - icon index (Note: starting from 0) ; $iWin ; | 1 - ToolbarWindow32, Win2000+ ; | 2 - NotifyIconOverflowWindow, Win7+ ; ; Requirement(s): ; Return Value(s): On Success - Returns True (visible) or False (hidden) ; On Failure - Sets @error and returns -1 ; | See _SysTrayGetButtonInfo for @error returns ; ; Author(s): Tuape, Erik Pilsits ; ;=============================================================================== Func _SysTrayIconVisible($iIndex, $iWin = 1) Local $TBBUTTON = _SysTrayGetButtonInfo($iIndex, $iWin, 1) If @error Then Return SetError(@error, 0, -1) Else Return Not BitAND(DllStructGetData($TBBUTTON, 3), 8) ;TBSTATE_HIDDEN EndIf EndFunc ;==>_SysTrayIconVisible ;=============================================================================== ; ; Function Name: _SysTrayIconHide($index, $iFlag, $iWin = 1) ; Description: Hides / unhides any icon on systray ; ; Parameter(s): $index - icon index. Can be queried with _SysTrayIconIndex() ; $iFlag - hide (1) or show (0) icon ; $iWin ; | 1 - ToolbarWindow32, Win2000+ ; | 2 - NotifyIconOverflowWindow, Win7+ ; ; Requirement(s): ; Return Value(s): On Success - Returns 1 if operation was successfull or 0 if ; icon was already hidden/unhidden ; On Failure - Sets @error and returns -1 ; | See _SysTrayGetButtonInfo for @error returns ; ; Author(s): Tuape, Erik Pilsits ; ;=============================================================================== Func _SysTrayIconHide($index, $iFlag, $iWin = 1) ;~ Local Const $TB_HIDEBUTTON = 0x0404 ; WM_USER + 4 Local $TBBUTTON = _SysTrayGetButtonInfo($index, $iWin, 1) If @error Then Return SetError(@error, 0, -1) Local $visible = Not BitAND(DllStructGetData($TBBUTTON, 3), 8) ;TBSTATE_HIDDEN If ($iFlag And Not $visible) Or (Not $iFlag And $visible) Then Return 0 Else Local $TRAYDATA = _SysTrayGetButtonInfo($index, $iWin, 2) If @error Then Return SetError(@error, 0, -1) Local $NOTIFYICONDATA = DllStructCreate("dword cbSize;hwnd hWnd;uint uID;uint uFlags;uint uCallbackMessage;handle hIcon;wchar szTip[128];" _ & "dword dwState;dword dwStateMask;wchar szInfo[256];uint uVersion;wchar szInfoTitle[64];dword dwInfoFlags;" _ & "STRUCT;ulong;ushort;ushort;byte[8];ENDSTRUCT;handle hBalloonIcon") DllStructSetData($NOTIFYICONDATA, 1, DllStructGetSize($NOTIFYICONDATA)) DllStructSetData($NOTIFYICONDATA, 2, Ptr(DllStructGetData($TRAYDATA, 1))) DllStructSetData($NOTIFYICONDATA, 3, DllStructGetData($TRAYDATA, 2)) DllStructSetData($NOTIFYICONDATA, 4, 8) ; NIF_STATE DllStructSetData($NOTIFYICONDATA, 8, $iFlag) ; dw_State, 0 or 1 = NIS_HIDDEN DllStructSetData($NOTIFYICONDATA, 9, 1) ; dwStateMask Local $ret = DllCall("shell32.dll", "bool", "Shell_NotifyIconW", "dword", 0x1, "struct*", $NOTIFYICONDATA) ; NIM_MODIFY DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", WinGetHandle("[CLASS:Shell_TrayWnd]"), "uint", 0x001A, "wparam", 0, "lparam", 0) ; WM_SETTINGCHANGE If IsArray($ret) And $ret[0] Then Return 1 Else Return 0 EndIf ;~ $ret = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $trayHwnd, "uint", $TB_HIDEBUTTON, "wparam", DllStructGetData($TBBUTTON, 2), "lparam", $iHide) ;~ If @error Or Not $ret[0] Then ;~ $return = -1 ;~ Else ;~ $return = $ret[0] ;~ EndIf EndIf EndFunc ;==>_SysTrayIconHide ;=============================================================================== ; ; Function Name: _SysTrayIconMove($curPos, $newPos, $iWin = 1) ; Description: Moves systray icon ; ; Parameter(s): $curPos - icon's current index (0 based) ; $newPos - icon's new position ; ($curPos+1 = one step to right, $curPos-1 = one step to left) ; $iWin ; | 1 - ToolbarWindow32, Win2000+ ; | 2 - NotifyIconOverflowWindow, Win7+ ; ; Requirement(s): AutoIt3 Beta ; Return Value(s): On Success - Returns 1 if operation was successfull, 0 if not ; On Failure - Sets @error and returns -1 ; | 1 - Bad parameters ; | 2 - Failed to find tray window ; ; Author(s): Tuape, Erik Pilsits ; ;=============================================================================== Func _SysTrayIconMove($curPos, $newPos, $iWin = 1) Local Const $TB_MOVEBUTTON = 0x0452 ; WM_USER + 82 Local $iconCount = _SysTrayIconCount($iWin) If $curPos < 0 Or $newPos < 0 Or $curPos > $iconCount - 1 Or $newPos > $iconCount - 1 Or Not IsInt($curPos) Or Not IsInt($newPos) Then Return SetError(1, 0, -1) Local $hWnd = _FindTrayToolbarWindow($iWin) If $hWnd = -1 Then Return SetError(2, 0, -1) Local $ret = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $TB_MOVEBUTTON, "wparam", $curPos, "lparam", $newPos) If @error Or Not $ret[0] Then Return 0 Else Return 1 EndIf EndFunc ;==>_SysTrayIconMove ;=============================================================================== ; ; Function Name: _SysTrayIconRemove($index, $iWin = 1) ; Description: Removes systray icon completely. ; ; Parameter(s): $index - Icon index (first icon is 0) ; $iWin ; | 1 - ToolbarWindow32, Win2000+ ; | 2 - NotifyIconOverflowWindow, Win7+ ; ; Return Value(s): On Success - Returns 1 if icon successfully removed, 0 if not ; On Failure - Sets @error and returns -1 ; | See _SysTrayGetButtonInfo for @error returns ; ; Author(s): Tuape, Erik Pilsits ; ;=============================================================================== Func _SysTrayIconRemove($index, $iWin = 1) Local Const $TB_DELETEBUTTON = 1046 Local $TRAYDATA = _SysTrayGetButtonInfo($index, $iWin, 2) If @error Then Return SetError(@error, 0, -1) Local $NOTIFYICONDATA = DllStructCreate("dword cbSize;hwnd hWnd;uint uID;uint uFlags;uint uCallbackMessage;handle hIcon;wchar szTip[128];" _ & "dword dwState;dword dwStateMask;wchar szInfo[256];uint uVersion;wchar szInfoTitle[64];dword dwInfoFlags;" _ & "STRUCT;ulong;ushort;ushort;byte[8];ENDSTRUCT;handle hBalloonIcon") DllStructSetData($NOTIFYICONDATA, 1, DllStructGetSize($NOTIFYICONDATA)) DllStructSetData($NOTIFYICONDATA, 2, Ptr(DllStructGetData($TRAYDATA, 1))) DllStructSetData($NOTIFYICONDATA, 3, DllStructGetData($TRAYDATA, 2)) Local $ret = DllCall("shell32.dll", "bool", "Shell_NotifyIconW", "dword", 0x2, "struct*", $NOTIFYICONDATA) ; NIM_DELETE DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", WinGetHandle("[CLASS:Shell_TrayWnd]"), "uint", 0x001A, "wparam", 0, "lparam", 0) ; WM_SETTINGCHANGE If IsArray($ret) And $ret[0] Then Return 1 Else Return 0 EndIf ;~ Local $hWnd = _FindTrayToolbarWindow($iWin) ;~ If $hwnd = -1 Then Return -1 ;~ Local $ret = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $TB_DELETEBUTTON, "wparam", $index, "lparam", 0) ;~ If @error Or Not $ret[0] Then Return -1 ;~ Return $ret[0] EndFunc ;==>_SysTrayIconRemove ;=============================================================================== ; ; Function Name: _FindTrayToolbarWindow($iWin = 1) ; Description: Utility function for finding Toolbar window hwnd ; Parameter(s): $iWin ; | 1 - ToolbarWindow32, Win2000+ ; | 2 - NotifyIconOverflowWindow, Win7+ ; ; Requirement(s): ; Return Value(s): On Success - Returns Toolbar window hwnd ; On Failure - returns -1 ; ; Author(s): Tuape, Erik Pilsits ; ;=============================================================================== Func _FindTrayToolbarWindow($iWin = 1) Local $hwnd, $ret = -1 If $iWin = 1 Then $hWnd = DllCall("user32.dll", "hwnd", "FindWindow", "str", "Shell_TrayWnd", "ptr", 0) If @error Then Return -1 $hWnd = DllCall("user32.dll", "hwnd", "FindWindowEx", "hwnd", $hWnd[0], "hwnd", 0, "str", "TrayNotifyWnd", "ptr", 0) If @error Then Return -1 If @OSVersion <> "WIN_2000" Then $hWnd = DllCall("user32.dll", "hwnd", "FindWindowEx", "hwnd", $hWnd[0], "hwnd", 0, "str", "SysPager", "ptr", 0) If @error Then Return -1 EndIf $hWnd = DllCall("user32.dll", "hwnd", "FindWindowEx", "hwnd", $hWnd[0], "hwnd", 0, "str", "ToolbarWindow32", "ptr", 0) If @error Then Return -1 $ret = $hwnd[0] ElseIf $iWin = 2 Then ; NotifyIconOverflowWindow for Windows 7 $hWnd = DllCall("user32.dll", "hwnd", "FindWindow", "str", "NotifyIconOverflowWindow", "ptr", 0) If @error Then Return -1 $hWnd = DllCall("user32.dll", "hwnd", "FindWindowEx", "hwnd", $hWnd[0], "hwnd", 0, "str", "ToolbarWindow32", "ptr", 0) If @error Then Return -1 $ret = $hwnd[0] EndIf Return $ret EndFunc ;==>_FindTrayToolbarWindow
Example
#NoTrayIcon #include <_SysTray.au3> #include <Process.au3> $count = _SysTrayIconCount() ConsoleWrite("Count visible tray: " & $count & @CRLF) For $i = $count - 1 To 0 Step -1 $handle = _SysTrayIconHandle($i) $visible = _SysTrayIconVisible($i) $pid = WinGetProcess($handle) $name = _ProcessGetName($pid) $title = WinGetTitle($handle) $tooltip = _SysTrayIconTooltip($i) ConsoleWrite("index: " & $i & @TAB & "visible: " & $visible & @TAB & "handle: " & $handle & @TAB & "pid: " & _ $pid & @TAB & "proc: " & $name & @TAB & @TAB & "title: " & $title & @TAB & @TAB & "tooltip: " & $tooltip & @CRLF) If $pid = -1 Then _SysTrayIconRemove($i) Next If _FindTrayToolbarWindow(2) <> -1 Then ConsoleWrite("-====================-" & @CRLF) $countwin7 = _SysTrayIconCount(2) ConsoleWrite("Count overflow area: " & $countwin7 & @CRLF) For $i = $countwin7 - 1 To 0 Step -1 $handle = _SysTrayIconHandle($i, 2) $visible = _SysTrayIconVisible($i, 2) $pid = WinGetProcess($handle) $name = _ProcessGetName($pid) $title = WinGetTitle($handle) $tooltip = _SysTrayIconTooltip($i, 2) ConsoleWrite("index: " & $i & @TAB & "visible: " & $visible & @TAB & "handle: " & $handle & @TAB & "pid: " & _ $pid & @TAB & "proc: " & $name & @TAB & @TAB & "title: " & $title & @TAB & @TAB & "tooltip: " & $tooltip & @CRLF) If $pid = -1 Then _SysTrayIconRemove($i, 2) Next EndIf