我主要是想当用户点击控制台程序的右上角时,控制台程序不关闭,必须输入指定的字符,控制台才关闭。请高手帮忙!

解决方案 »

  1.   

    重载onclosing函数。
    添加代码:
    e.cancel = true;
      

  2.   

    还有如何使得CTROL+C无效~,.Net控制台有点不爽~
      

  3.   

    winform 测试成功。不知控制台程序为何不行?
      

  4.   

    还有一法:用api,可以把关闭按钮变灰。
      

  5.   

    回复人:Red_angelX(当你XX你会想起谁) ( 五级(中级)) 信誉:100  2007-02-27 17:19:37  得分:0

    还有如何使得CTROL+C无效~,.Net控制台有点不爽~---------------------------------------------------------------------------------
    屏蔽之。
      

  6.   

    to: Qim(莫名-想星星) ( ) 信
    如何把把关闭按钮变灰,能给出代码吗 多谢
      

  7.   

    控制台程序估计不行
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 最新版本:20070212http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  8.   

    用FindWindow查找控制台窗口,用找到后的窗体句柄调用GetSystemMenu,然后调用RemoveMenu把关闭窗体移除后关闭控钮就灰到不可用了.
      

  9.   

    Private Shared SC_CLOSE As Integer = &HF060
        Private Shared MF_BYCOMMAND As Integer = &H0   <DllImport("USER32.DLL")> _
        Private Shared Function _
            GetSystemMenu(ByVal argWnd As IntPtr, ByVal argRevert As Integer) As IntPtr
        End Function    <DllImport("USER32.DLL")> _
        Private Shared Function _
            RemoveMenu(ByVal argMenu As IntPtr, ByVal argPosition As Integer, ByVal wFlags As Integer) As Integer
        End Function调用:
            Dim aoMenu As IntPtr = GetSystemMenu(Me.Handle, 0)
            RemoveMenu(aoMenu, SC_CLOSE, MF_BYCOMMAND)
      

  10.   

    多谢各位 ,按照 hbxtlhx(平民百姓) Qim(莫名-想星星) 两位的方法搞定了,现贴C#代码 [DllImport("User32.dll",EntryPoint="FindWindow")]  
    private  static  extern  int  FindWindow(string  lpClassName,string  lpWindowName);   [DllImport("user32.dll",EntryPoint="GetSystemMenu")]  
    extern  static  IntPtr  GetSystemMenu(IntPtr  hWnd,  IntPtr  bRevert);  
     
    [DllImport("user32.dll",EntryPoint="RemoveMenu")]  
    extern  static  int  RemoveMenu(IntPtr  hMenu,  int  nPos,  int  flags);  
    // // 用API安装事件处理
    // static ConsoleCtrlDelegate newDelegate=new ConsoleCtrlDelegate(HandlerRoutine); /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {    //移除控制台窗口的关闭按钮*************************************************************** string fullPath=@""+System.Environment.CurrentDirectory+"\\Proxy.exe";
    int  WINDOW_HANDLER  =  FindWindow(null,fullPath);  
    IntPtr  CLOSE_MENU=GetSystemMenu((IntPtr)WINDOW_HANDLER,IntPtr.Zero);
    int SC_CLOSE=0xF060;
    RemoveMenu(CLOSE_MENU, SC_CLOSE, 0x0);