![]() |
|
#1
|
|||
|
|||
|
hi all, friend i use d7
exist a way for 'detect' when notepad was opened with corte.txt? i think in made a service or trayicon program and read every 5 minutes, but not know if is the best way? thanks |
|
#2
|
|||
|
|||
|
This is a *Very* simple way of doing it, and gives you a ton of options on how you can execute it. Attached you will find a component (Not my code) you can install or clip whats needed, but it will list the captions of the open windows running on the system, including Notepad with the filename. (it also will list most anything else you could want too know) very quickly and with very little resources. Here is about as simple of an example you can write:
Code:
var
Form1: TForm1;
killit:boolean;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
xUp:integer;
begin
killit := false;
WindowList1.Refresh;
pb1.max := WindowList1.Count;
Randomize;
memo1.Lines.Add('Listing out all: ' + Inttostr(WindowList1.Count) + ' Window Captions.');
for i := 1 to WindowList1.Count -1 do begin (* List out the windows *)
if WindowList1.Windows[i].WinCaption <> '' then (* Dont add blanks *)
memo1.Lines.Add(WindowList1.Windows[i].WinCaption); (* List all captions in memo1 *)
xUp := Random(50); (* -\/- *)
if xUp = Random(44) then begin (* Update interface randomly to avoid slowdowns [not even needed] *)
Application.ProcessMessages;
pb1.position := pb1.position +1; (* Show progress [goes so fast you don't see it] *)
if killit = true then break; (* Kill Switch in case of hang *)
end;
end;
end;
I believe that this can be written into a console app (98% sure) and can be called with SW_Hidden by the windows task scheduler, so you do not even have to have a persistent process running. Let me know if you would like me to expand any more. - ouiji
__________________
"not quite smart enough to be dumb" Extended Stats No Longer Available Due To Changes To The Forum.
|
|
#3
|
|||
|
|||
|
i generate the: appsrunning.
of this list i am interested in kill the app: Genkey How To? Other think: i dont, want run on schedule task. i want 'detect' when any external progam open the notepad with the file corte.txt immmediatly show a message. (understand me)? some friends tell me: 'use Hook' but not know how to. any advice? thanks |
|
#4
|
|||
|
|||
|
I wrote this code 7 years ago...
you could hook "on create window event" to use call back, but is to much work to avoid use a simple timer that is light and solve the problem.. but you can't adapt the code if you want and use call back way. create a service application , or create a console application and start it using "hide" parameter Code:
function GetProgramHandle(PartOfTitle: String):longint;
var
WinHandle: hWnd; //handleWindow
TempArray: array[0..254] of Char; //Temporary storage...
TitleStr: String; //Found result
begin
PartOfTitle:=UpperCase(PartOfTitle); //Make input uppercase
WinHandle:=FindWindow(nil,nil); //Zero's the counter
While (WinHandle <> 0) do begin //Begin loop
GetWindowText(WinHandle,TempArray,255);//Read the window name
TitleStr:=TempArray; //Change the result to string
TitleStr:=UpperCase(TitleStr); //Makes it all uppercase
If Pos(PartOfTitle,TitleStr)<>0 then //Compares the result and input,
break //if the same then break loop
Else //Else get next window...
WinHandle:=GetWindow(WinHandle,GW_HWNDNEXT);
End;
If WinHandle <> 0 then
//PostMessage(WinHandle,WM_CLOSE,0,0) //close it...
Result:=WinHandle
Else //Else show message...
result:=0;
// ShowMessage('Error: Application not found');
end;
//put a timer , enable it and in the event paste this code
procedure TForm1.Timer1Timer(Sender: TObject);
var
wnd: HWND;
begin
//put here the part of your "title" of your window to get the handle
wnd := GetProgramHandle('corte.txt - bloco de notas'); //portuguese windows
if wnd=0 then
wnd := GetProgramHandle('corte.txt - notepad'); //english windows
if wnd <> 0 then
begin
beep;
//showmessage('found it');
end
end;
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|