‘调用示例 Dim I As Integer Dim ShowArray As Variant ShowArray = ProcessArray For I = LBound(ShowArray) To UBound(ShowArray) Debug.Print ShowArray(I) Next I
Option Explicit Private Declare Function CreateToolhelp32Snapshot Lib “kernel32” (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long Private Declare Function Process32First Lib “kernel32” (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long Private Declare Function Process32Next Lib “kernel32” (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long Private Declare Function CloseHandle Lib “kernel32” (ByVal hObject As Long) As Long Private Declare Function OpenProcess Lib “kernel32” (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long Private Declare Function TerminateProcess Lib “kernel32” (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long
Private Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szExeFile As String * 1024 End Type
Const TH32CS_SNAPHEAPLIST = &H1 Const TH32CS_SNAPPROCESS = &H2 Const TH32CS_SNAPTHREAD = &H4 Const TH32CS_SNAPMODULE = &H8 Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE) Const TH32CS_INHERIT = &H80000000
Private Function ProcessArray() As Variant ‘生成进程名数组 Dim pProcess As PROCESSENTRY32 Dim lRet As Long Dim lRet1 As Long Dim sName As String Dim I As Integer lRet = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) If lRet Then pProcess.dwSize = 1060 If (Process32First(lRet, pProcess)) Then ‘遍历第一个进程 Dim iCount As Integer Dim TempArray() As String Do I = InStr(1, pProcess.szExeFile, Chr(0)) sName = LCase(Left(pProcess.szExeFile, I – 1)) ReDim Preserve TempArray(0 To iCount) TempArray(iCount) = sName iCount = iCount + 1 Loop Until (Process32Next(lRet, pProcess) < 1) ‘遍历所有进程知道返回值为False End If lRet1 = CloseHandle(lRet) End If ProcessArray = TempArray End Function
Option Explicit Private Declare Function TransparentBlt Lib “msimg32” _ (ByVal hdcDest As Long, ByVal nXOriginDest As Long, _ ByVal nYOriginDest As Long, ByVal nWidthDest As Long, _ ByVal nHeightDest As Long, ByVal hdcSrc As Long, _ ByVal nXOriginSrc As Long, ByVal nYOriginSrc As Long, _ ByVal nWidthSrc As Long, ByVal nHeightSrc As Long, _ ByVal crTransparent As Long) As Long Private Declare Function GetPixel Lib “gdi32” (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
‘调用示例 ‘添加一个 PictureBox,命名为 picSource,并加载图片 Dim TransparentColor As Long TransparentColor = GetPixel(picSource.hdc, 0, 0) ‘选择左上角(0,0)的颜色为屏蔽色 ‘thne simply draw with the transparent color equal to the value we found above With picSource TransparentBlt Me.hdc, 0, 0, .ScaleWidth, .ScaleHeight, .hdc, 0, 0, .ScaleWidth, .ScaleHeight, TransparentColor End With Me.Refresh