4 static char Copyright
[] = "Copyright Martin Ayotte, 1994";
10 #include <sys/types.h>
16 /* #define DEBUG_TASK */
17 /* #undef DEBUG_TASK */
21 static LPWINETASKENTRY lpTaskList
= NULL
;
22 static int nTaskCount
= 0;
24 /**********************************************************************
25 * GetCurrentTask [KERNEL.36]
27 HTASK
GetCurrentTask()
29 LPWINETASKENTRY lpTask
= lpTaskList
;
31 dprintf_task(stddeb
,"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
;
38 dprintf_task(stddeb
,"GetCurrentTask() returned hTask=%04X !\n", lpTask
->te
.hTask
);
39 return lpTask
->te
.hTask
;
43 /**********************************************************************
44 * GetNumTasks [KERNEL.152]
48 dprintf_task(stddeb
,"GetNumTasks() returned %d !\n", nTaskCount
);
53 /**********************************************************************
54 * GetWindowTask [USER.224]
56 HTASK
GetWindowTask(HWND hWnd
)
60 LPWINETASKENTRY lpTask
= lpTaskList
;
61 dprintf_task(stddeb
,"GetWindowTask(%04X) !\n", hWnd
);
62 while (lpTask
!= NULL
) {
63 wptr
= lpTask
->lpWndList
;
66 while (++count
< MAXWIN_PER_TASK
) {
67 dprintf_task(stddeb
,"GetWindowTask // searching %04X %04X !\n",
68 lpTask
->te
.hTask
, *(wptr
));
69 if (*(wptr
) == hWnd
) {
70 dprintf_task(stddeb
,"GetWindowTask(%04X) found hTask=%04X !\n",
71 hWnd
, lpTask
->te
.hTask
);
72 return lpTask
->te
.hTask
;
77 lpTask
= lpTask
->lpNextTask
;
83 /**********************************************************************
84 * EnumTaskWindows [USER.225]
86 BOOL
EnumTaskWindows(HANDLE hTask
, FARPROC lpEnumFunc
, LONG lParam
)
91 LPWINETASKENTRY lpTask
= lpTaskList
;
92 dprintf_task(stddeb
,"EnumTaskWindows(%04X, %08X, %08X) !\n", hTask
, lpEnumFunc
, lParam
);
94 if (lpTask
->te
.hTask
== hTask
) break;
96 dprintf_task(stddeb
,"EnumTaskWindows // hTask=%04X not found !\n", hTask
);
99 lpTask
= lpTask
->lpNextTask
;
101 dprintf_task(stddeb
,"EnumTaskWindows // found hTask=%04X !\n", hTask
);
102 wptr
= lpTask
->lpWndList
;
103 if (wptr
== NULL
) return FALSE
;
104 if (lpEnumFunc
== NULL
) return FALSE
;
105 while ((hWnd
= *(wptr
++)) != 0) {
106 if (++count
>= MAXWIN_PER_TASK
) return FALSE
;
107 dprintf_task(stddeb
,"EnumTaskWindows // hWnd=%04X count=%d !\n", hWnd
, count
);
109 bRet
= (*lpEnumFunc
)(hWnd
, lParam
);
111 bRet
= CallBack16(lpEnumFunc
, 2, 0, (int)hWnd
, 2, (int)lParam
);
113 if (bRet
== 0) break;
119 /**********************************************************************
120 * CreateNewTask [internal]
122 HANDLE
CreateNewTask(HINSTANCE hInst
, HTASK hTaskParent
)
125 LPWINETASKENTRY lpTask
= lpTaskList
;
126 LPWINETASKENTRY lpNewTask
;
129 module
.dwSize
= sizeof(module
);
130 ModuleFindHandle(&module
, hInst
);
132 if (lpTask
!= NULL
) {
134 if (lpTask
->lpNextTask
== NULL
) break;
135 lpTask
= lpTask
->lpNextTask
;
138 hTask
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(WINETASKENTRY
));
139 lpNewTask
= (LPWINETASKENTRY
) GlobalLock(hTask
);
140 dprintf_task(stddeb
,"CreateNewTask entry allocated %08X\n", lpNewTask
);
141 if (lpNewTask
== NULL
) return 0;
142 if (lpTaskList
== NULL
) {
143 lpTaskList
= lpNewTask
;
144 lpNewTask
->lpPrevTask
= NULL
;
147 lpTask
->lpNextTask
= lpNewTask
;
148 lpTask
->te
.hNext
= lpNewTask
->te
.hTask
;
149 lpNewTask
->lpPrevTask
= lpTask
;
151 lpNewTask
->lpNextTask
= NULL
;
152 lpNewTask
->hIcon
= 0;
153 lpNewTask
->te
.dwSize
= sizeof(TASKENTRY
);
154 lpNewTask
->te
.hModule
= 0;
155 lpNewTask
->te
.hInst
= hInst
;
156 lpNewTask
->te
.hTask
= hTask
;
157 lpNewTask
->te
.hTaskParent
= hTaskParent
;
158 lpNewTask
->te
.wSS
= 0;
159 lpNewTask
->te
.wSP
= 0;
160 lpNewTask
->te
.wStackTop
= 0;
161 lpNewTask
->te
.wStackMinimum
= 0;
162 lpNewTask
->te
.wStackBottom
= 0;
163 lpNewTask
->te
.wcEvents
= 0;
164 lpNewTask
->te
.hQueue
= 0;
165 strcpy(lpNewTask
->te
.szModule
, module
.szModule
);
166 lpNewTask
->te
.wPSPOffset
= 0;
167 lpNewTask
->unix_pid
= getpid();
168 lpNewTask
->lpWndList
= (HWND
*) malloc(MAXWIN_PER_TASK
* sizeof(HWND
));
169 if (lpNewTask
->lpWndList
!= NULL
)
170 memset((LPSTR
)lpNewTask
->lpWndList
, 0, MAXWIN_PER_TASK
* sizeof(HWND
));
171 dprintf_task(stddeb
,"CreateNewTask // unix_pid=%08X return hTask=%04X\n",
172 lpNewTask
->unix_pid
, hTask
);
179 /**********************************************************************
180 * AddWindowToTask [internal]
182 BOOL
AddWindowToTask(HTASK hTask
, HWND hWnd
)
186 LPWINETASKENTRY lpTask
= lpTaskList
;
187 dprintf_task(stddeb
,"AddWindowToTask(%04X, %04X); !\n", hTask
, hWnd
);
189 if (lpTask
->te
.hTask
== hTask
) break;
190 if (lpTask
== NULL
) {
191 fprintf(stderr
,"AddWindowToTask // hTask=%04X not found !\n", hTask
);
194 lpTask
= lpTask
->lpNextTask
;
196 wptr
= lpTask
->lpWndList
;
197 if (wptr
== NULL
) return FALSE
;
198 while (*(wptr
) != 0) {
199 if (++count
>= MAXWIN_PER_TASK
) return FALSE
;
203 dprintf_task(stddeb
,"AddWindowToTask // window added, count=%d !\n", count
);
208 /**********************************************************************
209 * RemoveWindowFromTask [internal]
211 BOOL
RemoveWindowFromTask(HTASK hTask
, HWND hWnd
)
215 LPWINETASKENTRY lpTask
= lpTaskList
;
216 dprintf_task(stddeb
,"RemoveWindowFromTask (%04X, %04X); !\n", hTask
, hWnd
);
218 if (lpTask
->te
.hTask
== hTask
) break;
219 if (lpTask
== NULL
) {
220 fprintf(stderr
,"RemoveWindowFromTask // hTask=%04X not found !\n", hTask
);
223 lpTask
= lpTask
->lpNextTask
;
225 wptr
= lpTask
->lpWndList
;
226 if (wptr
== NULL
) return FALSE
;
227 while (*(wptr
) != hWnd
) {
228 if (++count
>= MAXWIN_PER_TASK
) return FALSE
;
231 while (*(wptr
) != 0) {
232 *(wptr
) = *(wptr
+ 1);
233 if (++count
>= MAXWIN_PER_TASK
) return FALSE
;
236 dprintf_task(stddeb
,"RemoveWindowFromTask // window removed, count=%d !\n", --count
);
240 BOOL
TaskFirst(LPTASKENTRY lpTask
)
242 dprintf_task(stddeb
,"TaskFirst(%8x)\n", (int) lpTask
);
244 memcpy(lpTask
, &lpTaskList
->te
, lpTask
->dwSize
);
250 BOOL
TaskNext(LPTASKENTRY lpTask
)
252 LPWINETASKENTRY list
;
253 dprintf_task(stddeb
,"TaskNext(%8x)\n", (int) lpTask
);
256 if (list
->te
.hTask
== lpTask
->hTask
) {
257 list
= list
->lpNextTask
;
259 memcpy(lpTask
, &list
->te
, lpTask
->dwSize
);
264 list
= list
->lpNextTask
;
269 BOOL
TaskFindHandle(LPTASKENTRY lpTask
, HTASK hTask
)
271 static LPWINETASKENTRY list
;
272 dprintf_task(stddeb
,"TaskFindHandle(%8x,%4x)\n", (int) lpTask
, hTask
);
275 if (list
->te
.hTask
== hTask
) {
276 list
= list
->lpNextTask
;
278 memcpy(lpTask
, &list
->te
, lpTask
->dwSize
);
283 list
= list
->lpNextTask
;