Solved

Starting program

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

 
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

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

623 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