Jump to content

Completely hide control panel?


Recommended Posts

Hi,

I'm trying to find a way to quickly switch between stereo output and quadraphonic output.

At first, I tried to achieve this by directly changing the registry: I used Process Monitor to detect which registry keys were accessed when changing the output setting. I then copied the keys that were actually changed to a .reg file and run that to change the output. This almost worked, but for some reason applications had to be restarted to allow them to reload the settings. When I switched the output normally, the output switch occured immediately. I could clearly see this in Process Monitor: When doing it manually, applications like Winamp accessed the changed keys. When using the reg files, they did not. Maybe this problem can be solved, but I have no idea how...

Then I decided to give AutoIt a try. I created this script:

Opt('WinWaitDelay', 90)
Run("control mmsys.cpl")
WinWait("[CLASS:#32770]")
WinSetState("[CLASS:#32770]","",@SW_HIDE)
ControlListView("[CLASS:#32770]", "", 1000, "Select", 2)
ControlClick("[CLASS:#32770]", "", 1001)
WinWait("[CLASS:NativeHWNDHost]")
WinSetState("[CLASS:NativeHWNDHost]","",@SW_HIDE)
ControlCommand("[CLASS:NativeHWNDHost]", "", 1303, "SetCurrentSelection", 1)
ControlClick("[CLASS:NativeHWNDHost]", "", "Button1")
ControlClick("[CLASS:NativeHWNDHost]", "", "Button1")
ControlClick("[CLASS:NativeHWNDHost]", "", "Button2")
ControlClick("[CLASS:#32770]", "", 1)

This basically works, but the one problem I experience with this, is that the @SW_HIDE argument in the Run function doesn't seem to work for the control panel - so it cannot be hidden. I've also created a script for the seperate Realtek application, but that window couldn't be hidden either.

Is there any to completely hide the control panel/Realtek window, or is there a better solution to my problem?

Thanks in advance!

Edited by KeyMs92
Link to comment
Share on other sites

WinSetTrans

Opt("WinWaitDelay", 0)
Run("control mmsys.cpl")
WinWait("Sound")
WinSetTrans("Sound", "", 1)

0 for Completely invisible

1 for Naked 2 the eye, but can still be actived

but if you dont like how it flashes for a split second "like me". Then you could A. Make a system hook to detect when the window is being re-draw and set the trans then. Or just move it off-screen ^^

Opt("WinWaitDelay", 0)
Run("control mmsys.cpl")
WinWait("Sound")
WinMove("Sound", "", -500, -500)
Edited by IanN1990
Link to comment
Share on other sites

Hi, thanks for your reply!

If I understand you correctly, every hiding solution will have to wait for the window to appear first. This means the WinWaitDelay should be as low as possible. Strangely, I cannot even set it close to 0-1. I must set it to at least 100ms to reliably complete the routine every time :o. Am I doing something wrong?

Link to comment
Share on other sites

So to check, both codes above. DId they not work for u ?

cuz i just checked again. Windows 7 Proffesional N 64 Bit (Scite Full Version).

Both codes started up Sound, and once its visible its instantly hidden. "By Tran or by moving it off screen"

*One thought that did come to me, cuz i was coding for a friend. Is my version of windows is English. So the sound panels title is "Sound". If yours is not english, then it would be named something different and the code would fail as it cant find that title

Edited by IanN1990
Link to comment
Share on other sites

OK, I've done testing and found out that the Winamp process seems to be the cause of the considerable delay between windows opening. When I quit Winamp, I can set the WinWaitDelay to 0. Although that doesn't always work perfect either (I occasionally see a really short windows flash or it will get stuck because the WinWaitDelay is too low), it's much faster than with Winamp running. All this applies to WinSetTrans as well as WinMove.

Is there any way this is can be improved, or will I have to "live with it"?

Edited by KeyMs92
Link to comment
Share on other sites

Is this any better?

$SystemGUI=GUICreate('',1920,360,0,-256,-2147483648,168)
$SystemHook = DllCall('user32.dll', 'int', 'RegisterWindowMessageW', 'wstr', 'SHELLHOOK') ;$SystemHook
GUIRegisterMsg($SystemHook[0], "SystemDetectHook")
DllCall('user32.dll', 'int', 'RegisterShellHookWindow', 'hwnd', $SystemGUI)
Run("control mmsys.cpl")

