Hooking wm_activate message

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,

I am trying to develop user windows tracking (i.e what things he has been doing since logged in). For this i thought to hook the Windows Activate event and read the Windows Title to save the information.

The entire code is being written in delphi. However, I am not getting proper hooking.

here is the code for registering the hook
<div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px <table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="border-right:1px solid gray;font-family:Courier New;font-size:11px;background-color:rgb(238, 238, 238);padding-right:5px;padding-left:10px;width:5px;color:gray;text-align:right;vertical-align:top <col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap <tbody><tr><td><nobr>1</nobr></td><td><font style="font-size:11px   CurrentHook := SetWindowsHookEx(WM_ACTIVATE, ptrHookProcAdd, hndDllInstance, </font><font style="color:blue 0</font><font style="font-size:11px ); </font></td></tr><tr><td><nobr>2</nobr></td><td style="background-color:rgb(247, 247, 247)   DllPrSetHookHandle(CurrentHook); //setting the currenthook handle to the dll having callback method for hookchain
</td></tr></tbody></table>
and here is the Hook (callback method which is written in separate DLL) code which i am using just to test whether i am receiving proper values or not
<div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px <table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="border-right:1px solid gray;font-family:Courier New;font-size:11px;background-color:rgb(238, 238, 238);padding-right:5px;padding-left:10px;width:5px;color:gray;text-align:right;vertical-align:top <col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap <tbody><tr><td><nobr>1</nobr></td><td><font style="font-weight:bold;color:navy function</font><font style="font-size:11px fnGlobalWindowsActivateHook (code:Integer; wParam:Word; lParam:LongWord): LongWord; stdcall; </font></td></tr><tr><td><nobr>2</nobr></td><td style="background-color:rgb(247, 247, 247) <font style="font-weight:bold;color:navy begin</font><font style="font-size:11px  </font></td></tr><tr><td><nobr>3</nobr></td><td>  AssignFile(txtFile, <font style="color:blue E:aleetrackerTest11.txt</font><font style="font-size:11px ); </font></td></tr><tr><td><nobr>4</nobr></td><td style="background-color:rgb(247, 247, 247)   Rewrite(txtFile); </td></tr><tr><td><nobr>5</nobr></td><td>  Writeln(txtFile, <font style="color:blue hello from callback wParam:[</font><font style="font-size:11px  +IntToStr(wParam)+</font><font style="color:blue ] - lParam:[</font><font style="font-size:11px +IntToStr(lParam)+</font><font style="color:blue ] - code:[</font><font style="font-size:11px  + IntToStr(code) + </font><font style="color:blue ]</font><font style="font-size:11px ); </font></td></tr><tr><td><nobr>6</nobr></td><td style="background-color:rgb(247, 247, 247)   CloseFile(txtFile); </td></tr><tr><td><nobr>7</nobr></td><td>  <font style="font-weight:bold;color:navy if</font><font style="font-size:11px  code < </font><font style="color:blue 0</font><font style="font-size:11px  </font><font style="font-weight:bold;color:navy then</font><font style="font-size:11px  </font></td></tr><tr><td><nobr>8</nobr></td><td style="background-color:rgb(247, 247, 247)   <font style="font-weight:bold;color:navy begin</font><font style="font-size:11px  </font></td></tr><tr><td><nobr>9</nobr></td><td>    fnGlobalWindowsActivateHook := CallNextHookEx(CurrentHook, code, wParam, lParam); </td></tr><tr><td><nobr>10</nobr></td><td style="background-color:rgb(247, 247, 247)     Exit; </td></tr><tr><td><nobr>11</nobr></td><td>  <font style="font-weight:bold;color:navy end</font><font style="font-size:11px ; </font></td></tr><tr><td><nobr>12</nobr></td><td style="background-color:rgb(247, 247, 247) <font style="font-weight:bold;color:navy end</font><font style="font-size:11px ; </font></td></tr></tbody></table>
Accoding to documentation, i should be receiving WA_ACTIVE or WA_CLICKACTIVE in wParam but the problem is that I am always getting 0 value in wParam and i am getting lParam some long number which is definitely not the window handle (since its always changing for the same window).

What thing i am missing .. :( ? can someone guide?

P.S:
I appologize if you people says that its not delphi forum. But the Hooking code and basic concept is native win32. So i kindly request you to help me in this.
<hr class=sig>Software Engineer

View the full article
 
Back
Top