Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Detect "Minimize" and "Autostart"

Detect "Minimize" and "Autostart"

Scheduled Pinned Locked Moved C#
tutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stefan Troschuetz
    wrote on last edited by
    #1

    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


    www.troschuetz.de

    N 1 Reply Last reply
    0
    • S Stefan Troschuetz

      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


      www.troschuetz.de

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • N Nick Parker

        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

        S Offline
        S Offline
        Stefan Troschuetz
        wrote on last edited by
        #3

        First problem solved; only one to go THX Nick :)


        www.troschuetz.de

        C 1 Reply Last reply
        0
        • S Stefan Troschuetz

          First problem solved; only one to go THX Nick :)


          www.troschuetz.de

          C Offline
          C Offline
          Christian Pedersen
          wrote on last edited by
          #4

          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 ;)

          S 1 Reply Last reply
          0
          • C Christian Pedersen

            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 ;)

            S Offline
            S Offline
            Stefan Troschuetz
            wrote on last edited by
            #5

            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


            www.troschuetz.de

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups