Solved

Starting program

Posted on 1998-09-12
8
130 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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