Link to home
Start Free TrialLog in
Avatar of mmilan
mmilan

asked on

Starting program

How can I detect when some Windows application was started?
Can you send source code, please?
Avatar of duke_n
duke_n

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;

Avatar of mmilan

ASKER

I want to detrect all programs. I want to get a name of strted program!
ASKER CERTIFIED SOLUTION
Avatar of viktornet
viktornet
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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
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.

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

do you wanna build a task manager or a process viewer?
Black Death.