RunMessageScript from spy

1、执行函数

void CComputerRobotTestDlg::RunMessageScript(CString str)
{
// <00055> 00020540 S message:0x07F3 [用户定义:WM_USER+1011] wParam:00000000 lParam:00000000
CString sInput = str;
int pos1, pos2;
// get wnd handle
pos1 = sInput.Find(_T("> ")) + _tcslen(_T("> "));;
CString strHWND = sInput.Mid(pos1, _tcslen(_T("00020540")));

pos1 = sInput.Find(_T("> ")) + _tcslen(_T("> 00020540 "));
CString strFun = sInput.Mid(pos1, 1);

pos1 = sInput.Find(_T("message:")) + _tcslen(_T("message:"));
CString strmessage = sInput.Mid(pos1, _tcslen(_T("0x07F3")));

pos1 = sInput.Find(_T("wParam:")) + _tcslen(_T("wParam:"));
CString strwParam = sInput.Mid(pos1, _tcslen(_T("00000000")));

pos1 = sInput.Find(_T("lParam:")) + _tcslen(_T("lParam:"));
CString strlParam = sInput.Mid(pos1, _tcslen(_T("00000000")));

HWND hWnd = NULL;
DWORD dMsg;
WPARAM wParam;
LPARAM lParam;

#ifdef _UNICODE
hWnd = (HWND)wcstoul(strHWND, NULL, 16);
dMsg = (DWORD)wcstoul(strmessage, NULL, 16);
wParam = (WPARAM)wcstoul(strwParam, NULL, 16);
lParam = (LPARAM)wcstoul(strlParam, NULL, 16);
#else
hWnd = (HWND)strtoul(strHWND, NULL, 16);
dMsg = (DWORD)strtoul(strmessage, NULL, 16);
wParam = (WPARAM)strtoul(strlParam, NULL, 16);
lParam = (LPARAM)wcstoul(strlParam, NULL, 16);
#endif

if (_T("S")==strFun)
{
::SendMessage(hWnd, dMsg, wParam, lParam);
}
else if (_T("P")==strmessage)
{
::PostMessage(hWnd, dMsg, wParam, lParam);
}

}

2、调用函数

CStdioFileEx file;
if (file.Open(_T("c:\\tmp.txt"), CFile::modeRead))
{
CString str;
while (file.ReadString(str))
{
RunMessageScript(str);
}
}

  

原文地址:https://www.cnblogs.com/carl2380/p/2290412.html