Solved

Know Everything

Posted on 2004-10-12
7
224 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
  • 4
  • 2
7 Comments
 
LVL 26

Expert Comment

by:EddieShipman
Comment Utility
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
Comment Utility
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
Comment Utility
Helllloooo, PeritoX, are you there???

Did my response help you solve your problem?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:peritoX
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
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…

743 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