4 static char Copyright
[] = "Copyright Martin Ayotte, 1994";
10 #include <sys/types.h>
18 /* #define DEBUG_TASK /* */
19 /* #undef DEBUG_TASK /* */
22 static LPWINETASKENTRY lpTaskList
= NULL
;
23 static int nTaskCount
= 0;
25 /**********************************************************************
26 * GetCurrentTask [KERNEL.36]
28 HTASK
GetCurrentTask()
30 LPWINETASKENTRY lpTask
= lpTaskList
;
33 fprintf(stddeb
,"GetCurrentTask() // unix_pid=%08X !\n", pid
);
35 if (lpTask
== NULL
) return 0;
37 if (lpTask
->unix_pid
== pid
) break;
38 if (lpTask
->lpNextTask
== NULL
) return 0;
39 lpTask
= lpTask
->lpNextTask
;
42 fprintf(stddeb
,"GetCurrentTask() returned hTask=%04X !\n", lpTask
->te
.hTask
);
44 return lpTask
->te
.hTask
;
48 /**********************************************************************
49 * GetNumTasks [KERNEL.152]
54 fprintf(stddeb
,"GetNumTasks() returned %d !\n", nTaskCount
);
60 /**********************************************************************
61 * GetWindowTask [USER.224]
63 HTASK
GetWindowTask(HWND hWnd
)
67 LPWINETASKENTRY lpTask
= lpTaskList
;
69 fprintf(stddeb
,"GetWindowTask(%04X) !\n", hWnd
);
71 while (lpTask
!= NULL
) {
72 wptr
= lpTask
->lpWndList
;
75 while (++count
< MAXWIN_PER_TASK
) {
77 fprintf(stddeb
,"GetWindowTask // searching %04X %04X !\n",
78 lpTask
->te
.hTask
, *(wptr
));
80 if (*(wptr
) == hWnd
) {
82 fprintf(stddeb
,"GetWindowTask(%04X) found hTask=%04X !\n",
83 hWnd
, lpTask
->te
.hTask
);
85 return lpTask
->te
.hTask
;
90 lpTask
= lpTask
->lpNextTask
;
96 /**********************************************************************
97 * EnumTaskWindows [USER.225]
99 BOOL
EnumTaskWindows(HANDLE hTask
, FARPROC lpEnumFunc
, LONG lParam
)
104 LPWINETASKENTRY lpTask
= lpTaskList
;
106 fprintf(stddeb
,"EnumTaskWindows(%04X, %08X, %08X) !\n", hTask
, lpEnumFunc
, lParam
);
109 if (lpTask
->te
.hTask
== hTask
) break;
110 if (lpTask
== NULL
) {
112 fprintf(stddeb
,"EnumTaskWindows // hTask=%04X not found !\n", hTask
);
116 lpTask
= lpTask
->lpNextTask
;
119 fprintf(stddeb
,"EnumTaskWindows // found hTask=%04X !\n", hTask
);
121 wptr
= lpTask
->lpWndList
;
122 if (wptr
== NULL
) return FALSE
;
123 if (lpEnumFunc
== NULL
) return FALSE
;
124 while ((hWnd
= *(wptr
++)) != 0) {
125 if (++count
>= MAXWIN_PER_TASK
) return FALSE
;
127 fprintf(stddeb
,"EnumTaskWindows // hWnd=%04X count=%d !\n", hWnd
, count
);
130 bRet
= (*lpEnumFunc
)(hWnd
, lParam
);
132 bRet
= CallBack16(lpEnumFunc
, 2, 0, (int)hWnd
, 2, (int)lParam
);
134 if (bRet
== 0) break;
140 /**********************************************************************
141 * CreateNewTask [internal]
143 HANDLE
CreateNewTask(HINSTANCE hInst
, HTASK hTaskParent
)
146 LPWINETASKENTRY lpTask
= lpTaskList
;
147 LPWINETASKENTRY lpNewTask
;
150 module
.dwSize
= sizeof(module
);
151 ModuleFindHandle(&module
, hInst
);
153 if (lpTask
!= NULL
) {
155 if (lpTask
->lpNextTask
== NULL
) break;
156 lpTask
= lpTask
->lpNextTask
;
159 hTask
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(WINETASKENTRY
));
160 lpNewTask
= (LPWINETASKENTRY
) GlobalLock(hTask
);
162 fprintf(stddeb
,"CreateNewTask entry allocated %08X\n", lpNewTask
);
164 if (lpNewTask
== NULL
) return 0;
165 if (lpTaskList
== NULL
) {
166 lpTaskList
= lpNewTask
;
167 lpNewTask
->lpPrevTask
= NULL
;
170 lpTask
->lpNextTask
= lpNewTask
;
171 lpTask
->te
.hNext
= lpNewTask
->te
.hTask
;
172 lpNewTask
->lpPrevTask
= lpTask
;
174 lpNewTask
->lpNextTask
= NULL
;
175 lpNewTask
->hIcon
= 0;
176 lpNewTask
->te
.dwSize
= sizeof(TASKENTRY
);
177 lpNewTask
->te
.hModule
= 0;
178 lpNewTask
->te
.hInst
= hInst
;
179 lpNewTask
->te
.hTask
= hTask
;
180 lpNewTask
->te
.hTaskParent
= hTaskParent
;
181 lpNewTask
->te
.wSS
= 0;
182 lpNewTask
->te
.wSP
= 0;
183 lpNewTask
->te
.wStackTop
= 0;
184 lpNewTask
->te
.wStackMinimum
= 0;
185 lpNewTask
->te
.wStackBottom
= 0;
186 lpNewTask
->te
.wcEvents
= 0;
187 lpNewTask
->te
.hQueue
= 0;
188 strcpy(lpNewTask
->te
.szModule
, module
.szModule
);
189 lpNewTask
->te
.wPSPOffset
= 0;
190 lpNewTask
->unix_pid
= getpid();
191 lpNewTask
->lpWndList
= (HWND
*) malloc(MAXWIN_PER_TASK
* sizeof(HWND
));
192 if (lpNewTask
->lpWndList
!= NULL
)
193 memset((LPSTR
)lpNewTask
->lpWndList
, 0, MAXWIN_PER_TASK
* sizeof(HWND
));
195 fprintf(stddeb
,"CreateNewTask // unix_pid=%08X return hTask=%04X\n",
196 lpNewTask
->unix_pid
, hTask
);
204 /**********************************************************************
205 * AddWindowToTask [internal]
207 BOOL
AddWindowToTask(HTASK hTask
, HWND hWnd
)
211 LPWINETASKENTRY lpTask
= lpTaskList
;
213 fprintf(stddeb
,"AddWindowToTask(%04X, %04X); !\n", hTask
, hWnd
);
216 if (lpTask
->te
.hTask
== hTask
) break;
217 if (lpTask
== NULL
) {
218 fprintf(stderr
,"AddWindowToTask // hTask=%04X not found !\n", hTask
);
221 lpTask
= lpTask
->lpNextTask
;
223 wptr
= lpTask
->lpWndList
;
224 if (wptr
== NULL
) return FALSE
;
225 while (*(wptr
) != 0) {
226 if (++count
>= MAXWIN_PER_TASK
) return FALSE
;
231 fprintf(stddeb
,"AddWindowToTask // window added, count=%d !\n", count
);
237 /**********************************************************************
238 * RemoveWindowFromTask [internal]
240 BOOL
RemoveWindowFromTask(HTASK hTask
, HWND hWnd
)
244 LPWINETASKENTRY lpTask
= lpTaskList
;
246 fprintf(stddeb
,"RemoveWindowToTask(%04X, %04X); !\n", hTask
, hWnd
);
249 if (lpTask
->te
.hTask
== hTask
) break;
250 if (lpTask
== NULL
) {
251 fprintf(stderr
,"RemoveWindowFromTask // hTask=%04X not found !\n", hTask
);
254 lpTask
= lpTask
->lpNextTask
;
256 wptr
= lpTask
->lpWndList
;
257 if (wptr
== NULL
) return FALSE
;
258 while (*(wptr
) != hWnd
) {
259 if (++count
>= MAXWIN_PER_TASK
) return FALSE
;
262 while (*(wptr
) != 0) {
263 *(wptr
) = *(wptr
+ 1);
264 if (++count
>= MAXWIN_PER_TASK
) return FALSE
;
268 fprintf(stddeb
,"RemoveWindowFromTask // window removed, count=%d !\n", --count
);
273 BOOL
TaskFirst(LPTASKENTRY lpTask
)
276 fprintf(stddeb
,"TaskFirst(%8x)\n", (int) lpTask
);
279 memcpy(lpTask
, &lpTaskList
->te
, lpTask
->dwSize
);
285 BOOL
TaskNext(LPTASKENTRY lpTask
)
287 LPWINETASKENTRY list
;
289 fprintf(stddeb
,"TaskNext(%8x)\n", (int) lpTask
);
293 if (list
->te
.hTask
== lpTask
->hTask
) {
294 list
= list
->lpNextTask
;
296 memcpy(lpTask
, &list
->te
, lpTask
->dwSize
);
301 list
= list
->lpNextTask
;
306 BOOL
TaskFindHandle(LPTASKENTRY lpTask
, HTASK hTask
)
308 static LPWINETASKENTRY list
;
310 fprintf(stddeb
,"TaskFindHandle(%8x,%4x)\n", (int) lpTask
, hTask
);
314 if (list
->te
.hTask
== hTask
) {
315 list
= list
->lpNextTask
;
317 memcpy(lpTask
, &list
->te
, lpTask
->dwSize
);
322 list
= list
->lpNextTask
;