4 static char Copyright[] = "Copyright Martin Ayotte, 1994";
17 static LPWINETASKENTRY lpTaskList
= NULL
;
18 static int nTaskCount
= 0;
20 /**********************************************************************
21 * GetCurrentTask [KERNEL.36]
23 HTASK
GetCurrentTask(void)
25 LPWINETASKENTRY lpTask
= lpTaskList
;
27 dprintf_task(stddeb
,"GetCurrentTask() // unix_pid=%08X !\n", pid
);
28 if (lpTask
== NULL
) return 0;
30 if (lpTask
->unix_pid
== pid
) break;
31 if (lpTask
->lpNextTask
== NULL
) return 0;
32 lpTask
= lpTask
->lpNextTask
;
34 dprintf_task(stddeb
,"GetCurrentTask() returned hTask=%04X !\n", lpTask
->te
.hTask
);
35 return lpTask
->te
.hTask
;
39 /**********************************************************************
40 * GetNumTasks [KERNEL.152]
42 WORD
GetNumTasks(void)
44 dprintf_task(stddeb
,"GetNumTasks() returned %d !\n", nTaskCount
);
49 /**********************************************************************
50 * GetWindowTask [USER.224]
52 HTASK
GetWindowTask(HWND hWnd
)
56 LPWINETASKENTRY lpTask
= lpTaskList
;
57 dprintf_task(stddeb
,"GetWindowTask(%04X) !\n", hWnd
);
58 while (lpTask
!= NULL
) {
59 wptr
= lpTask
->lpWndList
;
62 while (++count
< MAXWIN_PER_TASK
) {
63 dprintf_task(stddeb
,"GetWindowTask // searching %04X %04X !\n",
64 lpTask
->te
.hTask
, *(wptr
));
65 if (*(wptr
) == hWnd
) {
66 dprintf_task(stddeb
,"GetWindowTask(%04X) found hTask=%04X !\n",
67 hWnd
, lpTask
->te
.hTask
);
68 return lpTask
->te
.hTask
;
73 lpTask
= lpTask
->lpNextTask
;
79 /**********************************************************************
80 * EnumTaskWindows [USER.225]
82 BOOL
EnumTaskWindows(HANDLE hTask
, FARPROC lpEnumFunc
, LONG lParam
)
87 LPWINETASKENTRY lpTask
= lpTaskList
;
88 dprintf_task(stddeb
,"EnumTaskWindows(%04X, %08X, %08X) !\n", hTask
,
89 (unsigned int) lpEnumFunc
, (unsigned int) lParam
);
91 if (lpTask
->te
.hTask
== hTask
) break;
93 dprintf_task(stddeb
,"EnumTaskWindows // hTask=%04X not found !\n", hTask
);
96 lpTask
= lpTask
->lpNextTask
;
98 dprintf_task(stddeb
,"EnumTaskWindows // found hTask=%04X !\n", hTask
);
99 wptr
= lpTask
->lpWndList
;
100 if (wptr
== NULL
) return FALSE
;
101 if (lpEnumFunc
== NULL
) return FALSE
;
102 while ((hWnd
= *(wptr
++)) != 0) {
103 if (++count
>= MAXWIN_PER_TASK
) return FALSE
;
104 dprintf_task(stddeb
,"EnumTaskWindows // hWnd=%04X count=%d !\n", hWnd
, count
);
106 bRet
= (*lpEnumFunc
)(hWnd
, lParam
);
108 bRet
= CallBack16(lpEnumFunc
, 2, 0, (int)hWnd
, 2, (int)lParam
);
110 if (bRet
== 0) break;
116 /**********************************************************************
117 * CreateNewTask [internal]
119 HANDLE
CreateNewTask(HINSTANCE hInst
, HTASK hTaskParent
)
122 LPWINETASKENTRY lpTask
= lpTaskList
;
123 LPWINETASKENTRY lpNewTask
;
126 module
.dwSize
= sizeof(module
);
127 ModuleFindHandle(&module
, hInst
);
129 if (lpTask
!= NULL
) {
131 if (lpTask
->lpNextTask
== NULL
) break;
132 lpTask
= lpTask
->lpNextTask
;
135 hTask
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(WINETASKENTRY
));
136 lpNewTask
= (LPWINETASKENTRY
) GlobalLock(hTask
);
137 dprintf_task(stddeb
,"CreateNewTask entry allocated %p\n", lpNewTask
);
138 if (lpNewTask
== NULL
) return 0;
139 if (lpTaskList
== NULL
) {
140 lpTaskList
= lpNewTask
;
141 lpNewTask
->lpPrevTask
= NULL
;
144 lpTask
->lpNextTask
= lpNewTask
;
145 lpTask
->te
.hNext
= lpNewTask
->te
.hTask
;
146 lpNewTask
->lpPrevTask
= lpTask
;
148 lpNewTask
->lpNextTask
= NULL
;
149 lpNewTask
->hIcon
= 0;
150 lpNewTask
->te
.dwSize
= sizeof(TASKENTRY
);
151 lpNewTask
->te
.hModule
= 0;
152 lpNewTask
->te
.hInst
= hInst
;
153 lpNewTask
->te
.hTask
= hTask
;
154 lpNewTask
->te
.hTaskParent
= hTaskParent
;
155 lpNewTask
->te
.wSS
= 0;
156 lpNewTask
->te
.wSP
= 0;
157 lpNewTask
->te
.wStackTop
= 0;
158 lpNewTask
->te
.wStackMinimum
= 0;
159 lpNewTask
->te
.wStackBottom
= 0;
160 lpNewTask
->te
.wcEvents
= 0;
161 lpNewTask
->te
.hQueue
= 0;
162 strcpy(lpNewTask
->te
.szModule
, module
.szModule
);
163 lpNewTask
->te
.wPSPOffset
= 0;
164 lpNewTask
->unix_pid
= getpid();
165 lpNewTask
->lpWndList
= (HWND
*) malloc(MAXWIN_PER_TASK
* sizeof(HWND
));
166 if (lpNewTask
->lpWndList
!= NULL
)
167 memset((LPSTR
)lpNewTask
->lpWndList
, 0, MAXWIN_PER_TASK
* sizeof(HWND
));
168 dprintf_task(stddeb
,"CreateNewTask // unix_pid=%08X return hTask=%04X\n",
169 lpNewTask
->unix_pid
, hTask
);
176 /**********************************************************************
177 * AddWindowToTask [internal]
179 BOOL
AddWindowToTask(HTASK hTask
, HWND hWnd
)
183 LPWINETASKENTRY lpTask
= lpTaskList
;
184 dprintf_task(stddeb
,"AddWindowToTask(%04X, %04X); !\n", hTask
, hWnd
);
186 if (lpTask
->te
.hTask
== hTask
) break;
187 if (lpTask
== NULL
) {
188 fprintf(stderr
,"AddWindowToTask // hTask=%04X not found !\n", hTask
);
191 lpTask
= lpTask
->lpNextTask
;
193 wptr
= lpTask
->lpWndList
;
194 if (wptr
== NULL
) return FALSE
;
195 while (*(wptr
) != 0) {
196 if (++count
>= MAXWIN_PER_TASK
) return FALSE
;
200 dprintf_task(stddeb
,"AddWindowToTask // window added, count=%d !\n", count
);
205 /**********************************************************************
206 * RemoveWindowFromTask [internal]
208 BOOL
RemoveWindowFromTask(HTASK hTask
, HWND hWnd
)
212 LPWINETASKENTRY lpTask
= lpTaskList
;
213 dprintf_task(stddeb
,"RemoveWindowFromTask (%04X, %04X); !\n", hTask
, hWnd
);
215 if (lpTask
->te
.hTask
== hTask
) break;
216 if (lpTask
== NULL
) {
217 fprintf(stderr
,"RemoveWindowFromTask // hTask=%04X not found !\n", hTask
);
220 lpTask
= lpTask
->lpNextTask
;
222 wptr
= lpTask
->lpWndList
;
223 if (wptr
== NULL
) return FALSE
;
224 while (*(wptr
) != hWnd
) {
225 if (++count
>= MAXWIN_PER_TASK
) return FALSE
;
228 while (*(wptr
) != 0) {
229 *(wptr
) = *(wptr
+ 1);
230 if (++count
>= MAXWIN_PER_TASK
) return FALSE
;
233 dprintf_task(stddeb
,"RemoveWindowFromTask // window removed, count=%d !\n", --count
);
237 BOOL
TaskFirst(LPTASKENTRY lpTask
)
239 dprintf_task(stddeb
,"TaskFirst(%8x)\n", (int) lpTask
);
241 memcpy(lpTask
, &lpTaskList
->te
, lpTask
->dwSize
);
247 BOOL
TaskNext(LPTASKENTRY lpTask
)
249 LPWINETASKENTRY list
;
250 dprintf_task(stddeb
,"TaskNext(%8x)\n", (int) lpTask
);
253 if (list
->te
.hTask
== lpTask
->hTask
) {
254 list
= list
->lpNextTask
;
256 memcpy(lpTask
, &list
->te
, lpTask
->dwSize
);
261 list
= list
->lpNextTask
;
266 BOOL
TaskFindHandle(LPTASKENTRY lpTask
, HTASK hTask
)
268 static LPWINETASKENTRY list
;
269 dprintf_task(stddeb
,"TaskFindHandle(%8x,%4x)\n", (int) lpTask
, hTask
);
272 if (list
->te
.hTask
== hTask
) {
273 list
= list
->lpNextTask
;
275 memcpy(lpTask
, &list
->te
, lpTask
->dwSize
);
280 list
= list
->lpNextTask
;