while 1
sleep(250)
WEnd

Func SystemDetectHook($hWnd,$Msg,$wParam,$lParam)
Switch StringRight($wParam, 1)
Case 1 ;Window Created
If WinGetTitle($lParam) = "Sound" then WinSetTrans("Sound", "", 1)
EndSwitch
EndFunc
Link to comment
Share on other sites

Thanks for your reply! I added my code to it:

$SystemGUI=GUICreate('',1920,360,0,-256,-2147483648,168)
$SystemHook = DllCall('user32.dll', 'int', 'RegisterWindowMessageW', 'wstr', 'SHELLHOOK') ;$SystemHook
GUIRegisterMsg($SystemHook[0], "SystemDetectHook")
DllCall('user32.dll', 'int', 'RegisterShellHookWindow', 'hwnd', $SystemGUI)
Run("control mmsys.cpl")

Sleep(1000)

Func SystemDetectHook($hWnd,$Msg,$wParam,$lParam)
Switch StringRight($wParam, 1)
Case 1 ;Window Created
WinSetTrans(WinGetTitle($lParam), "", 1)
ControlListView("[CLASS:#32770]", "", 1000, "Select", 0)
ControlClick("[CLASS:#32770]", "", 1001)
ControlCommand("[CLASS:NativeHWNDHost]", "", 1303, "SetCurrentSelection", 1)
ControlClick("[CLASS:NativeHWNDHost]", "", "Button1")
ControlClick("[CLASS:NativeHWNDHost]", "", "Button1")
ControlClick("[CLASS:NativeHWNDHost]", "", "Button2")
ControlClick("[CLASS:#32770]", "", 1)
EndSwitch
EndFunc

It kinda works, but I need a better understanding of your script to be able to make improvements. Could you maybe add some comments/describe what the functions do and how they interact? Especially, why you've added the "while" loop.

I also noticed that the "while" loop causes the script to stay paused when the operation is finished. I removed the loop but then when I set the sleep value too low or too high, the script will go in a (infinite) loop. And even when the value is 'right' it will occasionally go into a loop. It's really weird : P

Edited by KeyMs92
Link to comment
Share on other sites

Though i have been on autoit for some time, i dont count myself as an expert. I will do my best to explain.

Every time windows does something it sends a message, a hook is basicly catchin all these messages allowing you to do things.

$GUIHook=GUICreate('Autoit Hook GUI') ;A GUI is needed to catch the messages.

$SystemHook = DllCall('user32.dll', 'int', 'RegisterWindowMessageW', 'wstr', 'SHELLHOOK') ;This the hook cut down and simplifed. Check link for a more detailed info on it.
GUIRegisterMsg($SystemHook[0], "GUIHook") ;Is the function you want to regesiter the Hook to. "GUIHook"
DllCall('user32.dll', 'int', 'RegisterShellHookWindow', 'hwnd', $GUIHook) ;Links it to your GUI so you can see the messages.

;Run("control mmsys.cpl") ;Runs the Sound Program

while 1
sleep(250)
;This is to keep the script alive, check HotKeySet in HelpFile. Its the same idea.
WEnd

Func GUIHook($hWnd,$Msg,$wParam,$lParam)
Switch StringRight($wParam, 1)
Case $wParam=32774 ;Flash
ConsoleWrite(WinGetTitle($lParam) & " has been flashed" & @CRLF)
Case 1 ;Window Created
ConsoleWrite(WinGetTitle($lParam) & " has been created" & @CRLF)
Case 2 ;Window Destoryed
ConsoleWrite(WinGetTitle($lParam) & " has been destroyed" & @CRLF)
Case 4 ;Actived
ConsoleWrite(WinGetTitle($lParam) & " has been actived" & @CRLF)
Case 6 ;Redrawn
ConsoleWrite(WinGetTitle($lParam) & " has been redrawn" & @CRLF)
EndSwitch
EndFunc

Thats the class over. If i made any mistakes then others feel free to correct. Nothing worse then the blind leading the blind :) Now with get your code working.

You have two Options.

If your A. Putting this into a exe that closes itself you can do this.

local $Sound

$GUIHook=GUICreate('Autoit Hook GUI') ;A GUI is needed to catch the messages.

