[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Know Everything

Posted on 2004-10-12
7
Medium Priority
?
251 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
Technology Partners: 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

Technology Partners: 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

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…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

656 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