CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  Windows SDK/API

请问如何从任务管理器的应用程序列表中获知该应用程序属于哪个进程

楼主niat97222(Freeman)2006-03-06 22:21:03 在 Delphi / Windows SDK/API 提问

如我们打开DELPHI后,任务管理器的应用程序列表中将出现DELPHI7这个程序,且该程序状态为正在运行,而进程中也必然出现delphi32.exe的进程,且DELPHI7这个程序是由DELPHI32.EXE这个进程产生的。如果现在应用程序列表中出现了名称为AAA的程序,我如何从进程列表中获知该程序是由哪个进程产生的呢,还请不吝赐教 问题点数:200、回复次数:4Top

1 楼niat97222(Freeman)回复于 2006-03-06 22:35:48 得分 0

啊,这里没有人来吗Top

2 楼aiirii(ari-http://spaces.msn.com/members/aiirii/)回复于 2006-03-06 22:49:23 得分 80

//还有别忘了在   uses   部分加上TLHelp32单元  
  function   GetAppName(const   AWindowHandle:   THandle):   string;  
  var  
      PI:   DWORD;  
      ContinueLoop:BOOL;  
      SnapshotHandle:THandle;  
      ProcessEntry32:TProcessEntry32;  
  begin  
      Result   :=   '';  
      GetWindowThreadProcessId(AWindowHandle,   @PI);  
   
      SnapshotHandle   :=   CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,   0);  
      ProcessEntry32.dwSize   :=   Sizeof(ProcessEntry32);  
      ContinueLoop   :=   Process32First(SnapshotHandle,ProcessEntry32);  
      while   ContinueLoop   do  
      begin  
          if   ProcessEntry32.th32ProcessID   =   PI   then  
          begin  
              Result   :=   ProcessEntry32.szExeFile;  
              break;  
          end;  
          ContinueLoop:=Process32Next(SnapshotHandle,   ProcessEntry32);  
      end;  
      CloseHandle(SnapshotHandle);  
  end;  
   
  用以上的方法找到窗口HANDLE和PROCESSID后,用GETWINDOWTHREADPROCESS这个API函数可以得到创建窗口的PROCESSID,再和PROCESSID比较一下,可以找到!Top

3 楼liangqingzhi(老之)回复于 2006-03-06 23:12:23 得分 80

列举任务栏、进程ID、路径的程序:  
   
  unit   Unit1;  
   
  interface  
   
  uses  
    Windows,   Messages,   SysUtils,   Classes,   Graphics,   Controls,   Forms,   Dialogs,  
    StdCtrls,PSAPI;  
   
  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     IsWindowVisible(Wnd)   and  
   
          ((GetWindowLong(Wnd,   GWL_HWNDPARENT)   =   0)   or  
            (HWND(GetWindowLong(Wnd,   GWL_HWNDPARENT))   =   GetDesktopWindow))   and  
          ((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,path:   array   [0..255]   of   Char;  
    Wnd,hModule,hProcess:   HWND;  
    tid,   pid,Needed:   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   );  
                hProcess:=OpenProcess(PROCESS_QUERY_INFORMATION   or   PROCESS_VM_READ,False,PID);  
        if   hProcess>0     then  
              begin  
                  EnumProcessModules(hProcess,@hModule,SizeOf(hModule),Needed);  
                  GetModuleFileNameEx(hProcess,hModule,Path,SizeOf(Path));  
                  GetShortPathName(Path,Path,256);  
              end;  
                label1.caption   :=  
                    Format(  
                        'HWND:   %8.8x'#13#10+  
                        'Class:   %s'#13#10+  
                        'Process   ID:   %8.8x'#13#10+  
                        'Thread   ID:   %8.8x'#13#10+  
                        'Path:%s',  
                        [Wnd,   theClassname,   pid,   tid,   path]   );  
            end;  
        end;  
    end;  
  end;  
   
  end.Top

4 楼ly_liuyang(Liu Yang LYSoft http://lysoft.7u7.net)回复于 2006-03-07 10:57:43 得分 40

The   GetWindowThreadProcessId   function   retrieves   the   identifier   of   the   thread   that   created   the   specified   window   and,   optionally,   the   identifier   of   the   process   that   created   the   window.   This   function   supersedes   the   GetWindowTask   function.Top

相关问题

  • 怎么才能让Form在任务管理器里的应用程序列表 里不出现呢!?
  • 怎么使程序在任务管理器的应用程序列表中看不到?
  • 如何在“任务管理器”的“应用程序”列表中不显示我的程序
  • 怎样将一个运行的程序,从CRT+ALT+DEL弹出的任务管理器的应用程序列表中删除,只显示在进程中!
  • 应用程序的进程能在任务管理器中不显示吗?
  • 如何使应用程序在任务管理器中不可见??
  • 怎样枚举任务管理器中应用程序选项卡中程序?
  • 如何改变MFC应用程序在资源管理器中的文件图标?
  • 自己做个资源管理器,想点击其中文件就用关联应用程序打开它
  • 如何让自己的应用程序文档在资源管理器中显示为指定的图标?

关键词

  • 应用程序
  • delphi
  • snapshothandle
  • processentry
  • 进程
  • 列表
  • continueloop
  • getwindowthreadprocessid
  • processid
  • hprocess

得分解答快速导航

  • 帖主:niat97222
  • aiirii
  • liangqingzhi
  • ly_liuyang

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo