Solved

Starting program

Posted on 1998-09-12
8
129 Views
Last Modified: 2010-04-06
How can I detect when some Windows application was started?
Can you send source code, please?
0
Comment
Question by:mmilan
8 Comments
 
LVL 1

Expert Comment

by:duke_n
ID: 1339505
I would place on form a timer with interval property:=1(msec).
I tried to do the following in straight way-without a label, but did not succeed.  :

procedure TForm1.Timer1Timer(Sender: TObject);
begin
label1.Caption:=inttostr(FindWindow(nil,'My Computer'));
if not (label1.Caption='0') then
showmessage('You''ve opened My Computer');
timer1.enabled:=false//so it'll show the message only once
end;

0
 

Author Comment

by:mmilan
ID: 1339506
I want to detrect all programs. I want to get a name of strted program!
0
 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
ID: 1339507
Here is an exampleon how to do that witha callback function.....
----------------
interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TFormCallback = class(TForm)
    ListBox1: TListBox;
    Panel1: TPanel;
    BtnTitles: TButton;
    procedure BtnTitlesClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormCallback: TFormCallback;

implementation

{$R *.DFM}

type
  EnumWindowsProc = function (Hwnd: THandle;
    Param: Pointer): Boolean; stdcall;

function GetTitle (Hwnd: THandle; Param: Pointer): Boolean; stdcall;
var
  Text: string;
begin
  SetLength (Text, 100);
  GetWindowText (Hwnd, PChar (Text), 100);
  FormCallBack.ListBox1.Items.Add (
    IntToStr (Hwnd) + ': ' + Text);
  Result := True;
end;

procedure TFormCallback.BtnTitlesClick(Sender: TObject);
var
  EWProc: EnumWindowsProc;
begin
  ListBox1.Items.Clear;
  EWProc := GetTitle;
  EnumWindows (@EWProc, 0);
end;
end.
------------------
Just remmember that this one takes all windows no matter if they can be seen or are just popup menus, dialogs and stuff

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339508
Here is an easier way that takes only the visible windows that do have a name.....
---------------
function GetWinProc(Handle : HWND;  lParam : LPARAM):Boolean;stdcall;
var
  Name : array[0..100]of char;
begin
  if IsWindowVisible(Handle) then
  begin
    GetWindowText(Handle, Name, SizeOf(Name));
    if not(Name = '') then
      form1.listbox1.items.add(Name);
  end;
  Result := true;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  EnumWindows(@GetWinProc,0);
end;
----------
Regards,
Viktor Ivanov
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Expert Comment

by:viktornet
ID: 1339509
Try this.....
//This checks if Notepad is running and if it is then it displays a message
if FindWindow(nil, 'Untitled - Notepad') <> 0 then
  ShowMessage('The application is already running');

Regards,
Viktor Ivanov
0
 
LVL 1

Expert Comment

by:EmmDieh
ID: 1339510
You can use CreateToolhelp32Snapshot, Process32First and
Process32Next to enumerate through the running processes
but these functions are ONLY available in Win95 (?98) not
in NT.
BTW never use the window title to find a window with FindWindow
always use the window-class.

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1339511
Ok, use this then....
var
  H : HWND;
begin
  H := FindWindow('Notepad' nil);
  if H <> 0 then
    ShowMessage('Notepad is already running...');
end;

Regards,
Viktor Ivanov

0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1339512
do you wanna build a task manager or a process viewer?
Black Death.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

867 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

12 Experts available now in Live!

Get 1:1 Help Now