4 static char Copyright
[] = "Copyright Martin Ayotte, 1994";
13 #include <sys/types.h>
19 static LPWINETASKENTRY lpTaskList
= NULL
;
20 static int nTaskCount
= 0;
22 /**********************************************************************
23 * GetCurrentTask [KERNEL.36]
25 HTASK
GetCurrentTask()
27 LPWINETASKENTRY lpTask
= lpTaskList
;
30 printf("GetCurrentTask() // unix_pid=%08X !\n", pid
);
32 if (lpTask
== NULL
) return 0;
34 if (lpTask
->unix_pid
== pid
) break;
35 if (lpTask
->lpNextTask
== NULL
) return 0;
36 lpTask
= lpTask
->lpNextTask
;
39 printf("GetCurrentTask() returned hTask=%04X !\n", lpTask
->te
.hTask
);
41 return lpTask
->te
.hTask
;
45 /**********************************************************************
46 * GetNumTasks [KERNEL.152]
50 printf("GetNumTasks() returned %d !\n", nTaskCount
);
55 /**********************************************************************
56 * GetWindowTask [USER.224]
58 HTASK
GetWindowTask(HWND hWnd
)
62 LPWINETASKENTRY lpTask
= lpTaskList
;
63 printf("GetWindowTask(%04X) !\n", hWnd
);
64 while (lpTask
!= NULL
) {
65 wptr
= lpTask
->lpWndList
;
68 while (++count
< MAXWIN_PER_TASK
) {
69 printf("GetWindowTask // searching %04X %04X !\n",
70 lpTask
->te
.hTask
, *(wptr
));
71 if (*(wptr
) == hWnd
) {
72 printf("GetWindowTask(%04X) found hTask=%04X !\n",
73 hWnd
, lpTask
->te
.hTask
);
74 return lpTask
->te
.hTask
;
79 lpTask
= lpTask
->lpNextTask
;
85 /**********************************************************************
86 * EnumTaskWindows [USER.225]
88 BOOL
EnumTaskWindows(HANDLE hTask
, FARPROC lpEnumFunc
, LONG lParam
)
93 LPWINETASKENTRY lpTask
= lpTaskList
;
94 printf("EnumTaskWindows(%04X, %08X, %08X) !\n", hTask
, lpEnumFunc
, lParam
);
96 if (lpTask
->te
.hTask
== hTask
) break;
98 printf("EnumTaskWindows // hTask=%04X not found !\n", hTask
);
101 lpTask
= lpTask
->lpNextTask
;
103 printf("EnumTaskWindows // found hTask=%04X !\n", hTask
);
104 wptr
= lpTask
->lpWndList
;
105 if (wptr
== NULL
) return FALSE
;
106 if (lpEnumFunc
== NULL
) return FALSE
;
107 while ((hWnd
= *(wptr
++)) != 0) {
108 if (++count
>= MAXWIN_PER_TASK
) return FALSE
;
109 printf("EnumTaskWindows // hWnd=%04X count=%d !\n", hWnd
, count
);
111 bRet
= (*lpEnumFunc
)(hWnd
, lParam
);
113 bRet
= CallBack16(lpEnumFunc
, 2, 0, (int)hWnd
, 2, (int)lParam
);
115 if (bRet
== 0) break;
121 /**********************************************************************
122 * CreateNewTask [internal]
124 HANDLE
CreateNewTask(HINSTANCE hInst
, HTASK hTaskParent
)
127 LPWINETASKENTRY lpTask
= lpTaskList
;
128 LPWINETASKENTRY lpNewTask
;
131 module
.dwSize
= sizeof(module
);
132 ModuleFindHandle(&module
, hInst
);
134 if (lpTask
!= NULL
) {
136 if (lpTask
->lpNextTask
== NULL
) break;
137 lpTask
= lpTask
->lpNextTask
;
140 hTask
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(WINETASKENTRY
));
141 lpNewTask
= (LPWINETASKENTRY
) GlobalLock(hTask
);
143 printf("CreateNewTask entry allocated %08X\n", lpNewTask
);
145 if (lpNewTask
== NULL
) return 0;
146 if (lpTaskList
== NULL
) {
147 lpTaskList
= lpNewTask
;
148 lpNewTask
->lpPrevTask
= NULL
;
151 lpTask
->lpNextTask
= lpNewTask
;
152 lpTask
->te
.hNext
= lpNewTask
->te
.hTask
;
153 lpNewTask
->lpPrevTask
= lpTask
;
155 lpNewTask
->lpNextTask
= NULL
;
156 lpNewTask
->hIcon
= 0;
157 lpNewTask
->te
.dwSize
= sizeof(TASKENTRY
);
158 lpNewTask
->te
.hModule
= 0;
159 lpNewTask
->te
.hInst
= hInst
;
160 lpNewTask
->te
.hTask
= hTask
;
161 lpNewTask
->te
.hTaskParent
= hTaskParent
;
162 lpNewTask
->te
.wSS
= 0;
163 lpNewTask
->te
.wSP
= 0;
164 lpNewTask
->te
.wStackTop
= 0;
165 lpNewTask
->te
.wStackMinimum
= 0;
166 lpNewTask
->te
.wStackBottom
= 0;
167 lpNewTask
->te
.wcEvents
= 0;
168 lpNewTask
->te
.hQueue
= 0;
169 strcpy(lpNewTask
->te
.szModule
, module
.szModule
);
170 lpNewTask
->te
.wPSPOffset
= 0;
171 lpNewTask
->unix_pid
= getpid();
172 lpNewTask
->lpWndList
= (HWND
*) malloc(MAXWIN_PER_TASK
* sizeof(HWND
));
173 if (lpNewTask
->lpWndList
!= NULL
)
174 memset((LPSTR
)lpNewTask
->lpWndList
, 0, MAXWIN_PER_TASK
* sizeof(HWND
));
176 printf("CreateNewTask // unix_pid=%08X return hTask=%04X\n",
177 lpNewTask
->unix_pid
, hTask
);
185 /**********************************************************************
186 * AddWindowToTask [internal]
188 BOOL
AddWindowToTask(HTASK hTask
, HWND hWnd
)
192 LPWINETASKENTRY lpTask
= lpTaskList
;
194 printf("AddWindowToTask(%04X, %04X); !\n", hTask
, hWnd
);
197 if (lpTask
->te
.hTask
== hTask
) break;
198 if (lpTask
== NULL
) {
199 printf("AddWindowToTask // hTask=%04X not found !\n", hTask
);
202 lpTask
= lpTask
->lpNextTask
;
204 wptr
= lpTask
->lpWndList
;
205 if (wptr
== NULL
) return FALSE
;
206 while (*(wptr
) != 0) {
207 if (++count
>= MAXWIN_PER_TASK
) return FALSE
;
212 printf("AddWindowToTask // window added, count=%d !\n", count
);
218 /**********************************************************************
219 * RemoveWindowFromTask [internal]
221 BOOL
RemoveWindowFromTask(HTASK hTask
, HWND hWnd
)
225 LPWINETASKENTRY lpTask
= lpTaskList
;
227 printf("RemoveWindowToTask(%04X, %04X); !\n", hTask
, hWnd
);
230 if (lpTask
->te
.hTask
== hTask
) break;
231 if (lpTask
== NULL
) {
232 printf("RemoveWindowFromTask // hTask=%04X not found !\n", hTask
);
235 lpTask
= lpTask
->lpNextTask
;
237 wptr
= lpTask
->lpWndList
;
238 if (wptr
== NULL
) return FALSE
;
239 while (*(wptr
) != hWnd
) {
240 if (++count
>= MAXWIN_PER_TASK
) return FALSE
;
243 while (*(wptr
) != 0) {
244 *(wptr
) = *(wptr
+ 1);
245 if (++count
>= MAXWIN_PER_TASK
) return FALSE
;
249 printf("RemoveWindowFromTask // window removed, count=%d !\n", --count
);
254 BOOL
TaskFirst(LPTASKENTRY lpTask
)
256 printf("TaskFirst(%8x)\n", (int) lpTask
);
259 memcpy(lpTask
, &lpTaskList
->te
, lpTask
->dwSize
);
265 BOOL
TaskNext(LPTASKENTRY lpTask
)
267 LPWINETASKENTRY list
;
269 printf("TaskNext(%8x)\n", (int) lpTask
);
273 if (list
->te
.hTask
== lpTask
->hTask
) {
274 list
= list
->lpNextTask
;
276 memcpy(lpTask
, &list
->te
, lpTask
->dwSize
);
281 list
= list
->lpNextTask
;
286 BOOL
TaskFindHandle(LPTASKENTRY lpTask
, HTASK hTask
)
288 static LPWINETASKENTRY list
;
290 printf("TaskFindHandle(%8x,%4x)\n", (int) lpTask
, hTask
);
294 if (list
->te
.hTask
== hTask
) {
295 list
= list
->lpNextTask
;
297 memcpy(lpTask
, &list
->te
, lpTask
->dwSize
);
302 list
= list
->lpNextTask
;