系统相关
首页 > 系统相关> > c++ 创建进程设置窗口标题模拟键盘鼠标例子

c++ 创建进程设置窗口标题模拟键盘鼠标例子

作者:互联网

很简单

// 鼠标键盘.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>

void creatqq()
{
STARTUPINFO si = {0};           
PROCESS_INFORMATION pi;        
si.cb = sizeof(si);        

TCHAR qqname[]=TEXT("C:/Users/CSXJJ/Desktop/2.exe");
BOOL res = CreateProcess(    qqname,     
    NULL,     
    NULL,     
    NULL,     
    FALSE,     
    CREATE_NEW_CONSOLE,     
    NULL,     
    NULL, &si, &pi);     
if (res==NULL)
{
MessageBox(NULL,TEXT("进程创建失败"),0,0);
}
Sleep(1000);
}




int main(int argc, char* argv[])
{
creatqq();
HWND hwnd=::FindWindow(TEXT("WTWindow"),TEXT(""));
if(hwnd != NULL)                                
{                                
    //修改窗口标题                            
    ::SetWindowText(hwnd,"新的窗口标题");                            
}                                
else                                
{                                
    ::MessageBox(NULL,TEXT("窗口没有找到"),TEXT("[ERROR]"),MB_OK);                            
}    


HWND htext = FindWindowEx(hwnd,NULL,"Edit","");//获取子窗口 用ex函数
//printf("%d",htext);
//模拟鼠标单击
RECT r; //获得编辑框输出的矩形区域
::GetWindowRect(htext,&r);
::SetCursorPos(r.left+10,r.top+10);
//printf("%d",r.left+10);
//鼠标左键单击
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);//点下左键 
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);//松开左键

//模拟键盘
keybd_event(97,0,0,0);
keybd_event(97,0,KEYEVENTF_KEYUP,0);
Sleep(1000);
keybd_event(66,0,0,0);
keybd_event(66,0,KEYEVENTF_KEYUP,0);

                            
::SendMessage(htext,WM_SETTEXT,NULL,(LPARAM)"4756");;//设置文字
Sleep(1000);
::SendMessage(hwnd,WM_CLOSE,NULL,NULL);
    return 0;
}

 

参照代码

 

标签:htext,鼠标,TEXT,c++,键盘,keybd,hwnd,NULL,event
来源: https://www.cnblogs.com/xuexidememeda/p/12821502.html