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 ...
随机推荐
- ref:Web Service 渗透测试从入门到精通
ref:https://www.anquanke.com/post/id/85910 Web Service 渗透测试从入门到精通 发布时间:2017-04-18 14:26:54 译文声明:本文是翻 ...
- JSP中常用JSTL用法
使用标签时,需要在jsp文件头加入以下代码: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/cor ...
- ElasticSearch6 报错FORBIDDEN/12/index read-only / allow delete (api)
FORBIDDEN/12/index read-only / allow delete (api) 官方解决方法: curl -XPUT -H "Content-Type: applicat ...
- django添加REST_FRAMEWORK 接口浏览
1.安装rest_framework pip install djangorestframework 2.配置rest_framework ## 将rest_framework加入项目app列表 I ...
- Hibernate 双向一对多的关联映射
双向的一对多的关联关系是单项的一对多和单项的多对一的情况下产生的. 1.设计表结构 虽然关联关系变为双向的一对多,但是我们表结构不会发生改变,只是指向变了. 2.创建student对象 3.创建Gra ...
- 【UOJ #206】【APIO 2016】Gap
http://uoj.ac/problem/206 对于T=1,直接从两端往中间跳可以遍历所有的点. 对于T=2,先求出最小值a和最大值b,由鸽巢原理,答案一定不小于\(\frac{b-a}{N-1} ...
- Matrix-tree定理 spoj HIGH
Matrix-tree定理,给出一个无向图,问求出的生成树方案有多少种方案,利用Matrix-tree定理,主对角线第i行是i的度数,(i,j) 值为i和j之间边的数量,然后删去第一行第一列,利用初等 ...
- 字符串的模板 Manacher kmp ac自动机 后缀数组 后缀自动机
为何scanf("%s", str)不需要&运算 经常忘掉的字符串知识点,最好不加&,不加&最标准,指针如果像scanf里一样加&是错的,大概是未定 ...
- ElasticSearch学习笔记--2、ES相关配置
1.配置文件 ES的配置文件位置:config/elasticsearch.yml可以直接搜索elasticsearch.yml 2.配置远程api访问 network.host: 192.168.1 ...
- python开发_random
和java中的random()函数一样,在python中也有类似的模块random,即随机数 下面是我做的demo 运行效果: ==================================== ...