自学MFC三天,从网上也找了很多的资料,实现了点击某个程序中的CALL按钮的功能
(用spy++ 来查询相关按钮的句柄、TITLE等)
代码如下:
void CqqView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
::CWnd *pWnd;
pWnd = CWnd::FindWindow(NULL,_T("XXXXXX"));
HWND callHwnd = pWnd->GetSafeHwnd();
callHwnd = pWnd->m_hWnd;
//::EnumWindows((WNDENUMPROC)EnumWindowsProc,1);
HWND hb=::FindWindowEx(callHwnd,NULL,NULL,_T("63055087"));
if(hb == NULL)
{
MessageBox(_T("Error"));
//hb = (HWND)000206B4;
}
else
{
HWND hcallbutton = ::FindWindowEx(hb,NULL,NULL,_T("call"));
if(hcallbutton == NULL)
{
MessageBox(_T("Error"));
}
else
{
/*::CWnd * windowcall = CWnd::FromHandle(hcallbutton);
windowcall->SetWindowTextW(_T("call"));*/
while(true)
{
::SendMessage(hcallbutton, WM_LBUTTONDOWN,NULL,NULL);
::SendMessage(hcallbutton, WM_LBUTTONUP,NULL,NULL);
Sleep(30000);
}
/*UINT DlgID = ::GetDlgCtrlID(m_hWnd);
::PostMessage(hb, WM_COMMAND, DlgID|BN_CLICKED<<16,(LPARAM)hb);*/
}
}
//::ShowWindow(*pWnd,SW_SHOWMAXIMIZED);
//::UpdateWindow(*pWnd);
CView::OnLButtonDown(nFlags, point);
}