Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-20-2001, 02:24 PM
AliHeshmati AliHeshmati is offline
Junior Member
 
Join Date: Jan 2001
Posts: 28
Default How can I find that NOTEPAD is closed or not ?

Hello
First read these codes please :


...
Var wnd: HWND;
...

//#########################################

procedure TVideoForm.FormShow(Sender: TObject);
var
s:string;
begin

s:='Notepad';
Winexec (PChar(s),SW_SHOW);
wnd := FindWindow( 'Notepad', nil );
Windows.SetParent( wnd, VideoForm.handle );
SetWindowPos(wnd,0,0,0,clientwidth,clientheight, SWP_NOZORDER or SWP_SHOWWINDOW);

end;

//#########################################

procedure TVideoForm.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
if Wnd <> 0 then
begin
PostMessage(fWnd1, WM_CLOSE, 0, 0);
CanClose := True;
end
else
CanClose := False;
end;

//#########################################


They are some code in my program , but the question is :
How can I find , If someone close the NOTEPAD (which is inbound my form) ? I mean If someone close the NOTEPAD , I want to My form will be close after that ...
I have NOTEPAD handle , It called WND , but

How to check If it is OPENED or CLOSED in my form ???

Thanx
Sorry about my VERY BAD english
:")

Bob
Reply With Quote
  #2  
Old 01-20-2001, 02:55 PM
Wise Guy Wise Guy is offline
Member
 
Join Date: Jan 2001
Posts: 45
Default RE: How can I find that NOTEPAD is closed or not ?

Hey!
I suggest you can "capture" all the programs from the task list (notice that Notepad is not hidedn there) and see if Notepad is in it! Here is an example unit of how to capture the task list. Look at this code and take whatever you need, modify it and use it in your application! Good Luck! Here is the exmpale unit:

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

Function EnumWindowsProc (Wnd: HWND; lb: TListbox): BOOL; stdcall;
var
caption: Array [0..128] of Char;
begin
Result := True;
if { skip invisible windows }
IsWindowVisible(Wnd) and
{ only process truly top-level windows. GetWindowLong must be used, not
GetParent }
((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or
(HWND(GetWindowLong(Wnd, GWL_HWNDPARENT)) = GetDesktopWindow)) and
{ skip WS_EX_TOOLWINDOW windows }
((GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW) = 0)
then begin
SendMessage( Wnd, WM_GETTEXT, Sizeof( caption ), integer(@caption));
lb.Items.AddObject( caption, TObject( Wnd ));
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
listbox1.clear;
EnumWindows( @EnumWindowsProc, integer( listbox1 ));
end;

procedure TForm1.ListBox1Click(Sender: TObject);
var
theClassname: Array [0..128] of Char;
Wnd: HWND;
tid, pid: DWORD;
begin
With Sender As TListbox Do Begin
If ItemIndex >= 0 Then Begin
Wnd:= HWND(Items.Objects[ itemindex ]);
If Wnd <> 0 Then Begin
Windows.GetClassname( Wnd, theClassname, Sizeof( classname ));
tid := GetWindowThreadProcessID( Wnd, @pid );
label1.caption :=
Format(
'HWND: %8.8x'#13#10+
'Class: %s'#13#10+
'Process ID: %8.8x'#13#10+
'Thread ID: %8.8x',
[Wnd, theClassname, pid, tid] );
End;
End;
End;
end;

end.
Reply With Quote
  #3  
Old 01-21-2001, 03:22 AM
Lapince Lapince is offline
Senior Member
 
Join Date: Jan 2001
Posts: 163
Default RE: How can I find that NOTEPAD is closed or not ?

First, your code is bad : you use FindWindow('Notepad',nil),
to get "your notepad" handle... But if the user had already opened a notepad, you can get this one handle...
I'll think about this problem.
You can do something else : you execute notepad and wait until its termination... But during waiting, you process other messages.
Reply With Quote
  #4  
Old 01-21-2001, 03:23 PM
Wise Guy Wise Guy is offline
Member
 
Join Date: Jan 2001
Posts: 45
Default RE: RE: How can I find that NOTEPAD is closed or not ?

As I wrote before I suggest a code that looks @ the TASKLIST... I don't know what's the problem if NOTEPAD is already opened - it'll show up in the tasklist so you can get your answer... If I made any errors in my code - I'm sorry... but after all I'm trying to help you...
Reply With Quote
  #5  
Old 01-21-2001, 06:16 PM
AliHeshmati AliHeshmati is offline
Junior Member
 
Join Date: Jan 2001
Posts: 28
Default FINALLY ...

Thanx Everyone ...

But finally I found REPLY to my QUESTION my self.
There is a function within a Timer :

if not IsWindowVisible(NotepadHandel) then
Form.Close;


That's it all.

Bye
Reply With Quote
  #6  
Old 01-22-2001, 08:49 AM
Lapince Lapince is offline
Senior Member
 
Join Date: Jan 2001
Posts: 163
Default RE: FINALLY ...

I'm happy for you, but I hope you're aware that you are actually doing a mistake which can be source of bug
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 08:56 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.