0 Basic Reverse Engineering 40_win32_14_ Enumeration Window _ Simulate mouse keyboard

Source: Internet
Author: User

1 Find Windows 1.1 code case
Finds the specified window TCHAR Sztitle[max_path] = {0};            HWND hwnd =:: FindWindow (Text ("#32770"), Text ("Flying Pigeon Biography IP Messenger"));     if (hwnd! = NULL) {//Modify Window Caption:: SetWindowText (hwnd, "new Window caption");        } else {:: MessageBox (Null,text ("Window not Found"), TEXT ("[ERROR]"), MB_OK);          }//Window control TCHAR Sztitle[max_path] = {0};            HWND hwnd =:: FindWindow (Text ("#32770"), Text ("Flying Pigeon Biography IP Messenger"));         if (hwnd! = NULL) {typedef void (WINAPI *pswitchtothiswindow) (Hwnd,bool);         Pswitchtothiswindow Switchtothiswindow;          Hmodule huser32=loadlibrary ("user32.dll");                       switchtothiswindow= (Pswitchtothiswindow) GetProcAddress (HUser32, "Switchtothiswindow");     Switch window Switchtothiswindow (hwnd,false);    Sleep (3000); Close window:: SendMessage (hwnd,wm_close,0,0);} else{:: MessageBox (Null,text ("Window not Found"), TEXT ("[ERROR]"), MB_OK);} 
2 Find child Windows 2.1 use the FindWindowEx () function to find
TCHAR szTitle[MAX_PATH] = {0};      HWND hwnd = ::FindWindow(TEXT("#32770"),TEXT("飞鸽传书  IP Messenger"));        if(hwnd != NULL)        {           //查找子窗口     HWND hEdit = FindWindowEx(hwnd,NULL,"Edit","");     //设置标题      ::SetWindowText(hEdit,"文本框新的标题");       //修改内容      ::SendMessage(hEdit,WM_SETTEXT,0,(LPARAM)"新的内容");   }       else        {           ::MessageBox(NULL,TEXT("窗口没有找到"),TEXT("[ERROR]"),MB_OK);    }       
2.2 Using resource ID to find
TCHAR szTitle[MAX_PATH] = {0};HWND hwnd = ::FindWindow(TEXT("#32770"),TEXT("飞鸽传书  IP Messenger"));if(hwnd != NULL){    //查找子窗口    HWND hEdit =::GetDlgItem(hwnd,0x3E9);    //获取内容    ::SendMessage(hEdit,WM_GETTEXT,MAX_PATH,(LPARAM)szTitle);    //修改内容    ::SendMessage(hEdit,WM_SETTEXT,0,(LPARAM)"新的内容");}else{    ::MessageBox(NULL,TEXT("窗口没有找到"),TEXT("[ERROR]"),MB_OK);}
3 Enumerating child window controls
BOOL CALLBACK EnumChildProc(HWND hWnd,LPARAM lParam)            {               TCHAR szTitle[MAX_PATH] = {0};              ::GetWindowText(hWnd,szTitle,MAX_PATH);                 MessageBox(NULL,szTitle,"[子窗口]",MB_OK);                 return true;            }                       VOID EnumChildWindow()          {               TCHAR szTitle[MAX_PATH] = {0};          HWND hWnd = ::FindWindow(TEXT("#32770"),TEXT("飞鸽传书  IP Messenger"));            if(hWnd != NULL)            {               ::EnumChildWindows(hWnd,EnumChildProc,0);       }           else            {               ::MessageBox(NULL,TEXT("窗口没有找到"),TEXT("[ERROR]"),MB_OK);        }       }
4 Enumerate all open windows
BOOL CALLBACK EnumOpenWindowProc(HWND hWnd,LPARAM lParam)           {               TCHAR szTitle[MAX_PATH] = {0};              ::GetWindowText(hWnd,szTitle,MAX_PATH);                 MessageBox(NULL,szTitle,"[窗口]",MB_OK);                      if(strcmp(szTitle,"飞鸽传书  IP Messenger") == 0)           {               MessageBox(NULL,szTitle,"[窗口]",MB_OK);              return FALSE;       }           return TRUE;            } VOID EnumOpenWindows()          {    EnumWindows(EnumOpenWindowProc,NULL);}
5 Simulating mouse clicks
TCHAR szTitle[MAX_PATH] = {0};  RECT r; HWND hwnd = ::FindWindow(TEXT("#32770"),TEXT("飞鸽传书  IP Messenger"));    if(hwnd != NULL)    {       HWND hButton = FindWindowEx(hwnd,NULL,"Button","刷新(&R)");        //获取窗口坐标    ::GetWindowRect(hButton,&r);        printf("%d %d",r.left,r.top);        //设置鼠标的位置    ::SetCursorPos(r.left+10,r.top+10);    Sleep(2000);    //鼠标左键单击    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);//点下左键     mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);//松开左键}   else    {       ::MessageBox(NULL,TEXT("窗口没有找到"),TEXT("[ERROR]"),MB_OK);}   
6 Analog Keyboard Click
  TCHAR Sztitle[max_path] = {0}; RECT R;    HWND hwnd =:: FindWindow (Text ("#32770"), Text ("Flying Pigeon Biography IP Messenger"));    if (hwnd! = NULL) {//hwnd Hbutton = FindWindowEx (hwnd,null, "button", "Refresh (&r)");        HWND hedit =::getdlgitem (HWND,0X3E9);        Get window Coordinates:: GetWindowRect (Hedit,&r);    Set Mouse position:: Setcursorpos (r.left+1,r.top+1);        Sleep (1000); Left mouse button click Mouse_event (mouseeventf_leftdown,0,0,0,0);//Point down Left button mouse_event (mouseeventf_leftup,0,0,0,0);//Release Left button//die    Quasi-keyboard 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);    Sleep (1000);    keybd_event (16,0,0,0);    keybd_event (67,0,0,0);    keybd_event (67,0,keyeventf_keyup,0);    keybd_event (16,0,keyeventf_keyup,0);   } else {:: MessageBox (Null,text ("Window not Found"), TEXT ("[ERROR]"), MB_OK);} 

Keyboard key and Virtual key code comparison table
msdn:https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731 (v=vs.85). aspx
Blog:https://www.cnblogs.com/del/archive/2007/12/07/987364.html

0 Basic Reverse Engineering 40_win32_14_ Enumeration Window _ Simulate mouse keyboard

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.