?
Solved

Know Everything

Posted on 2004-10-12
7
Medium Priority
?
247 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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

762 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