forked from ying32/govcl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
115 lines (88 loc) · 2.45 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// +build windows
package main
import (
"unsafe"
"github.com/ying32/govcl/vcl/types"
"github.com/ying32/govcl/vcl/rtl"
"path/filepath"
"fmt"
_ "github.com/ying32/govcl/pkgs/winappres"
"github.com/ying32/govcl/vcl"
"github.com/ying32/govcl/vcl/win"
)
type TMainForm struct {
*vcl.TForm
imgList *vcl.TImageList
lv1 *vcl.TListView
}
var mainForm *TMainForm
func (f *TMainForm) OnFormCreate(object vcl.IObject) {
f.SetCaption("Windows Process")
f.SetWidth(600)
f.SetHeight(400)
// 双缓冲
f.SetDoubleBuffered(true)
f.ScreenCenter()
f.initComponents()
}
func (f *TMainForm) initComponents() {
f.imgList = vcl.NewImageList(f)
f.imgList.SetWidth(24)
f.imgList.SetHeight(24)
f.lv1 = vcl.NewListView(f)
f.lv1.SetParent(f)
f.lv1.SetAlign(types.AlClient)
f.lv1.SetRowSelect(true)
f.lv1.SetReadOnly(true)
f.lv1.SetViewStyle(types.VsReport)
f.lv1.SetGridLines(true)
f.lv1.SetLargeImages(f.imgList)
f.lv1.SetSmallImages(f.imgList)
col := f.lv1.Columns().Add()
col.SetWidth(60)
col = f.lv1.Columns().Add()
col.SetCaption("进程名")
col.SetAutoSize(true)
col = f.lv1.Columns().Add()
col.SetCaption("PID")
col.SetAutoSize(true)
f.lv1.Clear()
f.imgList.Clear()
f.fullListView()
}
func (f *TMainForm) fullListView() {
var fProcessEntry32 win.TProcessEntry32
fProcessEntry32.DwSize = uint32(unsafe.Sizeof(fProcessEntry32))
fSnapShotHandle := win.CreateToolhelp32SnapShot(win.TH32CS_SNAPPROCESS, 0)
continueLoop := win.Process32First(fSnapShotHandle, &fProcessEntry32)
f.lv1.Items().BeginUpdate()
defer f.lv1.Items().EndUpdate()
ico := vcl.NewIcon()
ico.SetTransparent(true)
defer ico.Free()
for continueLoop {
item := f.lv1.Items().Add()
exeFileName := win.GoStr(fProcessEntry32.SzExeFile[:])
item.SubItems().Add(filepath.Base(exeFileName))
item.SubItems().Add(fmt.Sprintf("%.4X", fProcessEntry32.Th32ProcessID))
hProcess := win.OpenProcess(win.PROCESS_QUERY_INFORMATION|win.PROCESS_VM_READ, false, fProcessEntry32.Th32ProcessID)
if hProcess > 0 {
fullFileName, _ := win.GetModuleFileNameEx(hProcess, 0)
fmt.Println(fullFileName)
hIcon := win.ExtractIcon(rtl.MainInstance(), fullFileName, 0)
if hIcon != 0 {
ico.SetHandle(hIcon)
index := f.imgList.AddIcon(ico)
item.SetImageIndex(index)
}
win.CloseHandle(hProcess)
}
continueLoop = win.Process32Next(fSnapShotHandle, &fProcessEntry32)
}
if fSnapShotHandle != 0 {
win.CloseHandle(fSnapShotHandle)
}
}
func main() {
vcl.RunApp(&mainForm)
}