C#WinForm窗體的管理
来源:互联网 发布:dei网络语是什么意思 编辑:程序博客网 时间:2024/04/29 02:52
C#WinForm窗體的管理
1.API申明
//將指定的應用程序窗口標題欄上的標題復制放入緩衝器
[DllImport("user32.dll")]
private static extern int GetWindowText(int hWnd, StringBuilder title, int size);
//列舉出屏幕上的窗口應用程序
[DllImport("user32.dll")]
private static extern int EnumWindows(EnumWindowsProc ewp, int lParam);
//返回應用程序窗口是否顯示
[DllImport("user32.dll")]
private static extern bool IsWindowVisible(int hWnd);
//設置應用程序窗口是否顯示
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
//判斷應用程序窗口是否最小化
[DllImport("user32.dll")]
private static extern bool IsIconic(int hwnd);
//判斷應用程序窗口是否最大化
[DllImport("user32.dll")]
private static extern bool IsZoomed(int hwnd);
//將消息傳給指定窗口
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd,uint Msg,int wParam,int lParam);
[DllImport("user32.dll")]
private static extern int GetWindowText(int hWnd, StringBuilder title, int size);
//列舉出屏幕上的窗口應用程序
[DllImport("user32.dll")]
private static extern int EnumWindows(EnumWindowsProc ewp, int lParam);
//返回應用程序窗口是否顯示
[DllImport("user32.dll")]
private static extern bool IsWindowVisible(int hWnd);
//設置應用程序窗口是否顯示
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
//判斷應用程序窗口是否最小化
[DllImport("user32.dll")]
private static extern bool IsIconic(int hwnd);
//判斷應用程序窗口是否最大化
[DllImport("user32.dll")]
private static extern bool IsZoomed(int hwnd);
//將消息傳給指定窗口
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd,uint Msg,int wParam,int lParam);
2.遍歷窗體
private const int SW_HIDE = 0;
private const int SW_SHOWNORMAL = 1;
private const int SW_SHOWMINIMIZED = 2;
private const int SW_SHOWMAXIMIZED = 3;
private const int SW_SHOWNOACTIVATE = 4;
private const int SW_RESTORE = 9;
private const int SW_SHOWDEFAULT = 10;
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
private bool EvalWindow(int hWnd, int lParam)
{//檢測指定窗體
if (!IsWindowVisible(hWnd))
return true;
StringBuilder strTitle = new StringBuilder(256);
GetWindowText(hWnd, strTitle, 256);
if (strTitle.Length == 0)
return true;
if ((strTitle.ToString() != "ScrnClear"))
{
if (IsIconic(hWnd))
//窗體已最小化時的操作
else if (IsZoomed(hWnd))
//窗體已最大化時的操作
else
//窗體原始大小時的操作
}
return true;
}
private void GetWindows()
{
EnumWindowsProc ewp = new EnumWindowsProc(EvalWindow);
EnumWindows(ewp, 0);
}
private const int SW_SHOWNORMAL = 1;
private const int SW_SHOWMINIMIZED = 2;
private const int SW_SHOWMAXIMIZED = 3;
private const int SW_SHOWNOACTIVATE = 4;
private const int SW_RESTORE = 9;
private const int SW_SHOWDEFAULT = 10;
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
private bool EvalWindow(int hWnd, int lParam)
{//檢測指定窗體
if (!IsWindowVisible(hWnd))
return true;
StringBuilder strTitle = new StringBuilder(256);
GetWindowText(hWnd, strTitle, 256);
if (strTitle.Length == 0)
return true;
if ((strTitle.ToString() != "ScrnClear"))
{
if (IsIconic(hWnd))
//窗體已最小化時的操作
else if (IsZoomed(hWnd))
//窗體已最大化時的操作
else
//窗體原始大小時的操作
}
return true;
}
private void GetWindows()
{
EnumWindowsProc ewp = new EnumWindowsProc(EvalWindow);
EnumWindows(ewp, 0);
}
3.操作窗體 hWnd.ToString()="888"
//取得窗體裝態
if (IsIconic(Convert.ToInt32("888")))
//窗體最小化
else if (IsZoomed(Convert.ToInt32("888")))
//窗體最大化
else
//原始大小
//關閉程序
SendMessage("888", WM_SYSCOMMAND, SC_CLOSE, 0);
//隱藏程序窗體
if (IsWindowVisible("888"))
ShowWindowAsync((IntPtr)Convert.ToInt32("888"), SW_HIDE);
//顯示並最大化窗體
ShowWindowAsync((IntPtr)Convert.ToInt32("888"), SW_SHOWMAXIMIZED);
//顯示並最小化窗體
ShowWindowAsync((IntPtr)Convert.ToInt32("888"), SW_SHOWMINIMIZED);
//設定窗體為原來大小顯示
ShowWindowAsync((IntPtr)Convert.ToInt32("888"), SW_RESTORE);
if (IsIconic(Convert.ToInt32("888")))
//窗體最小化
else if (IsZoomed(Convert.ToInt32("888")))
//窗體最大化
else
//原始大小
//關閉程序
SendMessage("888", WM_SYSCOMMAND, SC_CLOSE, 0);
//隱藏程序窗體
if (IsWindowVisible("888"))
ShowWindowAsync((IntPtr)Convert.ToInt32("888"), SW_HIDE);
//顯示並最大化窗體
ShowWindowAsync((IntPtr)Convert.ToInt32("888"), SW_SHOWMAXIMIZED);
//顯示並最小化窗體
ShowWindowAsync((IntPtr)Convert.ToInt32("888"), SW_SHOWMINIMIZED);
//設定窗體為原來大小顯示
ShowWindowAsync((IntPtr)Convert.ToInt32("888"), SW_RESTORE);
- C#WinForm窗體的管理
- C#Winform编程的基础知识
- C#Winform进度条的使用
- c#winform文本文件的读写
- winform键盘事件的响应(C#,winform)
- [收藏]WINFORM(C#)的键盘测试
- C#WinForm登陆窗体的建立
- 用Visual C#开发WinForm的应用程序
- 用Visual C#开发WinForm的应用程序
- 用Visual C#开发WinForm的应用程序
- 几个常用的WINFORM开发经验(C#)
- C#WinForm系統熱鍵的注冊與解除
- 简单的图片飘C#(Winform)
- Winform(C#)实现XML文件的读取
- 简单的图片飘C#(Winform)
- C#Winform菜单的使用问题总结
- C#winform建立一个共用的数据库连接
- c#--winform 組件 bindingNavigator 的實際應用
- WebGIS网站Show
- 腾讯QQ与MSN的调用代码
- javascript难点
- 艾萨克·阿西莫夫作品
- 嵌入式内功.葵花宝典
- C#WinForm窗體的管理
- 想成为嵌入式程序员应知道的10个基本问题(必须精读)
- ASP.NET2.0 上传图片并为用户创建相应文件夹
- Session对象慎用Delete关键字
- Berkeley DB for C 使用手册
- matrix 类
- linux 常见问题1000个详细解答
- 20071211
- 芯片封装技术知多少