您的位置:首页 > 其它

VC获取其他软件控件的内容

2014-10-31 14:54 357 查看
// GetWindowData.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "GetWindowData.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// 唯一的应用程序对象
//CString strTitle = "RGBLPR车牌识别系统 V4.0";
//CString strClass = "Button";
CString strTitle = "过期域名抢注软件1.2——索雅软件(SoYaSoft.com)";
CString strClass = "ListView20WndClass";
CWinApp theApp;

using namespace std;

void MyFindListViewWindow(CString strTitle, CString strClass);

BOOL CALLBACK EnumChildProc(
HWND hwnd,      // handle to child window
LPARAM lParam   // application-defined value
)
{
Sleep(500);
char WindowTitle[100] = { NULL };
GetWindowText(hwnd, WindowTitle, 100);
int nCount = ::SendMessage(hwnd, LB_GETCOUNT, 0, 0);

if (nCount <= 0)
{
cerr << "获取ListBox总行数失败!" << endl;
}
else
{
char szBuf[255];
int nt = 0;
for (int i = 0; i < nCount; i++)
{
nt = (int)::SendMessage(hwnd, LB_GETTEXT, i, (LPARAM)szBuf);
if (nt == LB_ERR)
{
break;
}
cerr << "shuju:" << szBuf << endl;
}
}
//EnumChildWindows(hwnd, (WNDENUMPROC)EnumChildProc, NULL);
if (strlen(WindowTitle) == 0)
{
cerr << "句柄: " << hwnd << endl;
cerr << "标题: " << _T("Emty!") << endl;
char str[100];
memset(str, 0, sizeof(str));
//GetWindowText(hwnd, str, sizeof(str));   //获取控件的TEXT
//SendMessage(hwnd, WM_GETTEXT, 100, (LPARAM)str);
GetClassName(hwnd, str, 100);
cerr << "info: " << str << endl;
cerr << _T("<<<<<<<<<<<<<<<<<<<<") << endl;

return  true;
}
else
{
cerr << "句柄: " << hwnd << endl;
cerr << "标题  " << _T(WindowTitle) << endl;
if (0 == strcmp("打开多幅图像...", WindowTitle))
{
PostMessage(hwnd, WM_LBUTTONDOWN, NULL, NULL);
PostMessage(hwnd, WM_LBUTTONUP, NULL, NULL);
MyFindListViewWindow("打开", "Edit");
}
char str[100];
memset(str, 0, sizeof(str));
//GetWindowText(hwnd, str, sizeof(str));   //获取控件的TEXT
//SendMessage(hwnd, WM_GETTEXT, 100, (LPARAM)str);
GetClassName(hwnd, str, 100);
cerr << "info: " << str << endl;
cerr << _T("********************") << endl;

return  true;
}
EnumChildWindows(hwnd, (WNDENUMPROC)EnumChildProc, NULL);
return true;

}

void MyFindListViewWindow(CString strTitle, CString strClass)
{

HWND hParentWnd = NULL;
HWND hChild = NULL;
hParentWnd = ::FindWindow(NULL, strTitle);
if (hParentWnd == NULL)
{
::AfxMessageBox("查找窗口失败!");
return;
}

//再得到LISTBOX句柄

hChild = FindWindowEx(hParentWnd, NULL, strClass, NULL);
if (hChild == NULL)
{
::AfxMessageBox("查找ListBox失败!");
return;
}

//发消息获取数据显示到我的LISTBOX

int nCount = ::SendMessage(hChild, LB_GETCOUNT, 0, 0);
if (nCount <= 0)
{
::AfxMessageBox("获取ListBox总行数失败!");
//return;
}
char szBuf[100];
ListView_GetItemText(hChild, 0, 0, szBuf, 100);
cerr << szBuf << endl;
//先清空自己的数据
return;
int nt = 0;
for (int i = 0; i < 2; i++)
{
nt = (int)::SendMessage(hChild, LB_GETTEXT, i, (LPARAM)szBuf);
if (nt == LB_ERR)
{
break;
}
cerr << "shuju:" << szBuf << endl;
}
}

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

HMODULE hModule = ::GetModuleHandle(NULL);

if (hModule != NULL)
{
// 初始化 MFC 并在失败时显示错误
if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
{
// TODO:  更改错误代码以符合您的需要
_tprintf(_T("错误:  MFC 初始化失败\n"));
nRetCode = 1;
}
else
{

// TODO:  在此处为应用程序的行为编写代码。
MyFindListViewWindow(strTitle, strClass);

return 0;
HWND myhwnd;
myhwnd = ::FindWindow(NULL, "RGBLPR车牌识别系统 V4.0");
//myhwnd = ::FindWindow(NULL, "打开");
if (NULL == myhwnd)
{
::AfxMessageBox("meiyou");
}
else
{
//MyFindListViewWindow();
::AfxMessageBox("you");
EnumChildWindows(myhwnd, (WNDENUMPROC)EnumChildProc, NULL);
::AfxMessageBox("end");
}
}
}
else
{
// TODO:  更改错误代码以符合您的需要
_tprintf(_T("错误:  GetModuleHandle 失败\n"));
nRetCode = 1;
}

return nRetCode;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: