Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 08-21-2012, 05:49 AM
jamiguel77 jamiguel77 is offline
Senior Member
 
Join Date: Jan 2002
Posts: 1,138
Send a message via MSN to jamiguel77 Send a message via Yahoo to jamiguel77
Wink how to detect when notepad was opened with the file corte.txt

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
Reply With Quote
  #2  
Old 08-22-2012, 01:20 AM
Ouiji Ouiji is offline
Senior Member
 
Join Date: Nov 2001
Location: US of A
Posts: 478
Send a message via AIM to Ouiji
Lightbulb Not sure if this is the "best" way per-se, but it certainly works.

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;
With that, you can obviously add in something like If PoS(corte.txt,window[i].caption) <> 0 then do beep;

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
Attached Files
File Type: txt WindowLists.txt (4.5 KB, 1 views)
__________________
"not quite smart enough to be dumb"
Extended Stats No Longer Available Due To Changes To The Forum.
Reply With Quote
  #3  
Old 08-22-2012, 03:38 PM
jamiguel77 jamiguel77 is offline
Senior Member
 
Join Date: Jan 2002
Posts: 1,138
Send a message via MSN to jamiguel77 Send a message via Yahoo to jamiguel77
Default

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
Attached Files
File Type: txt appsrunning.txt (8.6 KB, 2 views)
Reply With Quote
  #4  
Old 08-25-2012, 03:59 PM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,573
Lightbulb

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;
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 09:51 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.