Results 1 to 2 of 2

Thread: Minimize other applications?

  1. #1

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172

    Minimize other applications?

    Hi i am working on something new (i hope :P) but i need to get all system processes allong with the ability to hide a certain processes windows (so not the app itself)

    can anyone provide me with C# code? i managed this in Vb.net a long time ago (the process part) but cant seem to find it anymore nor remember it and i cant seem to do it in C# :S
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    here's a quick example i knocked up just for you mate ...
    PHP Code:
            [StructLayout(LayoutKind.Sequential)]
                private 
    struct WINDOWPLACEMENT
            
    {
                
    internal int Length;
                
    internal int flags;
                
    internal int showCmd;
                
    internal Point ptMinPosition;
                
    internal Point ptMaxPosition;
                
    internal Rectangle rcNormalPosition;
            }

            [
    DllImport("user32.dll")]
            private static 
    extern int GetWindowPlacement (int hwndref WINDOWPLACEMENT lpwndpl);
            [
    DllImport("user32.dll")]
            private static 
    extern int SetWindowPlacement (int hwndref WINDOWPLACEMENT lpwndpl);
            private const 
    int SW_MINIMIZE 6;

            private 
    WINDOWPLACEMENT oldWinPlace;
            private 
    WINDOWPLACEMENT newWinPlace;

            private 
    void button1_Click(object senderSystem.EventArgs e)
            {
                
    Process[] procs Process.GetProcesses();
                foreach(
    Process p in procs)
                {
                    
    ListViewItem lvi = new ListViewItem(p.ProcessName);
                    
    lvi.SubItems.Add(p.MainWindowHandle.ToString());
                    
    listView1.Items.Add(lvi);
                }
            }

            private 
    void listView1_Click(object senderSystem.EventArgs e)
            {
                if(
    listView1.SelectedItems.Count != 0)
                {
                    if(
    Convert.ToInt32(listView1.SelectedItems[0].SubItems[1].Text) != 0)
                    {
                        
    int hHandle Convert.ToInt32(listView1.SelectedItems[0].SubItems[1].Text);
                        
    oldWinPlace = new WINDOWPLACEMENT(); // this will hold the window's existing Placement info  ( For restoring the window later ).
                        
    newWinPlace = new WINDOWPLACEMENT();
                        
    GetWindowPlacement(hHandle ref oldWinPlace);
                        
    newWinPlace.showCmd SW_MINIMIZE;
                        
    newWinPlace.Length Marshal.SizeOf(newWinPlace);
                        
    SetWindowPlacement(hHandle ref newWinPlace);
                    }
                }
            }

            private 
    void button2_Click(object senderSystem.EventArgs e)
            {
    // to restore the window to it's original state...
                
    try
                {
                    if(
    listView1.SelectedItems.Count != 0)
                    {
                        if(
    Convert.ToInt32(listView1.SelectedItems[0].SubItems[1].Text) != 0)
                        {
                            
    int hHandle Convert.ToInt32(listView1.SelectedItems[0].SubItems[1].Text);
                            
    SetWindowPlacement(hHandle ref oldWinPlace);
                        }
                    }
                }
                catch(
    Exception ex)
                {
                    
    MessageBox.Show(ex.Message);
                }
            } 
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width