$SystemHook = DllCall('user32.dll', 'int', 'RegisterWindowMessageW', 'wstr', 'SHELLHOOK') ;This the hook cut down and simplifed. Check link for a more detailed info on it.
GUIRegisterMsg($SystemHook[0], "GUIHook") ;Is the function you want to regesiter the Hook to. "GUIHook"
DllCall('user32.dll', 'int', 'RegisterShellHookWindow', 'hwnd', $GUIHook) ;Links it to your GUI so you can see the messages.

Run("control mmsys.cpl") ;Runs the Sound Program

while 1
sleep(250)
;This is to keep the script alive, check HotKeySet in HelpFile. Its the same idea.
WEnd

Func GUIHook($hWnd,$Msg,$wParam,$lParam)
Switch StringRight($wParam, 1)
Case 1 ;Window Created
If WinGetTitle($lParam) = "Sound" and $Sound = 0 Then
$Sound = 1
WinSetTrans(WinGetTitle($lParam), "", 1)
ControlListView("[CLASS:#32770]", "", 1000, "Select", 0)
ControlClick("[CLASS:#32770]", "", 1001)
ControlCommand("[CLASS:NativeHWNDHost]", "", 1303, "SetCurrentSelection", 1)
ControlClick("[CLASS:NativeHWNDHost]", "", "Button1")
ControlClick("[CLASS:NativeHWNDHost]", "", "Button1")
ControlClick("[CLASS:NativeHWNDHost]", "", "Button2")
ControlClick("[CLASS:#32770]", "", 1)
Exit
EndIf
EndSwitch
EndFunc

If B. your code needs to run all the time and you set this up with hotkey. You have to do this.

