本文主要是介绍五种循环调戏QQ,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本文用五种循环来移动QQ:1.while 2.do while 3.for 4.goto 5.递归
一.相关API介绍
HWND FindWindowA(LPCTSTR lpClassName, PCTSTR lpWindowName)
lpClassName 是窗口类名,lpWindowName 是窗口标题名,返回值为窗口的句柄(就是一个指向结构体的指针)
这里参数需要窗口类名和窗口标题名,QQ的这些信息怎么获得呢?这里我们要借助一个工具Spy.exe,运行这个工具,接着打开QQ
点击spy.exe 左上脚菜单(显示系统活动窗口),
可以QQ窗体的标题为QQ,窗体类名为TXGuiFoundation
BOOL SetWindowPos(HWN hWnd, const CWnd* pWndInsertAfter, int x, int y,int cx, int cy, UINT nFlags); 这个函数使用比较简单具体可见MSDN或者百度百科
源代码:主程序:
#include "stdafx.h"
#include<Windows.h>
#include"pub.h"
int _tmain(int argc, _TCHAR* argv[])
{int ScreeX = GetSystemMetrics( SM_CXSCREEN ); //获取系统分辨率大小int ScreeY= GetSystemMetrics( SM_CYSCREEN );HWND wnd = FindWindowA("TXGuiFoundation", "QQ");//寻找QQif (wnd == NULL) //空指针避免野指针{printf("please open QQ!\n");}else{printf("start move!");MoveUseWhile(wnd,ScreeX,ScreeY);MoveUseFor(wnd,ScreeX,ScreeY);MoveUseDoWhile(wnd,ScreeX,ScreeY);MoveUseGoto(wnd,ScreeX,ScreeY);MoveUseRecursion(wnd,ScreeX,ScreeY,0);SetWindowPos(wnd, NULL, ScreeX/2-300, ScreeY/2-300, 300, 300, 1);}printf("over \n");system("pause");return 0;
}
程序接口:pub.h
//采用五种循环调戏QQ
#ifndef QQ_TEST_PUB_H
#define QQ_TEST_PUB_Hvoid MoveUseWhile(HWND wnd,int ScreeX,int ScreenY);//ScreeX ScreenY 为分变率大小
void MoveUseFor(HWND wnd,int ScreeX,int ScreenY);
void MoveUseDoWhile(HWND wnd,int ScreeX,int ScreenY);
void MoveUseGoto(HWND wnd,int ScreeX,int ScreenY);
void MoveUseRecursion(HWND wnd,int ScreeX,int ScreenY,int XPos);#endif
具体实现:pub.cpp
#include"stdafx.h"
#include<Windows.h>
void MoveUseWhile(HWND wnd,int ScreeX,int ScreenY)// 水平右移
{int i = 0;while(i<ScreeX-300){SetWindowPos(wnd, NULL, i, 0, 300, 300, 1);//移动窗口Sleep(1);i++;}
}
void MoveUseFor(HWND wnd,int ScreeX,int ScreenY)//垂直下移
{int i = 0;for(i = 0;i<ScreenY;i++){SetWindowPos(wnd, NULL, ScreeX-300, i, 300, 300, 1);Sleep(1);i++;}
}
void MoveUseDoWhile(HWND wnd,int ScreeX,int ScreenY)//水平左移
{int i = ScreeX;do{SetWindowPos(wnd,NULL,i,ScreenY-300,300,300,1);i--;Sleep(1);}while(i>0);
}
void MoveUseGoto(HWND wnd,int ScreeX,int ScreenY)//垂直上移
{int i = ScreenY;
Move:if(i>0){SetWindowPos(wnd, NULL, 0, i, 300, 300, 1);i--;Sleep(1);goto Move;}
}
void MoveUseRecursion(HWND wnd,int ScreeX,int ScreenY,int XPos)//对交线移动
{if(XPos<ScreeX){SetWindowPos(wnd, NULL, XPos, XPos*ScreenY/ScreeX, 300, 300, 1);Sleep(1);MoveUseRecursion(wnd,ScreeX,ScreenY,++XPos);}}
测试:
这篇关于五种循环调戏QQ的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!