I'm working on a hooking application. I am able to hook on XPs system calculator. I can make it function using a separate application
(similar in UI, since I manually copied the entire sys calc UI). My problem right now, is I can't update my own edit box in real time
(Or once I click my app, system calc's edit box updates but not my edit box). My idea is to use ON_MESSAGE but I don't know how to make it loop like what a WindowProc could do
(Where I placed my button clicks, ::PostMessage(hwnd, WM_LBUTTONDOWN, 0, 0); ::PostMessage(hwnd, WM_LBUTTONUP, 0, 0);
). Or do you have any idea on how I can loop within my process so that all I have to do is get and display data from sys calc to my app? I'm a beginner.... :) So please, somehow, provide some codes. In additon, I tried to place my
UpdateEditBox()
code within the
WindowProc()
together with
PostMessage()
s but it will cause a Stack Overflow.
Some parts of my code:
=================================================================
BEGIN_MESSAGE_MAP(CCalcHookExDlg, CDialog)<br />
ON_MESSAGE(UWM_HOOKLINK, OnHookMessage)
....
END_MESSAGE_MAP()
=================================================================
LRESULT CCalcHookExDlg::OnHookMessage(WPARAM wParam, LPARAM lParam)<br />
{<br />
UpDateEditBox((HWND)lParam);<br />
return 0;<br />
}
=================================================================
void CCalcHookExDlg::UpDateEditBox(HWND hwnd)<br />
{<br />
char str[35];<br />
::SendMessage(this->hwndHookedCalcDisp, WM_GETTEXT, sizeof(str), (long)str);<br />
CString s;<br />
s.Format("%s", str);<br />
this->cwndMyCalcDisp->SetWindowText(s);<br />
s.ReleaseBuffer();<br />
}
=================================================================
LRESULT CCalcHookExDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) <br />
{ <br />
switch(message)<br />
{<br />
case WM_CLOSE:<br />
{<br />
PostQuitMessage(0);<br />
this->DestroyWindow();<br />
break;<br />
}<br />
case WM_COMMAND:<br />
{<br />
CWnd* cWnd = GetFocus();<br />
char className[20];<br />
GetClassName(cWnd->GetSafeHwnd(), (LPTSTR)className,20);<br />
if(strcmp(className, "Button") == 0)<br />
{<br />
HWND hwnd = hr->RetrieveHookedAppHandler(cWnd->GetDlgCtrlID());<br />
::PostMessage(hwnd, WM_LBUTTONDOWN, 0, 0);<br />
::PostMessage(hwnd, WM_LBUTTONUP, 0, 0);<br />
}<br />
m_dummy.SetFocus();<br />
break; <br />
} <br />
}<br />
return CDialog::WindowProc(message, wParam, lParam);<br />
}<br />
=================================================================
I hope, the code will help you figure out what I mean. :)