Rev 6746 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6696 | leency | 1 | #define MEMSIZE 4096*20 |
2 | |||
3 | //===================================================// |
||
4 | // // |
||
5 | // LIB // |
||
6 | // // |
||
7 | //===================================================// |
||
8 | |||
9 | #include "../lib/gui.h" |
||
10 | #include "../lib/list_box.h" |
||
11 | #include "../lib/obj/box_lib.h" |
||
12 | #include "../lib/io.h" |
||
13 | #include "../lib/patterns/select_list.h" |
||
6708 | leency | 14 | #include "../lib/patterns/restart_process.h" |
6696 | leency | 15 | |
16 | //===================================================// |
||
17 | // // |
||
18 | // DATA // |
||
19 | // // |
||
20 | //===================================================// |
||
21 | |||
22 | #define T_WINDOW_TITLE "Process Manager" |
||
23 | #define T_SHOW_SYSTEM_PROCESSES "Show system" |
||
24 | #define T_DETAILS "Details" |
||
25 | #define T_END_PROCESS "End process" |
||
26 | |||
27 | |||
28 | #define BOTPANEL_H 34 |
||
29 | proc_info Form; |
||
30 | proc_info Process; |
||
31 | |||
32 | enum { |
||
33 | BTN_ID_SHOW_SYSTEM_PROCESSES=20, |
||
34 | BTN_ID_KILL_PROCESS, |
||
35 | BTN_ID_SHOW_PROCESS_INFO |
||
36 | }; |
||
37 | |||
38 | int current_process_id = 0; |
||
39 | int show_system; |
||
40 | unsigned maxcpu; |
||
41 | int proc_list[256]; |
||
42 | |||
43 | //===================================================// |
||
44 | // // |
||
45 | // CODE // |
||
46 | // // |
||
47 | //===================================================// |
||
48 | |||
49 | void GetCpuFrequency() { |
||
50 | EAX = 18; |
||
51 | EBX = 5; |
||
52 | $int 0x40 |
||
53 | maxcpu = EAX; |
||
54 | } |
||
55 | |||
56 | void main() |
||
57 | { |
||
58 | byte btn; |
||
59 | load_dll(boxlib, #box_lib_init,0); |
||
60 | SetEventMask(10000000000000000000000001100111b); |
||
61 | GetCpuFrequency(); |
||
62 | loop() |
||
63 | { |
||
64 | WaitEventTimeout(50); |
||
65 | switch(EAX & 0xFF) |
||
66 | { |
||
67 | case evMouse: |
||
68 | if (!CheckActiveProcess(Form.ID)) break; |
||
69 | SelectList_ProcessMouse(); |
||
70 | break; |
||
71 | case evKey: |
||
72 | GetKeys(); |
||
73 | if (select_list.ProcessKey(key_scancode)) SelectList_LineChanged(); |
||
74 | break; |
||
75 | case evButton: |
||
76 | btn = GetButtonID(); |
||
77 | if (1 == btn) |
||
78 | { |
||
79 | ExitProcess(); |
||
80 | } |
||
81 | if (BTN_ID_SHOW_SYSTEM_PROCESSES == btn) |
||
82 | { |
||
83 | show_system ^= 1; |
||
84 | Draw_ShowSystemProcessesCheckbox(); |
||
85 | SelectList_LineChanged(); |
||
86 | } |
||
87 | if (BTN_ID_KILL_PROCESS == btn) |
||
88 | { |
||
89 | KillProcess(current_process_id); |
||
90 | pause(10); |
||
91 | SelectList_LineChanged(); |
||
92 | } |
||
93 | if (BTN_ID_SHOW_PROCESS_INFO == btn) |
||
94 | { |
||
95 | io.run("/sys/tinfo", itoa(GetProcessSlot(current_process_id))); |
||
96 | } |
||
97 | break; |
||
98 | case evReDraw: |
||
99 | system.color.get(); |
||
6746 | leency | 100 | DefineAndDrawWindow(screen.width-400/2,screen.height-450/2,400,454,0x73,0,T_WINDOW_TITLE,0); |
6696 | leency | 101 | GetProcessInfo(#Form, SelfInfo); |
102 | if (Form.status_window>2) break; |
||
103 | if (Form.width < 300) { MoveSize(OLD,OLD,300,OLD); break; } |
||
104 | if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); break; } |
||
105 | SelectList_Init(6, 6, Form.cwidth-12 - scroll1.size_x, Form.cheight-12-BOTPANEL_H, false); |
||
106 | SelectList_DrawBorder(); |
||
107 | DrawWideRectangle(0, 0, Form.cwidth, Form.cheight, 4, system.color.work); |
||
108 | DrawBar(select_list.x-2, select_list.y+select_list.h+2, |
||
109 | select_list.w+scroll1.size_x+4, BOTPANEL_H, system.color.work); |
||
110 | DrawCaptButton(Form.cwidth-116, |
||
111 | select_list.y+select_list.h+5, |
||
112 | 110,25,BTN_ID_KILL_PROCESS,0xF38181, 0xFFFfff, T_END_PROCESS); |
||
113 | DrawCaptButton(Form.cwidth-236, |
||
114 | select_list.y+select_list.h+5, |
||
115 | 110,25,BTN_ID_SHOW_PROCESS_INFO, |
||
116 | system.color.work_button, system.color.work_button_text, T_DETAILS); |
||
117 | Draw_ShowSystemProcessesCheckbox(); |
||
118 | default: |
||
119 | SelectList_LineChanged(); |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | |||
124 | void SelectList_LineChanged() |
||
125 | { |
||
126 | GetProcessList(); |
||
127 | SelectList_Draw(); |
||
128 | } |
||
129 | |||
130 | |||
131 | void GetProcessList() |
||
132 | { |
||
133 | int i, j; |
||
134 | select_list.count=0; |
||
6708 | leency | 135 | for (i=0; i |
6696 | leency | 136 | { |
137 | GetProcessInfo(#Process, i); |
||
138 | if (Process.name) |
||
139 | { |
||
140 | for (j=0; j<11; j++) if (Process.name[j]!=' ') { |
||
141 | if (show_system==false) { |
||
142 | //do not show system process |
||
143 | if (Process.name[0]=='@') break; |
||
144 | if (!strcmp(#Process.name, "IDLE")) break; |
||
145 | if (!strcmp(#Process.name, "OS")) break; |
||
146 | } |
||
147 | proc_list[select_list.count] = i; |
||
148 | select_list.count++; |
||
149 | break; |
||
150 | } |
||
151 | } |
||
152 | } |
||
153 | } |
||
154 | |||
155 | void SelectList_DrawLine(dword i) |
||
156 | { |
||
157 | int posy; |
||
158 | char cpu_use[16]; |
||
159 | dword bg_color; |
||
160 | GetProcessInfo(#Process, proc_list[i+select_list.first]); |
||
161 | |||
162 | posy = i *select_list.item_h + select_list.y; |
||
163 | if (i % 2) bg_color = 0xFFFfff; else bg_color = 0xF0F0F0; |
||
164 | if (i+select_list.first == select_list.cur_y) { |
||
165 | current_process_id = Process.ID; |
||
166 | bg_color = 0x67CCEB; |
||
167 | } |
||
168 | DrawBar(select_list.x, posy, select_list.w, select_list.item_h, bg_color); |
||
169 | WriteText(select_list.x+005, posy+select_list.text_y, select_list.font_type, 0, #Process.name); |
||
170 | WriteText(select_list.w/10*5+select_list.x, posy+select_list.text_y, select_list.font_type, 0x444444, ConvertSizeToKb(Process.use_memory)); |
||
171 | sprintf(#cpu_use, "%i %%", Process.use_cpu*100/maxcpu); |
||
172 | if (maxcpu) WriteText(select_list.w/10*8+select_list.x - calc(strlen(#cpu_use)-4*8), |
||
173 | posy+select_list.text_y, select_list.font_type, 0x444444, #cpu_use); |
||
174 | } |
||
175 | |||
176 | |||
177 | void Draw_ShowSystemProcessesCheckbox() { |
||
178 | CheckBox(select_list.x + 3, select_list.y+select_list.h+10, 20, |
||
179 | T_SHOW_SYSTEM_PROCESSES, show_system); |
||
180 | } |
||
181 | |||
182 | |||
183 | |||
184 | |||
185 | |||
186 | stop:11;>>> |