Solved

windows hoooks ! WH_SHELL

Posted on 2004-04-09
13
749 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…

734 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