Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 />
       //{{AFX_MSG_MAP(CCalcHookExDlg)<br />
          ON_MESSAGE(UWM_HOOKLINK, OnHookMessage) // user-defined Msg Map<br />

....
//}}AFX_MSG_MAP<br />
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 />
    // momentarily,I substituted the specific handler; sys calc edit box<br />
    // I'll be using hwnd later once I get to  solve the problem<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 />
                // this gets a stored sys calc handler, w/c is editbox<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. :)
Posted
Updated 22-Aug-10 23:54pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900