Solved

windows hoooks ! WH_SHELL

Posted on 2004-04-09
13
735 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now