Solved

Know Everything

Posted on 2004-10-12
7
235 Views
Last Modified: 2010-04-05
I used to program in VB, I used to use a dll ShellHook.dll
Is there anything similar in Delphi? I need to do exactly the same thing, need to know if anything is closed or opened (porgram or folder)
thanks
0
Comment
Question by:peritoX
[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
  • 4
  • 2
7 Comments
 
LVL 26

Expert Comment

by:EddieShipman
ID: 12290153
You can use this DLL with Delphi as well. Register the DLL, then Import the Type Library and it will
create a component that you can drop onto your form and hook up the events.
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 100 total points
ID: 12290492
Here is the sample program included with the DLL converted to Delphi.
Note. I am getting a C000005 error when closing. Not sure what is happening.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleServer, ShellHook_TLB, StdCtrls;

type
  TForm1 = class(TForm)
    cShellHook1: TcShellHook;
    Memo1: TMemo;
    procedure cShellHook1WindowCreated(Sender: TObject; hwnd: Integer);
    procedure cShellHook1WindowDestroyed(Sender: TObject; hwnd: Integer);
    procedure cShellHook1WindowActivated(Sender: TObject; hwnd: Integer);
    procedure FormShow(Sender: TObject);
    procedure cShellHook1ShellWindowActivated(Sender: TObject);
    procedure cShellHook1TaskBarButtonRedraw(Sender: TObject;
      hwnd: Integer);
    procedure cShellHook1TaskManActivated(Sender: TObject; hwnd: Integer);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure cShellHook1LocaleChanged(Sender: TObject; LocaleID: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function GetWndText(hwnd: LongInt):String;
var
  k: LongInt;
  sName: String;
begin
  SetLength(sName,128);
  k := GetWindowText(hwnd, PChar(sName), 128);
  if k > 0 then
    sName := Copy(sName, 1, k)
  else
    sName := 'No caption';
  Result := sName;
end;

function GetWndClass(hwnd: LongInt):String;
var
  k: LongInt;
  sName: String;
begin
  SetLength(sName,128);
  k := GetClassName(hwnd, PChar(sName), 128);
  if k > 0 then
    sName := Copy(sName, 1, k)
  else
    sName := 'No class';
  Result := sName;
end;

function GetLanguageInfo(const dwLocaleID: LongInt; const dwLCType: LongInt): String;
var
  sReturn: String;
  nRet: LongInt;
begin
  SetLength(sReturn,128);
  nRet := GetLocaleInfo(dwLocaleID, dwLCType, PChar(sReturn), 128);
  if nRet > 0 then
    Result := Copy(sReturn, 1, nRet - 1);
end;

procedure TForm1.cShellHook1WindowCreated(Sender: TObject; hwnd: Integer);
begin
  Memo1.Lines.Add('Window created, Caption: '+ GetWndText(hwnd) +
                  ', Class: ' + GetWndClass(hwnd) + ', hwnd = ' +IntToStr(hwnd));
end;

procedure TForm1.cShellHook1WindowDestroyed(Sender: TObject;
  hwnd: Integer);
begin
  Memo1.Lines.Add('Window destroyed, Caption: '+ GetWndText(hwnd) +
                  ', Class: ' + GetWndClass(hwnd) + ', hwnd = ' +IntToStr(hwnd));
end;

procedure TForm1.cShellHook1WindowActivated(Sender: TObject;
  hwnd: Integer);
begin
  Memo1.Lines.Add('Window activated, Caption: '+ GetWndText(hwnd) +
                  ', Class: ' + GetWndClass(hwnd) + ', hwnd = ' +IntToStr(hwnd));
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  cShellHook1.SetShellHook(Application.Handle, RSH_REGISTER_TASKMAN);
end;

procedure TForm1.cShellHook1ShellWindowActivated(Sender: TObject);
begin
  Memo1.Lines.Add('Main Shell Window activated');
end;

procedure TForm1.cShellHook1TaskBarButtonRedraw(Sender: TObject;
  hwnd: Integer);
begin
  Memo1.Lines.Add('Minimized button on taskbar was redrawn, Caption: '+ GetWndText(hwnd) +
                  ', Class: ' + GetWndClass(hwnd) + ', hwnd = ' +IntToStr(hwnd));
end;

procedure TForm1.cShellHook1TaskManActivated(Sender: TObject;
  hwnd: Integer);
begin
  Memo1.Lines.Add('Task manager activated, Caption: '+  GetWndText(hwnd) + ', Class: ' + GetWndClass(hwnd) + ', hwnd = ' + IntToStr(hwnd));
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  cShellHook1.RemoveShellHook;
end;

procedure TForm1.cShellHook1LocaleChanged(Sender: TObject;
  LocaleID: Integer);

  const LOCALE_SENGLANGUAGE = $1001;
var
  sLang: String;
begin
   sLang := GetLanguageInfo(LocaleID, LOCALE_SENGLANGUAGE);
   Memo1.Lines.Add('Language changed to '+ sLang);
end;

end.
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 12358679
Helllloooo, PeritoX, are you there???

Did my response help you solve your problem?
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!

 

Author Comment

by:peritoX
ID: 12372436
I am terribly sorry I didnt reply
truly I didnt try it yet because I dont have delphi installed, I will after like 5 days
anyway, the points are yours. If theres anything I want to ask you, you get an email
Thanks Alot & Sorry For The Delay.
0
 

Author Comment

by:peritoX
ID: 12452907
ok, I got delphi7 and I tried your code this is what I got(Im still newbie

so the problem may be very silly sorry):

Field Form1.cShellHook1 does not have a corresponding component. Remove the

dec?
The FormCreate method referenced by Form1.OnCreate does not exist. Remove

the ref?
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 12464612
You have to import the DLL using Import Type Library and then drop the cShellHook control on your form.

Then create the FormCreate by dbl-clicking it in the Object Inspector and copy/past the code from the FormCreae
above into it.
0
 

Expert Comment

by:instant_new
ID: 12680131
hello EddieShipman,
you seem good at VB and Delphi
please can u help me here:
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21220862.html
0

Featured Post

Independent Software Vendors: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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