控制窗口的关闭按钮方法:
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);
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);
解决方案 »
- 禁止WebBrowser弹出为帮助保护您的安全,您的WEB..
- 一个最简单的程序,竟然会有警告,求助
- 如何实现把客户端文件上传到服务器端指定位置?在线等待...
- 可不可以在安装的时候,记录程序的安装目录?
- C#中的延时应该如何实现呢?
- 做程序员好几年了,有一个很简单的问题一直不明白,望大家指教!
- 想通过GetProcesses()来获得本机所有进程,但是进程性能计数器已禁用,何解?
- c#如何实现sql数据库的备份,还原,压缩等功能?
- 如何将.pdf转化为word文档!!!
- 我的程序在命令行下编译后运行。。。先弹出一个DOS窗口,然后才弹出我的主windows窗体,怎样才能不让它弹dos窗口阿?
- 为什么不能改VS安装的文件夹啊!
- 哪里有套接字资料?
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
);