Solved

windows hoooks ! WH_SHELL

Posted on 2004-04-09
13
753 Views
Last Modified: 2010-04-05
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 ?
0
Comment
Question by:andrezzz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 6

Expert Comment

by:rbohac
ID: 10790730
have you tried:

Str:=TCBTCreateWnd(lParam)^.lpcs.lpszName; and TCBTCreateWnd(lParam)^.lpcs.hwndParent ?
0
 
LVL 17

Expert Comment

by:mokule
ID: 10790874
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.
0
 

Author Comment

by:andrezzz
ID: 10790905
Result := CallNextHookEx(SysHook, Code, wParam, lParam);
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 17

Expert Comment

by:mokule
ID: 10791102
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
0
 
LVL 17

Accepted Solution

by:
geobul earned 125 total points
ID: 10791156
Hi,

WH_SHELL callback function doesn't receive a pointer to a TCBTCreateWnd structure in lParam. So, your typecast is wrong and I'm surprised that you don't get an AV (access violation) while trying to do so. What code value are you interested in?

Regards, Geo
0
 

Author Comment

by:andrezzz
ID: 10791189
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 ?
0
 
LVL 17

Expert Comment

by:geobul
ID: 10791221
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
0
 
LVL 17

Expert Comment

by:geobul
ID: 10791261
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
0
 
LVL 17

Expert Comment

by:geobul
ID: 10791347
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
0
 

Author Comment

by:andrezzz
ID: 10791413
thx it works...
nut it isn't the same :
    Str := GetWindowText(wParam, windtext, 255);
???
0
 
LVL 17

Expert Comment

by:geobul
ID: 10791720
GetWindowText returns an integer not a string.

GetWindowText(wParam, windtext, 255);
Str := windtext;
0
 

Author Comment

by:andrezzz
ID: 10791748
ok, but what is difference between Str := windtext; and Str := ReadWindowText(wParam);
 ???
0
 
LVL 17

Expert Comment

by:mokule
ID: 10791860
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.

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month5 days, 9 hours left to enroll

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question