我使用了vc知识库上的一个类 CFindKillProcess (EnumProc.cpp),如果你想得到QQ上窗体等资源,可以使用VC以资源的方式打开QQ.exe
void CRecordVCDlg::OnButton2() //自动登陆QQ的方法
{
// TODO: Add your control notification handler code here
HWND hWnd=NULL,hWndChild=NULL,hTemp=NULL;
int childId;
long style=0l;
CFindKillProcess FindProc;
DWORD pid1=FindProc.FindProcess("QQ.exe",TRUE);
//hWnd=::FindWindow(NULL,"QQ用户登录");
BOOL bClassName=TRUE;// show window classname
BOOL bTitle=TRUE;// show window title
BOOL bBare=TRUE;
int count=0;
BOOL bFirstModule = TRUE;
CProcessIterator itp;
for (DWORD pid=itp.First(); pid; pid=itp.Next()) {
// Note: first module in CProcessModuleIterator is EXE for this process
//
TCHAR modname[_MAX_PATH];
CProcessModuleIterator itm(pid);
HMODULE hModule = itm.First(); // .EXE
if (hModule) {
GetModuleBaseName(itm.GetProcessHandle(),
hModule, modname, _MAX_PATH);
// Iterate over all top-level windows in process
//
BOOL bFirstWindow = TRUE;
CMainWindowIterator itw(pid);
for (HWND hwnd = itw.First(); hwnd; hwnd=itw.Next()) {
if (bFirstModule) {
if (!bBare) {