重金求教:如何得到Win98中按热启动时“关闭程序”中的列表项目。(300分)

  • 主题发起人 主题发起人 我是笨猪
  • 开始时间 开始时间

我是笨猪

Unregistered / Unconfirmed
GUEST, unregistred user!
重金求教:如何得到Win98中按热启动时“关闭程序”中的列表项目。
 
没作过,知道后请贴出来,大家共享
 
unit Unit1;

interface

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

type


TForm1 = class(TForm)
ListBox1: TListBox;
Panel1: TPanel;
Button2: TButton;
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
uses psapi;
{$R *.DFM}

procedure TForm1.Button2Click(Sender: TObject);
type
integer = DWORD; // different versions of psapi.pas floating around
var
i,j,pidNeeded,modNeeded : Integer;
PIDList : array[0..1000] of Integer; // 1000 should be enough
MODList : array[0..1000] of HInst;
PIDName : array [0..MAX_PATH - 1] of char;
MODName : array [0..MAX_PATH - 1] of char;
PH : THandle;
begin

// fill an array with process ids
if not enumprocesses (@PIDList, 1000, pidNeeded) then
begin
ListBox1.Items.Add('Need psapi.dll');
exit;
end;

// now open each process and its modules
for i := 0 to (pidNeeded div sizeof (Integer)- 1) do
begin
// get a handle to the process
PH := OpenProcess (PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False,
PIDList);

if PH <> 0 then
begin
// print the process name
if GetModuleBaseName (PH, 0, PIDName, sizeof (PIDName)) > 0 then
begin
ListBox1.Items.Add('process : ' + PIDName);

// fill an array of modules associated with this process
if not EnumProcessModules (PH,@MODList,1000, modNeeded) then modNeeded:= 0;

// print the modules in the list
for j := 0 to (modNeeded div sizeof (hInst) - 1) do
if GetModuleFileNameEx (PH, MODList[j], MODName,sizeof(MODName)) > 0 then
ListBox1.Items.Add(' module: ' + MODName);

if PH > 0 then CloseHandle(PH);
end;
end;
end;

end;

end.
 
最好当然是给银票!!

例程如下:

uses TLHelp32; //一定要加上

procedure TForm1.Button1Click(Sender: TObject);
var
PEntry: TProcessEntry32;
hSSHND: THandle;
ContinueLoop: BOOL;
begin
hSSHND:= CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
PEntry.dwSize:= SizeOf(PEntry);

ListBox1.Items.Clear;
ContinueLoop:=Process32First(hSSHND, PEntry);
while Integer(ContinueLoop) <> 0 do
begin
ListBox1.Items.Add(PEntry.szExeFile);
ContinueLoop:= Process32Next(hSSHND, PEntry);
end;
end;

 
kimfeng,你的列出的是系统进程。
yanghai0437你的好像没什么反映.
function EnumWndProc 中不加条件“IsWindowVisible(AWnd)”
时会出现许多系统进程的窗口,加了时像金山词霸这样的最小化后,
就会不出现在列表中,该如何挑出系统的,只要用户运行的?
unit Unisdf;

interface

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

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

var
Form1: TForm1;

implementation

{$R *.DFM}
function EnumWndProc(AWnd: HWND; AlParam: LPARAM):Boolean;stdcall;
//得到可视的顶层窗口列表
var

WndCaption: array[0..254] of Char;
ulpClassName : array[0..254] of Char;
i : integer ;
b : boolean ;
begin
GetWindowText(AWnd, @WndCaption, 254);
if (WndCaption[0]<>chr(0)) and IsWindowVisible(AWnd) and
((GetWindowLong(aWnd, GWL_HWNDPARENT) = 0) or
(HWND(GetWindowLong(aWnd, GWL_HWNDPARENT)) = GetDesktopWindow)) then
Form1.ListBox1.Items.Add(StrPas(WndCaption));
Result := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.ListBox1.Items.Clear;
EnumWindows(@EnumWndProc,0);
end;

end.
 
用现成控件包省事多了!AHM2000戓LMD,如果用D5则X2000是最好的选择!
 
to:louhong,lmd里哪个组件是呀?
 
to 我是笨猪:
没理解你的意思,关键是我不用98,是不是说:偶的程序把系统和用户的都列出来了。
而你只是要用户的是不是这个意思?
 
to kimfeng,非常正确,还有DLL文件
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
816
SUNSTONE的Delphi笔记
S
S
回复
0
查看
735
SUNSTONE的Delphi笔记
S
D
回复
0
查看
867
DelphiTeacher的专栏
D
后退
顶部