c# 使用api函数 ShowWindowAsync 控制窗体
1.需要匯入 System.Runtime.InteropServices 命名空間
2.宣告 ShowWindowAsync 函數
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(
IntPtr hWnd,
int nCmdShow
);
3.宣告 ShowWindow函數
[DllImport("user32.dll")]
public static extern int ShowWindow(
int hwnd,
int nCmdShow
);
4.宣告API常數定義
//API 常數定義
private const int SW_HIDE = 0;
private const int SW_NORMAL = 1;
private const int SW_MAXIMIZE = 3;
private const int SW_SHOWNOACTIVATE = 4;
private const int SW_SHOW = 5;
private const int SW_MINIMIZE = 6;
private const int SW_RESTORE = 9;
private const int SW_SHOWDEFAULT = 10;
5.上述函數功能相同,都是用來設定視窗大小,不同的是宣告的型態不一樣需轉型。
ShowWindowAsync(this.Handle, SW_MINIMIZE);
ShowWindow((int)this.Handle, SW_MINIMIZE);
6.若是把int 改成IntPtr ,使用ShowWindow就不用轉型,所以在宣告時就可以考慮資料型態,必免轉型所耗的資源。
[DllImport("user32.dll")]
public static extern int ShowWindow(
int hwnd,
int nCmdShow
);
C#完整範例
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace CS_WindowsResize
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//API 常數定義
private const int SW_HIDE = 0;
private const int SW_NORMAL = 1;
private const int SW_MAXIMIZE = 3;
private const int SW_SHOWNOACTIVATE = 4;
private const int SW_SHOW = 5;
private const int SW_MINIMIZE = 6;
private const int SW_RESTORE = 9;
private const int SW_SHOWDEFAULT = 10;
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(
IntPtr hWnd,
int nCmdShow
);
[DllImport("user32.dll")]
public static extern int ShowWindow(
int hwnd,
int nCmdShow
);
private void button1_Click(object sender, EventArgs e)
{
//最小化
ShowWindowAsync(this.Handle, SW_MINIMIZE);
}
private void button2_Click(object sender, EventArgs e)
{
//最大化
ShowWindowAsync(this.Handle, SW_MAXIMIZE);
}
private void button3_Click(object sender, EventArgs e)
{
//還原
ShowWindowAsync(this.Handle, SW_RESTORE);
}
private void button4_Click(object sender, EventArgs e)
{
//最小化
ShowWindow((int)this.Handle, SW_MINIMIZE);
}
private void button5_Click(object sender, EventArgs e)
{
//最大化
ShowWindow((int)this.Handle, SW_MAXIMIZE);
}
private void button6_Click(object sender, EventArgs e)
{
//還原
ShowWindow((int)this.Handle, SW_RESTORE);
}
}
}
转载自:http://www.dotblogs.com.tw/yc421206/archive/2009/07/06/9140.aspx
c# 使用api函数 ShowWindowAsync 控制窗体的更多相关文章
- C# 窗体常用API函数 应用程序窗体查找
常用的处理窗体的API函数如下(注意:API函数必须放在窗体中...): 使用C#语言,要引用DllImport,必须要添加using System.Runtime.InteropServices命名 ...
- Delphi使用Windows API函数AnimateWindow实现窗体特效
{**********************************************************************API函数 AnimateWindow 使用:函数功能:窗 ...
- 通过API函数来控制SQLite数据库增删改查
person类属性有Intenger id,String name,Intenger age,相应的构造方法和set get方法. package com.xh.tx.dao; import and ...
- Delphi 窗体函数 ShowScrollBar 控制滚动条
API函数 函数来源:FUNCTION ulong ShowScrollBar(ulong hwnd,ulong wBar,ulong bShow) LIBRARY "user32.dll& ...
- Windows API 函数列表 附帮助手册
所有Windows API函数列表,为了方便查询,也为了大家查找,所以整理一下贡献出来了. 帮助手册:700多个Windows API的函数手册 免费下载 API之网络函数 API之消息函数 API之 ...
- API函数
1. API之网络函数 WNetAddConnection 创建同一个网络资源的永久性连接 WNetAddConnection2 创建同一个网络资源的连接 WNetAddConnection3 创建同 ...
- WINDOWS API 函数(超长,值得学习)
一.隐藏和显示光标 函数: int ShowCursor ( BOOL bShow ); 参数 bshow,为布尔型,bShow的值为False时隐藏光标,为True时显示光标:该函数的返回值为整型 ...
- Delphi 常用API 函数(好多都没见过)
AdjustWindowRect 给定一种窗口样式,计算获得目标客户区矩形所需的窗口大小AnyPopup 判断屏幕上是否存在任何弹出式窗口ArrangeIconicWindows 排列一个父窗口的最小 ...
- Delphi 常用API 函数
Delphi 常用API 函数 AdjustWindowRect 给定一种窗口样式,计算获得目标客户区矩形所需的窗口大小 AnyPopup 判断屏幕上是否存在任何弹出式窗口 ArrangeIconic ...
随机推荐
- thinkjs项目中使用mongoose需要注意的地方
原文链接thinkjs项目中使用mongoose需要注意的地方 由于thinkjs不支持mongodb的关联模型查询,所以我不得不使用mongoose这个第三方odm. 我有两个选择,一是像我在exp ...
- PHP 中如何正确统计中文字数
PHP 中如何正确统计中文字数?这个是困扰我很久的问题,PHP 中有很多函数可以计算字符串的长度,比如下面的例子,分别使用了 strlen,mb_strlen,mb_strwidth 这个三个函数去测 ...
- ie8浏览器 图片本身问题导致 无法显示图片--- 诡异现象的排查分享
引子: 前段时间 做新版2.0 首页 的时候, 总感觉 新版首页 线上 精彩回顾下的 2张图片颜色怪怪的,当时以为是图片压缩太厉害导致的,由于实在太忙就没太在意!以下 是来自线上 截图: 红色方 ...
- 禁止viewpager不可滚动
import android.content.Context; import android.support.v4.view.ViewPager; import android.util.Attrib ...
- Centos7 安装单节点Torque PBS
Operation system: CentOS 7.3 Torque PBS: torque-6.1.1.1.tar hostname: rfmlab user name: cfd01 1. Ins ...
- hdu 1690 Bus System (有点恶心)
Problem Description Because of the huge population of China, public transportation is very important ...
- bound和unbound方法,类的绑定和非绑定是什么
作者:灵剑链接:https://www.zhihu.com/question/41006598/answer/148994582来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...
- CUDA学习笔记4:CUDA(英伟达显卡统一计算架构)代码运行时间测试
CUDA内核运行时间的测量函数 cudaEvent_t start1; cudaEventCreate(&start1); cudaEvent_t stop1; cudaEventCreate ...
- AHOI2018训练日程(3.10~4.12)
(总计:共90题) 3.10~3.16:17题 3.17~3.23:6题 3.24~3.30:17题 3.31~4.6:21题 4.7~4.12:29题 ZJOI&&FJOI(6题) ...
- 《python学习手册》第34章 异常对象
基于字符串的异常 python在2.6之前可以使用字符串来定义异常,并且是通过对象标识符来匹配的(即通过is 而不是==) myexc = "My excetion string" ...