Detect "Minimize" and "Autostart"
-
Hi CPs! I'm currently writing my first application that uses a NotifyIcon and everything works fine except the following two things. 1. I want to hide the NotifyIcon as long as the main form of my application isn't minimized. But I'm not sure how to detect the "Minimize event" as their is no such event or I'm to stupid to find it. So I thought about catching the Resize event of my form and querying the WindowState property there. Would this work or is there a better way? 2. I want to hide the main form of my application and only display the NotifyIcon if my application was started by Windows Autostart, whereas the main form should by shown if the user "normally" starts the application. Is their any way to detect this? THX in advance
-
Hi CPs! I'm currently writing my first application that uses a NotifyIcon and everything works fine except the following two things. 1. I want to hide the NotifyIcon as long as the main form of my application isn't minimized. But I'm not sure how to detect the "Minimize event" as their is no such event or I'm to stupid to find it. So I thought about catching the Resize event of my form and querying the WindowState property there. Would this work or is there a better way? 2. I want to hide the main form of my application and only display the NotifyIcon if my application was started by Windows Autostart, whereas the main form should by shown if the user "normally" starts the application. Is their any way to detect this? THX in advance
Stefan Troschütz wrote: But I'm not sure how to detect the "Minimize event" as their is no such event or I'm to stupid to find it. Here is a simple way to check to see if your application is being Minimized. What you are going to do is simply override the WndProc and check for a few message values:
int WM\_SYSCOMMAND = 0x0112; int SC\_MINIMIZE = 0xF020; protected override void WndProc(ref Message m) { if(m.Msg == WM\_SYSCOMMAND) { if(((int)m.WParam & 0xFFF0) == SC\_MINIMIZE) { MessageBox.Show("I'm being minimized"); } } base.WndProc(ref m); }
- Nick Parker
My Blog | My Articles -
Stefan Troschütz wrote: But I'm not sure how to detect the "Minimize event" as their is no such event or I'm to stupid to find it. Here is a simple way to check to see if your application is being Minimized. What you are going to do is simply override the WndProc and check for a few message values:
int WM\_SYSCOMMAND = 0x0112; int SC\_MINIMIZE = 0xF020; protected override void WndProc(ref Message m) { if(m.Msg == WM\_SYSCOMMAND) { if(((int)m.WParam & 0xFFF0) == SC\_MINIMIZE) { MessageBox.Show("I'm being minimized"); } } base.WndProc(ref m); }
- Nick Parker
My Blog | My Articles -
You could add a parameter to the autostart shortcut and check for it when the program starts. Or check the TickCount. If it's really low, the system was just started ;)
-
You could add a parameter to the autostart shortcut and check for it when the program starts. Or check the TickCount. If it's really low, the system was just started ;)
The possibility with the command line parameter came to my mind too shortly after posting. Guess I will use it, cause the TickCount may be a bit imprecise :). THX