• 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;
    }

    参照代码

  • 相关阅读:
    LOJ#10106. 「一本通 3.7 例 2」单词游戏
    小木棍(爆搜减枝)
    倍增求lca(模板)
    2018年第九届蓝桥杯C/C++A组省赛(最后一题)
    LOJ#10172. 「一本通 5.4 练习 1」涂抹果酱
    【[APIO/CTSC2007]动物园】状压DP
    c++滚动数组
    状态压缩入门(附经典题目和题解)
    小 M 的算式(dfs)
    P与NP问题详解
  • 原文地址:https://www.cnblogs.com/xuexidememeda/p/12821502.html
Copyright © 2020-2023  润新知