Link to home
Start Free TrialLog in
Avatar of andrezzz
andrezzz

asked on

windows hoooks ! WH_SHELL

if i have WH_CBT hool, then I use Str:=TCBTCreateWnd(Pointer(lParam)^).lpcs.lpszName; and TCBTCreateWnd(Pointer(lParam)^).lpcs.hwndParent

But when I use WH_SHELL then this str is empty ? why ? how i can get window's name using WH_SHELL ?
Avatar of rbohac
rbohac

have you tried:

Str:=TCBTCreateWnd(lParam)^.lpcs.lpszName; and TCBTCreateWnd(lParam)^.lpcs.hwndParent ?
What is lParam in Your code?

Look there
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/msdn_hooks32.asp

WH_SHELL
Windows calls this hook when actions occur to top-level (that is, unowned) windows. In the case of thread-specific hooks, Windows calls this hook only for windows that belong to the thread. This is a notification-only hook, so the filter function cannot modify or discard the event. The wParam parameter contains the handle to the window; the lParam parameter is not used.
Avatar of andrezzz

ASKER

Result := CallNextHookEx(SysHook, Code, wParam, lParam);
It don't answers my question.

If You call

SetWindowHookEx(WH_SHELL,YourHookProc,...);

then in

YourHookProc
lParam is not used. As stated in my previous post
ASKER CERTIFIED SOLUTION
Avatar of geobul
geobul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I want to get activeted window's name .
i want to get the same value that i got in WH_CBT with TCBTCreateWnd(lParam)^.lpcs.lpszName and TCBTCreateWnd(lParam)^.lpcs.hwndParent . it is imposible ?
lParam is used in WH_SHELL system-wide hooks but it contains different structures depending on code and OS version. See:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Hooks/HookReference/HookFunctions/ShellProc.asp

Regards, Geo
You have to check if the code is HSHELL_WINDOWACTIVATED first and then use wParam (which contains the handle to the window) to get its caption using GetWindowTextLength and GetWindowText APIs, for instance.

Regards, Geo
Try this (I haven't tested this in WH_SHELL callback function though):

function ReadWindowText(h:HWND) : string;
var
 buf : string;
 len : integer;
begin
 try
   len := SendMessage(h,wm_getTextLength,0,0);
   SetLength(buf,len);
   SendMessage(h,wm_getText,len+1,Integer(buf));
   result := buf;
 except
   result := '';
 end;
end;

// and use it this way in WH_SHELL function:
...
Str := ReadWindowText(wParam);

Regards, Geo
thx it works...
nut it isn't the same :
    Str := GetWindowText(wParam, windtext, 255);
???
GetWindowText returns an integer not a string.

GetWindowText(wParam, windtext, 255);
Str := windtext;
ok, but what is difference between Str := windtext; and Str := ReadWindowText(wParam);
 ???
The GetWindowText function copies the text of the specified window's title bar (if it has one) into a buffer. If the specified window is a control, the text of the control is copied. However, GetWindowText CANNOT retrieve the text of a control in another application.