当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

    摘要: 同学想买书学vc++(c++已看完),望推荐几本好书。最好百元以下。谢谢。 ......
    摘要: 各种页面元素(特别是form中的元素)在vbscript中都是怎么引用的,包括属性、方法、事件等等。 怎么我找的vbs资料全是vbscript语法本身的,没有提及getelementbyid、insertrow等我想要的任何东西。 哪里有啊?总在这里问也不是办法啊 ......


怎么获取进程的ID号啊

请问如何实现windows优化大师中的进程管理功能。。。

NO.1   作者: u2m

这是我做的一个进程信息以及管理单元  
  {-----------------------------------------------------------------------------  
    Unit   Name:   UProcess  
    Author:         Administrator  
    Purpose:       进程操作单元  
    History:       2002-04-25  
  -----------------------------------------------------------------------------}  
   
  unit   UProcess;  
   
  interface  
   
  uses  
      Windows,   Dialogs,   SysUtils,   Classes,   ShellAPI,   TLHelp32,   UServerMain;  
   
  type  
      TProcessInfo   =   record  
          FileName:   string;  
          Caption:   string;  
          Visible:   boolean;  
          Handle:   DWord;  
          PClass:   string;  
          ThreadID:   DWord;  
          PID:   DWord;  
      end;  
   
  var  
      DateiList,   CaptionList,   VisibleList,   HandleList,   ClassList,   ThreadIdList,  
          PIDList:   TStringList;  
      ProcessInfo:   array   of   TProcessInfo;  
   
  function   EnumWindowsProc(hWnd:   HWND;   lParam:   LPARAM):   Bool;   stdcall;  
  function   GetFileNameFromHandle(Handle:   hwnd):   string;  
  procedure   ShowProcessInfo;  
  procedure   GetProcessList;  
   
  implementation  
   
  procedure   GetProcessList;  
  var  
      i,   Laenge:   integer;  
  begin  
      DateiList.Clear;  
      HandleList.Clear;  
      ClassList.Clear;  
      CaptionList.Clear;  
      VisibleList.Clear;  
      ThreadIdList.Clear;  
      PIDList.Clear;  
      EnumWindows(@EnumWindowsProc,   0);   //只能列举最上层窗口  
      Laenge   :=   DateiList.Count;  
      SetLength(ProcessInfo,   Laenge);  
      for   i   :=   0   to   Laenge   -   1   do  
      begin  
          DateiList[i]   :=   UpperCase(DateiList[i]);  
          with   ProcessInfo[i]   do  
          begin  
              FileName   :=   DateiList[i];  
              Caption   :=   CaptionList[i];  
              Visible   :=   VisibleList[i]   =   1;  
              Handle   :=   StrToInt64(HandleList[i]);  
              PClass   :=   ClassList[i];  
              ThreadID   :=   StrToInt64(ThreadIdList[i]);  
              PID   :=   StrToInt64(PIDList[i]);  
          end;  
      end;  
  end;  
   
  function   EnumWindowsProc(hWnd:   HWND;   lParam:   LPARAM):   Bool;   //回调函数  
  var  
      Capt,   Cla:   array[0..255]   of   char;  
      Datei:   string;  
      ident:   dword;  
  begin  
      GetWindowText(hWnd,   Capt,   255);   //返回长度或者0  
      GetClassName(hwnd,   Cla,   255);   //返回number或者0//Cla这样写相当与字符数组首地址  
      //GetWindowThreadProcessId返回Thread标识  
      ThreadIdList.Add(IntToStr(GetWindowThreadProcessId(hwnd,   nil)));  
      Datei   :=   GetFileNameFromhandle(hwnd);  
      DateiList.Add(Datei);  
      HandleList.Add(IntToStr(HWnd));  
      if   IsWindowVisible(HWnd)   then   //窗口是否可见状态  
          VisibleList.Add(1)  
      else  
          VisibleList.Add(0);  
      ClassList.Add(Cla);  
      CaptionList.Add(Capt);  
      GetWindowThreadProcessId(StrToInt(HandleList[HandleList.Count   -   1]),   @ident);  
      PIDList.Add(IntToStr(ident));  
      Result   :=   true;  
  end;  
   
  function   GetFileNameFromHandle(Handle:   hwnd):   string;  
  var  
      PID:   DWord;  
      aSnapShotHandle:   THandle;  
      ContinueLoop:   Boolean;  
      aProcessEntry32:   TProcessEntry32;   //结构体  
  begin  
      GetWindowThreadProcessID(Handle,   @PID);  
      //CreateToolHelp32SnapShot:Returns   an   open   handle   to   the   specified   snapshot   if   successful   or     -   1   otherwise.  
      //TH32CS_SNAPPROCESS:Includes   the   Win32   process   list   in   the   snapshot  
      //the   Second   Param   is   0:表明是当前进程  
      aSnapShotHandle   :=   CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS,   0);  
      //Before   Process32First   must:  
      aProcessEntry32.dwSize   :=   SizeOf(aProcessEntry32);  
      {The   calling   application   must   set   the   dwSize   member   of   PROCESSENTRY32   to   the   size,   in   bytes,   of   the   structure.  
      Process32First   changes   dwSize   to   the   number   of   bytes   written   to   the   structure.   This   will   never   be   greater   than   the   initial   value   of   dwSize,   but   it   may   be   smaller.  
      If   the   value   is   smaller,   do   not   rely   on   the   values   of   any   members   whose   offsets   are   greater   than   this   value.}  
      //aSnapShotHandle   是CreateToolHelp32SnapShot返回值  
      ContinueLoop   :=   Process32First(aSnapShotHandle,   aProcessEntry32);  
      //Copy第一个进程信息  
      while   Integer(ContinueLoop)   <>   0   do  
      begin  
          if   aProcessEntry32.th32ProcessID   =   PID   then  
          begin  
              result   :=   aProcessEntry32.szExeFile;   //如果等于PID   then   取文件名结果  
              break;  
          end;  
          ContinueLoop   :=   Process32Next(aSnapShotHandle,   aProcessEntry32);  
          //在系统下一个进程信息  
      end;  
      CloseHandle(aSnapShotHandle);  
  end;  
   
  procedure   ShowProcessInfo;  
  var  
      i:   integer;  
  begin  
      with   FrmServerMain.lvProcess.Items   do  
      begin  
          BeginUpdate;  
          Clear;  
          EndUpdate;  
      end;  
      GetProcessList;  
      for   i   :=   0   to   Length(ProcessInfo)   -   1   do  
      begin  
          with   FrmServerMain.lvProcess.Items.Add   do  
          begin  
              Caption   :=   inttostr(ProcessInfo[i].PID);  
              SubItems.Add(inttostr(ProcessInfo[i].ThreadID));  
              SubItems.Add(ProcessInfo[i].FileName);  
              SubItems.Add(ProcessInfo[i].Caption);  
              SubItems.Add(inttostr(ProcessInfo[i].Handle));  
              SubItems.Add(ProcessInfo[i].PClass);  
              if   (ProcessInfo[i].Visible)   then  
                  SubItems.Add(YES)  
              else  
                  SubItems.Add(NO);  
          end;  
      end;  
  end;  
   
  initialization  
      DateiList   :=   TStringList.Create;  
      HandleList   :=   TStringList.Create;  
      ClassList   :=   TStringList.Create;  
      CaptionList   :=   TStringList.Create;  
      VisibleList   :=   TStringList.Create;  
      ThreadIdList   :=   TStringList.Create;  
      PIDList   :=   TStringList.Create;  
   
  finalization  
      DateiList.Free;  
      HandleList.Free;  
      ClassList.Free;  
      CaptionList.Free;  
      VisibleList.Free;  
      ThreadIdList.Free;  
      PIDList.Free;  
   
  end.

NO.2   作者: jenemery

procedure   TForm1.Button1Click(Sender:   TObject);  
  var  
      lppe:TProcessEntry32;  
      found:Boolean;  
      Handle:THandle;  
      i:integer;  
      p:DWORD;  
  begin  
      Handle:=CreateToolHelp32Snapshot(TH32CS_SNAPALL,0);  
      found:=Process32First(Handle,lppe);  
      while   found   do  
      begin  
            ListBox1.Items.Add(StrPas(lppe.szExeFile));  
            found:=Process32Next(Handle,lppe);  
      end;  
   
    end;  
 


    摘要: 就是:shotgraph这个画图组件啊!因为我要画图 ......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE