windows 简单api应用
//调用系统函数 将鼠标移动到相应位置
[DllImport("user32.dll", EntryPoint = "SetCursorPos")]
public extern static bool SetCursorPos(int x, int y);
//获取当前鼠标的绝对位置
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
}
[DllImport("User32")]
public extern static bool GetCursorPos(out POINT p);
//是否显示鼠标箭头
[DllImport("User32")]
public extern static int ShowCursor(bool bShow);
//调用系统函数 模拟鼠标事件函数
[DllImport("user32", EntryPoint = "mouse_event")]
private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); 例如:
private const int MOUSEEVENTF_LEFTDOWN = 0x0002; //模拟鼠标左键按下
private const int MOUSEEVENTF_LEFTUP = 0x0004; //模拟鼠标左键抬起
private const int MOUSEEVENTF_RIGHTDOWN = 0x0008; //模拟鼠标右键按下
private const int MOUSEEVENTF_RIGHTUP = 0x0010; //模拟鼠标右键抬起
private const int MOUSEEVENTF_ABSOLUTE = 0x8000;//鼠标绝对位置
mouse_event(MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE, 0, 0, 0, 0);//点击 其中 int dx, int dy没有效果
[DllImport("user32.dll")]
static extern IntPtr SetActiveWindow(IntPtr hWnd);//激活窗体
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);//把窗体顶层显示
//获取窗体的句柄,其中第一个参数可以为null,第二个参数是任务管理器中“应用程序的 名称”
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string strClass, string strWindow);
//获取窗口的相对的位置 高宽
[DllImport("user32.dll")]
private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect); [DllImport("user32.dll")]
private static extern bool IsZoomed(IntPtr hWnd);//判断窗口最大化,最大化则返回true
//以什么样的方式显示窗体
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); //ShowWindow参数
private const int SW_SHOWNORMAL = 1;
private const int SW_RESTORE = 9;
private const int SW_SHOWNOACTIVATE = 4;
//SendMessage参数
private const int WM_KEYDOWN = 0X100;
private const int WM_KEYUP = 0X101;
private const int WM_SYSCHAR = 0X106;
private const int WM_SYSKEYUP = 0X105;
private const int WM_SYSKEYDOWN = 0X104;
private const int WM_CHAR = 0X102;
ShowWindow(ParenthWnd, SW_RESTORE); //还原窗口
鼠标滚轮事件
[DllImport("user32.dll")]
static extern void mouse_event(int flags, int dX, int dY, int buttons, int extraInfo);
const int MOUSEEVENTF_MOVE = 0x1;
const int MOUSEEVENTF_LEFTDOWN = 0x2;
const int MOUSEEVENTF_LEFTUP = 0x4;
const int MOUSEEVENTF_RIGHTDOWN = 0x8;
const int MOUSEEVENTF_RIGHTUP = 0x10;
const int MOUSEEVENTF_MIDDLEDOWN = 0x20;
const int MOUSEEVENTF_MIDDLEUP = 0x40;
const int MOUSEEVENTF_WHEEL = 0x800;
const int MOUSEEVENTF_ABSOLUTE = 0x8000;
protected override bool ProcessCmdKey(ref Message msg, Keys key)
{
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;
if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
switch (key)
{
case Keys.Down:
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, -100, 0);
break;
case Keys.Up:
mouse_event(MOUSEEVENTF_WHEEL, 0, 0, 100, 0);
break;
}
}
return base.ProcessCmdKey(ref msg, key);
}
windows 简单api应用的更多相关文章
- mfc 调用Windows的API函数实现同步异步串口通信(源码)
在工业控制中,工控机(一般都基于Windows平台)经常需要与智能仪表通过串口进行通信.串口通信方便易行,应用广泛. 一般情况下,工控机和各智能仪表通过RS485总线进行通信.RS485的通信方式是半 ...
- Windows录音API学习笔记(转)
源:Windows录音API学习笔记 Windows录音API学习笔记 结构体和函数信息 结构体 WAVEINCAPS 该结构描述了一个波形音频输入设备的能力. typedef struct { W ...
- 【转】Windows 7 API Internet Connection Sharing(ICS) 与 Wireless Hosted Network构建本地AP
原文:http://hi.baidu.com/ritrachiao/item/bf7715e6bb8cb3a0c10d75be [此刻我要大大地记录一下!] 这个折腾了我好几天的Windows 7 A ...
- Windows录音API学习笔记
Windows录音API学习笔记 结构体和函数信息 结构体 WAVEINCAPS 该结构描述了一个波形音频输入设备的能力. typedef struct { WORD wMid; 用于波形 ...
- Windows Composition API 指南 - 认识 Composition API
微软在 Windows 10中 面向通用 Windows 应用 (Universal Windows Apps, UWA) 新引入了一套用于用户界面合成的 API:Composition API.Co ...
- Windows录音API学习笔记--转
Windows录音API学习笔记 结构体和函数信息 结构体 WAVEINCAPS 该结构描述了一个波形音频输入设备的能力. typedef struct { WORD wMid; 用于波形 ...
- 掉坑日志:Windows Native API与DPI缩放
高DPI显示器越来越普及,软件自然也要适应这个变化,最近实习的时候也遇到了一个关于DPI缩放的问题.因为内部框架的一个控件有BUG,会导致内容的显示出问题,后来实在没办法改成了用Windows Nat ...
- Windows Automation API和自动化测试
https://zhuanlan.zhihu.com/p/22083601\ 感谢轮子哥点赞,这会儿消息扎堆过来了,轮带逛果然不是随便说说的…… 第二篇一个简单的Windows Automation ...
- .NET 6学习笔记(4)——如何在.NET 6的Desktop App中使用Windows Runtime API
Windows Runtime API是当初某软为了区别Win32 API,力挺UWP而创建的另一套Windows 10专用的API集合.后来因为一些原因,UWP没火.为了不埋没很有价值的Window ...
随机推荐
- Menubar
A menubar is a common part of a GUI application. It is a group of commands located in various menus. ...
- PHPstorm自定义快捷键
Ctrl+alt+S 打开设置 PHPstorm 设置 PHPstorm 主题安装 自定义快捷键设置 ·全屏 F11 ·另外一种全屏alt+F11 Database数据库管理 alt+d Termin ...
- ecipse theme
市场里搜“jeeeyul's Eclipse Themes”
- SettingsJDK
迁移时间:2017年5月20日23:38:40 Author:Marydon 1.双击安装,更改安装路径为D:\ProgramFiles\Java\jdk1.7.0_55: 注意事项: 1.1 将 ...
- POJ--2752--Seek the Name, Seek the Fame【KMP】
链接:http://poj.org/problem? id=2752 题意:对于一个字符串S,可能存在前n个字符等于后n个字符,从小到大输出这些n值. 思路:这道题加深了对next数组的理解.next ...
- Linear Algebra Courses
Lecture 1:Demonstrate the columns of a matrix (imagine the vectors) in N-dimension space.How to mult ...
- Rational Rose 2003 逆向工程转换C++源代码成UML类图
主要介绍用户如何使用Rose的逆向工程生成UML模型,并用来进行C++代码的结构分析. Rational Rose可以支持标准C++和Visual C++的模型到代码的转换以及逆向工程.下面将详细地说 ...
- 如何发布开源自己的框架或类库到CocoaPods - 图文讲解
当自己的库已经上传GitHub后,那么如何快速简单的开源自己的库呢? 这里就是介绍如何将自己的类库上传到pods管理库,以便开源所有人都能方便使用. 准备前提: - 项目已上传到GitHub (注意, ...
- scanf/sscanf %[]格式控制串的用法(转)
scanf/sscanf %[]格式控制串的用法 scanf中一种很少见但很有用的转换字符:[...]和[ ^...]. #include<stdio.h> int main() { ch ...
- UltraEdit加入到右键菜单中
http://www.cppblog.com/prayer/archive/2009/02/20/74429.htmlUltraEdit安装好之后,拷贝到其它机器就可以直接使用而无需注册,但少了一个功 ...