Permanently disable Windows Aero using vb.net - 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)

Related

Show hidden application on trying to launch a new instance of a single instance application

I'm working on a single instance application in VB.NET that goes hidden when we minimize the form:
Private Sub Form_Resize(sender As Object, e As EventArgs) Handles Me.Resize
If Me.WindowState = FormWindowState.Minimized Then
Me.Visible = False
End if
End Sub
Then, if I try to launch it again, it doesn't open because it is already running (so far, so good).
Is it possible to make it just visible on this stage? I mean, can I just make the application visible if I try to launch it when it's already running?
I suppose this can be done because there are some applications with this exact behavior.
In your WinForms project properties select "View Application Events" (My Project -> Application -> View Application Events). From there you can see the events that get fired at the start and end of your application. One of which is the StartupNextInstance event handler. In here you should be able to make your form visible again.
Per docs:
A single-instance application raises the StartupNextInstance event when you attempt to restart the application when it is already active. When a single-instance application starts for the first time, it raises the Startup event. For more information, see Startup.
StartupNextInstance Documentation

How can I handle application startup without using default form mybase.load

I am having trouble figuring out how to run code on application startup. The scenario is, I need to check if a user setting exists, if it does not, then I need to open a company configuration form. I tried creating a module to store application level events, but get an error:
BC31418 Visual Basic AND VB.NET in modules must specify a 'WithEvents' variable qualified with a single identifier.
Module ApplicationEvents
Private Sub MyApplication_Startup(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
If My.Settings.xmlpath = "" Then
Dim f As New CompanySetup()
f.ShowDialog()
f.Dispose()
End If
End Sub
End Module
I really do not want to put the IF statement into the default form mybase.load handler, since this application is in early stages, and the default form may change, leading me to have to move this code around. Any help on this error, or suggestions of how to get the IF statement to occur on application startup without tying it into a sub on the default form would be greatly appreciated.
Get rid of that module. Open the Application page of the project properties and click the View Application Events button. That will open the proper code file in which to create a Startup event handler. You can do that using the second and third drop-downs in the Navigation Bar at the top of the code window.

Progress bar value events not reacting to value

I have used a timer, a progress bar and incremented the value by 2 on each timer tick. After that, "Main" should load, but it doesn't. Why? I did use a tracepoint which said the value was 100 and then the program exited with code 0.
Public Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
ProgressBar1.Increment(2)
If ProgressBar1.Value = 100 Then
Main.Show()
Me.Close()
End If
End Sub
Presumably you are using the Application Framework and you have selected the form that has that timer as the Startup object and you have the Shutdown mode set to the When startup form closes option (these are all options on the Application tab of the project properties designer window). I suspect that is the case because those are the default settings for a new VB WinForm application project. When you have your project configured that way, the application will automatically close when the startup form closes. Therefore, when you call Me.Close() on the first form, the application terminates immediately, even when it has already shown another form. One way to correct it is to change the Shutdown mode to the When last form closes option.

close form when application loses focus

My form is displayed as TopMost on my application. The problem I have is that whenever I minimize my application or it loses focus, the form remains displaying. I want to be able to minimize my application or move to another and also hide or close my form. Once the application regains the focus, then unhide or open the form again.
Here is what I worked out on the form's closing event:
Private Sub frmNavigation_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Static Minimize As Boolean
If Minimize = True Then
e.Cancel = True
Me.Hide()
End If
End Sub
I tried using the same code in the applications WindowDeactivate event but nothing happens.
You do not show how you create the instance of your frmNavigation. I am assuming that you are using the Show Method, so just use the version of Show that you pass in the top level window. That will assign the owner of the form, it will then stay on top of your Main Form and minimize and restore with it also. If this doesn't work please show how you are creating and showing your form.
frmNavigation.Show(Me)
I was able to find an answer to the question. MSDN had an article on this very issue.
it can be found here: http://support.microsoft.com/kb/186908#appliesto

Winforms: Closing a program to system tray

'This is the event that is fired as the application is closing, whether it
'be from a close button in the application or from the user
'clicking the X in the upper right hand corner
Private Sub Form1_FormClosing(sender as Object, e as FormClosingEventArgs) Handles Form1.FormClosing
'What we will do here is trap the closing of the application and send the application
'to the system tray (or so it will appear, we will just make it invisible, re-showing
'it will be up to you and your notify icon)
'First minimize the form
Me.WindowState = FormWindowState.Minimized
'Now make it invisible (make it look like it went into the system tray)
Me.Visible = False
End Sub
Hello again Stackoverflow!
Im trying to make an application that when you press X, the program gets put in system tray. But i have like no idea how i'm suppost to do that, so did a search on google and found this code. Only VB2010 (what i use) doesn't like the fourth line. Can anybody give me a quick tutorial on this, and make this work in VB 2010?
By the way, i will most likely use VB only tonight, just to make one application. So im not thinking of learing the whole language.
It looks like you found code over here Dream.In.Code: Minimize To System Tray
Did you "keep" reading the rest of the messages?
You need to add:
e.Cancel = True
to your FormClosing event or else the program just ends. Also, you need to add the NotifyIcon component and a ContextMenuStrip.