Solved

windows hoooks ! WH_SHELL

Posted on 2004-04-09
13
744 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
  • 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
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.

 
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

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 68
Show Listview image from database (String field) 5 134
Magic Software info 18 138
MS Access from Delphi 31 59
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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