Solved

Starting program

Posted on 1998-09-12
8
132 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
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!

 
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
 
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

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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