Saturday, March 13, 2010

Desktop icon disable

1. http://binaryworld.net/Main/CodeDetail.aspx?CodeId=3730

http://forums.techarena.in/software-development/1099472.htm


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace ShowHideDesktop
{
    public partial class Form1 : Form
    {
       
        //[DllImport("user32.dll", EntryPoint = "FindWindowA")]
        //private static extern long FindWindow(string lpClassName, string lpWindowName);

        //[DllImport("user32.dll")]
        //private static extern long GetWindow(long hwnd, long wCmd);

        //[DllImport("user32.dll")]
        //private static extern long ShowWindow(long hwnd, long nCmdShow);

        ////[DllImport("user32.dll")]
        ////private static extern long EnableWindow(long hwnd, long fEnable);

        //[DllImport("user32", EntryPoint = "FindWindowExA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]

        //public static extern long FindWindowEx(long hWnd1, long hWnd2, string lpsz1, string lpsz2);

        //[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]

        //public static extern long SetWindowPos(long hWnd, long hWndInsertAfter, long X, long Y, long cx, long cy, long wFlags);

        //[DllImport("User32.dll")]
        //public static extern int MessageBox(int h, string m, string c, int type);

        [DllImport("User32.dll")]
        public static extern int FindWindow(string lpClassName, string lpWindowName);

        [DllImport("User32.dll")]
        public static extern Int32 SendMessage(int hWnd, int Msg,  int wParam, int lParam);

        [DllImport("user32.dll")]
        static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
       
        void ShowDesktopIcons(bool show)
        {
            IntPtr hWnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Progman", null);
            if (show)
                ShowWindow(hWnd, 5);
            else
                ShowWindow(hWnd, 0);
        }



        public Form1()
        {
            InitializeComponent();
        }

        private void showIconcheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (showIconcheckBox.Checked)
            {
                //  ShowHideDesktopIcons(true);
                ShowDesktopIcons(true);

            }
            else
                ShowDesktopIcons(false);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Process p = new Process();

            p.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System);

            p.StartInfo.FileName = "taskmgr.exe";

            p.StartInfo.CreateNoWindow = true;

            p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

            p.Start();

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {

            const int WM_CLOSE = 0x0010;

            int taskManager = FindWindow("#32770", "Windows Task Manager");

            SendMessage(taskManager, WM_CLOSE, 0, 0);

        }


        //void ShowDesktopIcons(bool bVisible)
        //{
        //    ShowWindow(GetWindow(FindWindow("Progman", "Program Manager"), GW_CHILD),
        //    (bVisible ? SW_SHOW : SW_HIDE));
        //}

        /////
        ///// method for handling the showing/hiding of the desktop icons
        /////

        /////
condition: show or hide
        ///// true/false
        //public bool ShowHideDesktopIcons(bool show)
        //{
        //    try
        //    {
        //        //get a handle to the desktop ("Progman")
        //        long winHandle = FindWindowEx(0, 0, "Progman", null);

        //        //determine if we're showing or hiding
        //        switch (show)
        //        {
        //            case true:
        //                ShowWindow(winHandle, 0);
        //                break;
        //            case false:
        //                ShowWindow(winHandle, 5);
        //                break;
        //        }
        //        return true;
        //    }
        //    catch (Win32Exception ex)
        //    {
        //      //  MessageBox.Show(ex.ToString());
        //        return false;
        //    }

        //}

    }
}

Disable network...
1. http://www.eggheadcafe.com/community/aspnet/2/10068229/how-to-disconnect-the-int.aspx
2. http://lamahashim.blogspot.com/2010/03/disabling-network-using-c.html
3. http://www.codeguru.com/forum/showthread.php?t=328228&highlight=internethangup
4. http://www.debugging.com/bug/4715

No comments: