Solved

Apps running...

Posted on 1998-02-11
13
134 Views
Last Modified: 2010-04-04
I´m developing an application will execute in Win95 and WindowsNT. I need some function (or component) to identify all programs running in the computer. This function should be able in both platforms. Thanks!!
PD: My english is not good, sorry!!
0
Comment
Question by:Marcelito
  • 6
  • 4
  • 3
13 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1359037
You can use EnumWindows
0
 
LVL 4

Expert Comment

by:d003303
ID: 1359038
EnumWindows will return all windowed applications. Do you want to identify all running programs or all running processes (like the applications/processes page on NT task manager) ?
0
 

Author Comment

by:Marcelito
ID: 1359039
Ok! I need identify all programs running, but if I can identify all processes also is better. I have a primary solution, but not work properly in some cases. Thanks!!
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1359040
Can you be more specific about what is the porblem with your solution
0
 

Author Comment

by:Marcelito
ID: 1359041
When I execute the program in IDE, it´s work (sometimes I have an Access Violation error when close the main form). When I execute the .exe file, the program perform an invalid operation, and Windows close the task. I´m confused!!

PD: I´m not using components, only API functions. THANKS!!
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1359042
Post your code and we'll see why it fails

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Marcelito
ID: 1359043
Here is the code. Good Luck MikeP!!

 

unit Unit1;

interface

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

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

var
  Form1: TForm1;


implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);

var hWnd, hWndAux:integer;
    spBuffer:pChar;
    sWndTitle, sAux:string;
    encontre: boolean;
    nTitleSize,comp: integer;

begin
    nTitleSize:=0;
    hWnd:= 0;
    encontre:= false;
    spBuffer:='';
    hWnd:=GetTopWindow(0);
    nTitleSize:= GetWindowTextLength(hWnd);
    GetWindowText(hWnd,spBuffer,nTitleSize);
    sWndTitle:= StrPas(spBuffer);
    ShowMessage(sWndTitle);
    while hWnd <> 0 do
      begin
         hWndAux:=hWnd;
         hWnd:= GetNextWindow(hWndAux,GW_HWNDNEXT);
         if IsWindow(hWnd) then
           begin
             nTitleSize:= GetWindowTextLength(hWnd);
             GetWindowText(hWnd,spBuffer,nTitleSize+1);
             sWndTitle:= StrPas(spBuffer);
             sWndTitle:=Trim(sWndTitle);
             ShowMessage(sWndTitle);
           end;

      end;
end;

end.
0
 
LVL 4

Expert Comment

by:d003303
ID: 1359044
you have to init/uninit the spBuffer with GetMem and FreeMem before each call to GetWindowText. PChar is only a pointer to a character chain. You always have to allocate the memory before and free memory after you used it.

hWnd:=GetTopWindow(0);
nTitleSize:= GetWindowTextLength(hWnd);
// here you allocate the memory
GetMem(spBuffer, nTitleSize + 1);
// there was the + 1 missing
GetWindowText(hWnd,spBuffer,nTitleSize + 1);
sWndTitle:= StrPas(spBuffer);
// here you free it
FreeMem(spBuffer, nTitleSize + 1);
ShowMessage(sWndTitle);
while hWnd <> 0 do
begin
hWndAux:=hWnd;
hWnd:= GetNextWindow(hWndAux,GW_HWNDNEXT);
if IsWindow(hWnd) then
begin
nTitleSize:= GetWindowTextLength(hWnd);
// here you allocate the memory
GetMem(spBuffer, nTitleSize + 1);
GetWindowText(hWnd,spBuffer,nTitleSize+1);
sWndTitle:= StrPas(spBuffer);
// here you free it
FreeMem(spBuffer, nTitleSize + 1);
sWndTitle:=Trim(sWndTitle);
ShowMessage(sWndTitle);
end;

Slash/d003303
0
 

Author Comment

by:Marcelito
ID: 1359045
Well, I think that I have a cloud in my mind. How I can forget it? Thanks, d003303!! My solution is working now!! Thanks to MikeP also! See you.
0
 
LVL 4

Expert Comment

by:d003303
ID: 1359046
Your question has to be graded if you got a working answer. Please let us know if the main part of the question was solved by MikeP or me, that he / I can give an answer to put the question to the PAQ area.
0
 

Author Comment

by:Marcelito
ID: 1359047
Sorry. Really the main part of question was resolved by you, d003303. I was not know the way to grade the answer. Please, tell me and I will do! Thanks  
0
 
LVL 4

Accepted Solution

by:
d003303 earned 100 total points
ID: 1359048
OK, you have to accept this answer and grade the question. Have a look at the Expert grading help link below.

Good luck on all your projects,
Slash/d003303
0
 

Author Comment

by:Marcelito
ID: 1359049
Thanks!! Good luck for you!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now