使用c/c++操作qq界面demo。根据鼠标的位置动态的跳动位置。

引入相关函数库
通过HWND操作qq句柄。
获取客户端界面句柄工具,可以前往主页免费下载

#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <time.h>			//引用time函数库

void main()			//主程序
{
	
	
	HWND win = FindWindowA("TXGuiFoundation", "QQ");		//获取qq界面的句柄
	if(win==NULL)		//如果句柄是空的,表示当前句柄没有找到
	{
		printf("qq玩失踪");		//输出语句
		ShellExecuteA(0, "open", "\"F:\\QQ\\Bin\\QQScLauncher.exe\"", 0, 0, 0);		//执行一个shell命令
		Sleep(2000);			//休息两秒等待qq启动
	}
	win = FindWindowA("TXGuiFoundation", "QQ");
	while(1)
	{
		POINT pt;		//定义一个位置变量
		pt.x = pt.y = 0;		//初始化x轴与y轴
		//GetCursorPos(&pt);
		GetCursorPos(&pt);			//获取鼠标的位置,放入pt
		printf("\n鼠标x轴=%d############鼠标y轴=%d", pt.x, pt.y);
		// SetWindowPos(win, 0, pt.x + 10, pt.y + 10, 0, 0, 1);
		


		time_t ts;		//定义了一个ts的变量
		unsigned int num = time(&ts);		//通过time函数获取一个数字放入
		srand(num);		//随机数
		int data = rand() % 4;		//除以4求余。得到一个1到4的数字
		printf("%d", data);
		switch (data)			//分别对1到4做不同的处理
		{
		case 0:
			SetWindowPos(win, NULL, pt.x -300, pt.y -300, 500, 400, 0);
			break;
		case 1:
			SetWindowPos(win, NULL, pt.x -300, pt.y + 300, 500, 400, 0);
			break;
		case 2:
			SetWindowPos(win, NULL, pt.x + 300, pt.y - 300, 500, 400, 0);
			break;
		case 3:
			SetWindowPos(win, NULL, pt.x + 300, pt.y + 300, 500, 400, 0);
			break;
			
		}
		Sleep(200);		//休息0.2秒
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

languageStudents

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值