简体   繁体   中英

Permanently disable Windows Aero using vb.net

What I want to do is disable windows aero permanently for the user if he / she clicks a button.

Currently I have this code:

<System.RunTime.InteropServices.DLLImport("dwmapi.dll", PreserveSig:=False)>
Public Shared Sub DwmEnableComposition(bEnable As Boolean)

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    DwmEnableComposition(False)
End Sub

The current problem with this code is... It works, but whenever you exit your application Aero switches back on.

Is there a way to prevent this?

It sounds like in windows 8 aero transparency is disabled by default.

http://www.howtogeek.com/howto/windows-vista/disable-aero-on-windows-vista/

Also, from the link: https://msdn.microsoft.com/en-us/library/windows/desktop/aa969510%28v=vs.85%29.aspx

Disabling DWM composition disables it for the entire desktop. DWM composition will be automatically enabled when all processes that have disabled composition have called DwmEnableComposition to enable it or have been terminated. The WM_DWMCOMPOSITIONCHANGED notification is sent whenever DWM composition is enabled or disabled.

So it sounds to me like you need to leave your program running. You could do something like minimize it to the task tray (as opposed to exiting it ). Who knows, maybe you can even just launch a separate executable that stays running and doesn't show up in the taskbar OR task tray. But you will have to leave the process running.

If you want Aero to be disabled "PERMANENTLY" for the user regardless of whether your app is running or not, then you'll need to identify where this setting lives in the registry and modify that setting.

If you meant that you only want to disable it for your application (meaning that the next time you launch the app, it will be either enabled or disabled based on how it was set when it was last closed), then you will need to store this in a user setting.

Create a new bool setting (user-scope) in the project settings and call it DWM. Then, in the button click event toggle it's value. Apply that value to the setting at runtime.

EDIT: The previous version would have resulted in an always false setting. I've edited the If statements to an If-Else block.

<System.RunTime.InteropServices.DLLImport("dwmapi.dll", PreserveSig:=False)>
Public Shared Sub DwmEnableComposition(bEnable As Boolean)

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If My.Settings.DWM = False THEN 
        My.Settings.DWM = True
    Else
        My.Settings.DWM = False
    End If
    My.Settings.Save()
    DwmEnableComposition(My.Settings.DWM)
End Sub

In the onload or startup event of the form/app, run the code to set true or false

DwmEnableComposition(My.Settings.DWM)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM