控制窗口的关闭按钮方法:
public const int MF_ENABLED   = 0x0;
public const int MF_GRAYED    = 0x1;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Label label1;
public const int MF_DISABLED  = 0x2;[DllImport("user32.dll", EntryPoint="GetSystemMenu")]
public static extern IntPtr GetSystemMenu (
IntPtr hwnd,
int bRevert
);[DllImport("user32.dll", EntryPoint="EnableMenuItem")]
public static extern int  EnableMenuItem(
IntPtr hMenu,
int nPosition,
int wFlags
);代码:
IntPtr hSysMenu = GetSystemMenu(this.Handle,0);
//关闭按钮无效
EnableMenuItem(hSysMenu, 0xF060, MF_DISABLED | MF_GRAYED);
//关闭按钮有效
EnableMenuItem(hSysMenu, 0xF060, 0);

解决方案 »

  1.   

    但是在命令行程序中通过this.Handle不能过得运行窗口的句柄。希望再次关心!
      

  2.   

    try:[DllImport("user32.dll", EntryPoint="FindWindow")]
    public static extern IntPtr FindWindow (
    string lpClassName,
    string lpWindowName
     );[DllImport("user32.dll", EntryPoint="GetWindowText")]
    public static extern int GetWindowText (
    IntPtr hwnd,
    StringBuilder lpString,
    int cch
    );
    ///////////////////////
    IntPtr hWnd = FindWindow("ConsoleWindowClass",null);//use the class name
     if(hWnd != IntPtr.Zero){
     StringBuilder text = new StringBuilder(1024);
     GetWindowText(hWnd,text,1024);
     MessageBox.Show(text.ToString());//////////////////////////////How to abtain the class name??
    One way is:IntPtr hWnd = FindWindow(null,"hello");//"hello" is the window text
    if(hWnd != IntPtr.Zero){
       StringBuilder className = new StringBuilder(1024);
       GetClassName(hWnd,className,1024);
       MessageBox.Show(className.ToString());//Got it
      }
    The GetClassName method seems like:
    [DllImport("user32.dll", EntryPoint="GetClassName")]
     public static extern int GetClassName (
     IntPtr hwnd,
     StringBuilder lpClassName,
     int nMaxCount
     );