HotKeySet("{`}", "SoundFunction") ;Hotkey Set on the console button, ` normally located left of 1

local $Sound

$GUIHook=GUICreate('Autoit Hook GUI') ;A GUI is needed to catch the messages.

$SystemHook = DllCall('user32.dll', 'int', 'RegisterWindowMessageW', 'wstr', 'SHELLHOOK') ;This the hook cut down and simplifed. Check link for a more detailed info on it.
GUIRegisterMsg($SystemHook[0], "GUIHook") ;Is the function you want to regesiter the Hook to. "GUIHook"
DllCall('user32.dll', 'int', 'RegisterShellHookWindow', 'hwnd', $GUIHook) ;Links it to your GUI so you can see the messages.

while 1
sleep(250)
;This is to keep the script alive, check HotKeySet in HelpFile. Its the same idea.
WEnd

Func GUIHook($hWnd,$Msg,$wParam,$lParam)
Switch StringRight($wParam, 1)
Case 1 ;Window Created
If WinGetTitle($lParam) = "Sound" and $Sound Then
$Sound = 0
WinSetTrans(WinGetTitle($lParam), "", 1)
ControlListView("[CLASS:#32770]", "", 1000, "Select", 0)
ControlClick("[CLASS:#32770]", "", 1001)
ControlCommand("[CLASS:NativeHWNDHost]", "", 1303, "SetCurrentSelection", 1)
ControlClick("[CLASS:NativeHWNDHost]", "", "Button1")
ControlClick("[CLASS:NativeHWNDHost]", "", "Button1")
ControlClick("[CLASS:NativeHWNDHost]", "", "Button2")
ControlClick("[CLASS:#32770]", "", 1)
Exit
EndIf
EndSwitch
EndFunc

Func SoundFunction()
Run("control mmsys.cpl") ;Runs the Sound Program
$Sound = 1
EndFunc
Link to comment
Share on other sites

If I were wanting to do such a thing, I'd look into finding registry keys that hold the window position

of the particular window, and attempt to alter them so the window starts off screen.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

@IanN1990 Thanks for your reply! Perhaps I'm doing something wrong, but the code in option A doesn't work at all; the function GUIHook isn't even called. The only thing that happens is that it runs the sound program and is then stuck in the infinite 'while 1' loop. Let me know what you think.

@JohnOne Interesting suggestion but I haven't been able to find this registry key for the "Sound" window. I have been able to find the registry key that holds the positions, sizes etc. for all resizable control panel windows:

HKEY_CURRENT_USERSoftwareClassesLocal SettingsSoftwareMicrosoftWindowsShellBagsAllFoldersShellMicrosoft.Windows.ControlPanel

Edited by KeyMs92
Link to comment
Share on other sites

I just testing code A on my pc and it works without any problems. Sound is run and then Hidden. "I donno if the control code works as thats ur code, and my sound is set up differently".

If your sayin its not "hiding" it at all, the only thing i can think of is UR sound panel is called something differently. So many if you could provide the "summary" information from the Autoit Info tool then i can have a look :)

Link to comment
Share on other sites

Oh sorry, my bad, I made a stupid mistake... I won't go into the details because it's too embarrassing. :)

Anyway, it's working now, but as you already mentioned, it still doesn't seem to hide. The visibility of the windows depends on how quick the windows transition, which can differ quite a lot each time. Most of the time, it either gets stuck somewhere (the windows transitions are too slow) or I see a clear flash of the windows. Ocassionally, it will be hidden completely.

I think this is the summary info you need:

>>>> Window <<<<
Title: Sound
Class: #32770
Position: 156, 156
Size: 414, 462
Style: 0x94C800CC
ExStyle: 0x00050101
Handle: 0x00000000000201C0

>>>> Window <<<<
Title: Speaker Setup
Class: NativeHWNDHost
Position: 91, 178
Size: 544, 430
Style: 0x96C80080
ExStyle: 0x00040100
Handle: 0x00000000000B0240
Edited by KeyMs92
Link to comment
Share on other sites

Well i dont know what else 2 suggest :) You cant get any faster detection then a hook.

Maybe A. Replace winsettran with winmove as that function seams to be faster

or b. if your using windows 7

Computer -> System Properties --> Advanced System Settings --> Advanced Tab --> Performance Settings --> Custom.

I only use

Enable Desktop COmposition

Enable Transparent Glass

Show Thumbnails instead of icons

Show Windows Contents while Dragging

Smooth Edges of Screen fonts

Use visual styles on windows and buttons.

I do this for 2 reasons, one for a faster pc without any real visiable different and b no shadows, i think the "flash" u see, might be the shadow of the window.

Link to comment
Share on other sites

OK, I did some thorough testing with the code and came back with this:

$SystemHook = DllCall('user32.dll', 'int', 'RegisterWindowMessageW', 'wstr', 'SHELLHOOK')
GUIRegisterMsg($SystemHook[0], "GUIHook")
DllCall('user32.dll', 'int', 'RegisterShellHookWindow', 'hwnd', GUICreate('Autoit Hook GUI'))

Run("control mmsys.cpl")

sleep(250)

Func GUIHook()
WinMove("[CLASS:#32770]","",-500,-500)
ControlListView("[CLASS:#32770]", "", 1000, "Select", 0)
ControlClick("[CLASS:#32770]", "", 1001)
WinMove("[CLASS:NativeHWNDHost]","",-500,-500)
ControlCommand("[CLASS:NativeHWNDHost]", "", 1303, "SetCurrentSelection", 1)
ControlClick("[CLASS:NativeHWNDHost]", "", "Button1")
ControlClick("[CLASS:NativeHWNDHost]", "", "Button1")
ControlClick("[CLASS:NativeHWNDHost]", "", "Button2")
ControlClick("[CLASS:#32770]", "", 1)
EndFunc

As you can see, I removed some code that didn't seem really necessary (at least for me). I can confirm that the windows are definitely hidden/moved. The moving method indeed seems a little bit faster. I also did a lot of other trial/error which I won't go into, but in any case this is the best I could get. It's not 100% perfect but close to it: it either shows 0 or 1 frame of the windows. BTW, disabling the shadows didn't make a difference. This makes sense because I only see a flash of the window itself.

There's one other problem though: occasionally I get a "Common DLL not working" error, related to the shell. Do you know what causes this? Perhaps it's because I removed some of your code...

Edited by KeyMs92
Link to comment
Share on other sites

well the code you removed is stoppin the code from effecting everything.

Remember i said every time windows does something it sends a message. At the moment your code is picking up every message, and trying to "move sound and control click it".

I did a trail run on what codes effect sound, and its only two messages.

1 for when its created.

1 is for when its actived.

Created is before actived.

So as u see in the code i posted. I have a switch on the Windows Msg, and the code is under the "created" section. If the title is "sound" then it would run.

Link to comment
Share on other sites

From my understanding, a hook isn't a pool. Which is one of the advantages of them, as u dont need a tiny sleep. In my system script i use.

While 1

Sleep(7500000)

WEnd

and hooks pick up every message :)

Slight overkill of Sleep and not really recommended.

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

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...