1、windows.h
-
MessageBox 弹框
#include <stdio.h> #include <windows.h> int main() { //说明:n表示弹框点击按钮的返回的数字。第四个参数表示弹框样式(0~6) int n = MessageBox(0,"内容","标题",6); return 0; }
-
WinExec / ShellExecute 执行、打开
#include <stdio.h> #include <windows.h> int main() { //打开Xshell软件 WinExec("D:\\java\\Xshell\\Xshell.exe",1); ShellExecute(0,"open","D:\\java\\Xshell\\Xshell.exe",0,0,1); //打开百度 ShellExecute(0,"open","http://www.baidu.com",0,0,1); return 0; }
-
FindWindow 查找窗口
#include <stdio.h> #include <windows.h> int main() { HWND h;//定义一个窗口句柄变量,用以存储找到的窗口句柄 h = FindWindow(NULL,"a.txt - 记事本");//获得窗口名为"a.txt - 记事本"的窗口句柄 SendMessage(h,WM_CLOSE,0,0);//调用SendMessage函数,发送一个WM_CLOSE(关闭)消息给wnd窗口句柄。 return 0; }
-
GetCursorPos 获取鼠标坐标
#include <stdio.h> #include <windows.h> int main() { POINT curpos;//一个可以存储点坐标的结构体变量 while (true) { GetCursorPos(&curpos);//获取鼠标位置 printf("%d,%d\n", curpos.x, curpos.y);//打印坐标 Sleep(1000);//睡眠1s } return 0; }