| 1 |  | 
|---|
| 2 | /*********************************************************************** | 
|---|
| 3 |  | 
|---|
| 4 | $Id: killproc.c 1480 2009-11-22 22:58:49Z gyoung $ | 
|---|
| 5 |  | 
|---|
| 6 | Kill a process | 
|---|
| 7 |  | 
|---|
| 8 | Copyright (c) 1993-98 M. Kimes | 
|---|
| 9 | Copyright (c) 2005, 2008 Steven H. Levine | 
|---|
| 10 |  | 
|---|
| 11 | 24 May 05 SHL Rework Win_Error usage | 
|---|
| 12 | 14 Jul 06 SHL Use Runtime_Error | 
|---|
| 13 | 29 Jul 06 SHL Use xfgets | 
|---|
| 14 | 03 Nov 06 SHL Renames | 
|---|
| 15 | 03 Nov 06 SHL Count thread usage | 
|---|
| 16 | 06 Aug 07 GKY Reduce DosSleep times (ticket 148) | 
|---|
| 17 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat | 
|---|
| 18 | 02 Sep 07 GKY Replaced DosQProcStatus with DosQuerySysState to fix trap in thunk code | 
|---|
| 19 | 02 Sep 07 SHL Expand FillKillListThread2 stack to avoid exception in __TNK | 
|---|
| 20 | 16 JUL 08 GKY Use TMP directory for temp files | 
|---|
| 21 | 10 Dec 08 SHL Integrate exception handler support | 
|---|
| 22 | 08 Mar 09 GKY Removed variable aurguments from docopyf and unlinkf (not used) | 
|---|
| 23 | 12 Jul 09 GKY Add xDosQueryAppType and xDosAlloc... to allow FM/2 to load in high memory | 
|---|
| 24 |  | 
|---|
| 25 | ***********************************************************************/ | 
|---|
| 26 |  | 
|---|
| 27 | #include <stdlib.h> | 
|---|
| 28 | #include <string.h> | 
|---|
| 29 | #include <ctype.h> | 
|---|
| 30 | // #include <process.h> | 
|---|
| 31 | #include <limits.h> | 
|---|
| 32 |  | 
|---|
| 33 | #define INCL_DOS | 
|---|
| 34 | #define INCL_DOSERRORS | 
|---|
| 35 | #define INCL_WIN | 
|---|
| 36 | #define INCL_LONGLONG                   // dircnrs.h | 
|---|
| 37 |  | 
|---|
| 38 | #include "fm3dll.h" | 
|---|
| 39 | #include "fm3dll2.h"                    // #define's for UM_*, control id's, etc. | 
|---|
| 40 | #include "init.h"                       // Data declaration(s) | 
|---|
| 41 | #include "notebook.h"                   // Data declaration(s) | 
|---|
| 42 | #include "mainwnd.h"                    // Data declaration(s) | 
|---|
| 43 | #include "fm3dlg.h" | 
|---|
| 44 | #include "fm3str.h" | 
|---|
| 45 | #include "procstat.h" | 
|---|
| 46 | #include "errutil.h"                    // Dos_Error... | 
|---|
| 47 | #include "strutil.h"                    // GetPString | 
|---|
| 48 | #include "pathutil.h"                   // BldFullPathName | 
|---|
| 49 | #include "killproc.h" | 
|---|
| 50 | #include "systemf.h"                    // ShowSession | 
|---|
| 51 | #include "common.h"                     // DecrThreadUsage, IncrThreadUsage | 
|---|
| 52 | #include "notify.h"                     // Notify | 
|---|
| 53 | #include "copyf.h"                      // unlinkf | 
|---|
| 54 | #include "wrappers.h"                   // xfgets | 
|---|
| 55 | #include "stristr.h"                    // stristr | 
|---|
| 56 | #include "misc.h"                       // PostMsg | 
|---|
| 57 | #include "fortify.h" | 
|---|
| 58 | #include "excputil.h"                   // xbeginthread | 
|---|
| 59 |  | 
|---|
| 60 | // Data definitions | 
|---|
| 61 | #pragma data_seg(DATA2) | 
|---|
| 62 |  | 
|---|
| 63 | static PSZ pszSrcFile = __FILE__; | 
|---|
| 64 |  | 
|---|
| 65 | #pragma data_seg(GLOBAL1) | 
|---|
| 66 | BOOL fUseQProcStat; | 
|---|
| 67 | BOOL fUseQSysState; | 
|---|
| 68 | PID mypid; | 
|---|
| 69 |  | 
|---|
| 70 | CHAR *GetDosPgmName(PID pid, CHAR * string) | 
|---|
| 71 | { | 
|---|
| 72 | HSWITCH hs; | 
|---|
| 73 | SWCNTRL swctl; | 
|---|
| 74 | PCH pch; | 
|---|
| 75 |  | 
|---|
| 76 | *string = 0; | 
|---|
| 77 | hs = WinQuerySwitchHandle(0, pid); | 
|---|
| 78 | if (hs) { | 
|---|
| 79 | WinQuerySwitchEntry(hs, &swctl); | 
|---|
| 80 | pch = swctl.szSwtitle; | 
|---|
| 81 | while (*pch) { | 
|---|
| 82 | if (*pch < 0x10) | 
|---|
| 83 | if (pch != swctl.szSwtitle && *(pch - 1) == 0x20) | 
|---|
| 84 | memmove(pch, pch + 1, strlen(pch)); | 
|---|
| 85 | else { | 
|---|
| 86 | *pch = 0x20; | 
|---|
| 87 | pch++; | 
|---|
| 88 | } | 
|---|
| 89 | else | 
|---|
| 90 | pch++; | 
|---|
| 91 | } | 
|---|
| 92 | strcpy(string, swctl.szSwtitle); | 
|---|
| 93 | } | 
|---|
| 94 | if (!*string) | 
|---|
| 95 | strcpy(string, GetPString(IDS_UNKNOWNDOSPROCTEXT)); | 
|---|
| 96 | return string; | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 | static VOID FillKillListThread2(VOID * arg) | 
|---|
| 100 | { | 
|---|
| 101 | HWND hwnd = *(HWND *) arg; | 
|---|
| 102 | CHAR s[1036]; | 
|---|
| 103 | HAB thab; | 
|---|
| 104 | HMQ thmq; | 
|---|
| 105 | INT rc; | 
|---|
| 106 | PROCESSINFO *ppi; | 
|---|
| 107 | BUFFHEADER *pbh; | 
|---|
| 108 | MODINFO *pmi; | 
|---|
| 109 |  | 
|---|
| 110 | # ifdef FORTIFY | 
|---|
| 111 | Fortify_EnterScope(); | 
|---|
| 112 | #  endif | 
|---|
| 113 | thab = WinInitialize(0); | 
|---|
| 114 | thmq = WinCreateMsgQueue(thab, 0); | 
|---|
| 115 | WinCancelShutdown(thmq, TRUE); | 
|---|
| 116 | IncrThreadUsage(); | 
|---|
| 117 |  | 
|---|
| 118 | WinSendDlgItemMsg(hwnd, KILL_LISTBOX, LM_DELETEALL, MPVOID, MPVOID); | 
|---|
| 119 | rc = xDosAllocMem((PVOID) & pbh, USHRT_MAX + 4096, | 
|---|
| 120 | PAG_COMMIT | PAG_READ | PAG_WRITE, pszSrcFile, __LINE__); | 
|---|
| 121 | if (rc) | 
|---|
| 122 | Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__, | 
|---|
| 123 | GetPString(IDS_OUTOFMEMORY)); | 
|---|
| 124 | else { | 
|---|
| 125 | rc = DosQProcStatus((ULONG *)pbh, USHRT_MAX); | 
|---|
| 126 | if (!rc) { | 
|---|
| 127 | ppi = pbh->ppi; | 
|---|
| 128 | while (ppi->ulEndIndicator != PROCESS_END_INDICATOR) { | 
|---|
| 129 | if (ppi->pid != mypid) { | 
|---|
| 130 | pmi = pbh->pmi; | 
|---|
| 131 | while (pmi && ppi->hModRef != pmi->hMod) | 
|---|
| 132 | pmi = pmi->pNext; | 
|---|
| 133 | if (pmi) { | 
|---|
| 134 | sprintf(s, "%04x ", ppi->pid); | 
|---|
| 135 | if (!stricmp(pmi->szModName, "SYSINIT")) | 
|---|
| 136 | GetDosPgmName(ppi->pid, s + strlen(s)); | 
|---|
| 137 | else { | 
|---|
| 138 | if (*pmi->szModName) | 
|---|
| 139 | strcat(s, pmi->szModName); | 
|---|
| 140 | else | 
|---|
| 141 | strcat(s, GetPString(IDS_UNKNOWNPROCTEXT)); | 
|---|
| 142 | } | 
|---|
| 143 | if (WinIsWindow(thab, hwnd)) { | 
|---|
| 144 | WinSendDlgItemMsg(hwnd, KILL_LISTBOX, LM_INSERTITEM, | 
|---|
| 145 | MPFROM2SHORT(LIT_SORTASCENDING, 0), | 
|---|
| 146 | MPFROMP(s)); | 
|---|
| 147 | } | 
|---|
| 148 | else | 
|---|
| 149 | break; | 
|---|
| 150 | } | 
|---|
| 151 | } | 
|---|
| 152 | ppi = (PPROCESSINFO) (ppi->ptiFirst + ppi->usThreadCount); | 
|---|
| 153 | }                                 // while | 
|---|
| 154 | } | 
|---|
| 155 | DosFreeMem(pbh); | 
|---|
| 156 | } | 
|---|
| 157 |  | 
|---|
| 158 | if (WinIsWindow(thab, hwnd)) | 
|---|
| 159 | PostMsg(hwnd, UM_CONTAINER_FILLED, MPVOID, MPVOID); | 
|---|
| 160 | WinDestroyMsgQueue(thmq); | 
|---|
| 161 | DecrThreadUsage(); | 
|---|
| 162 | WinTerminate(thab); | 
|---|
| 163 | # ifdef FORTIFY | 
|---|
| 164 | Fortify_LeaveScope(); | 
|---|
| 165 | #  endif | 
|---|
| 166 | } | 
|---|
| 167 |  | 
|---|
| 168 | static VOID FillKillListThread3(VOID * arg) | 
|---|
| 169 | { | 
|---|
| 170 | HWND hwnd = *(HWND *) arg; | 
|---|
| 171 | CHAR s[1036]; | 
|---|
| 172 | HAB thab; | 
|---|
| 173 | HMQ thmq; | 
|---|
| 174 | INT rc; | 
|---|
| 175 | QSPREC *ppi; | 
|---|
| 176 | QSPTRREC *pbh; | 
|---|
| 177 | QSLREC *pmi; | 
|---|
| 178 |  | 
|---|
| 179 | # ifdef FORTIFY | 
|---|
| 180 | Fortify_EnterScope(); | 
|---|
| 181 | #  endif | 
|---|
| 182 | thab = WinInitialize(0); | 
|---|
| 183 | thmq = WinCreateMsgQueue(thab, 0); | 
|---|
| 184 | WinCancelShutdown(thmq, TRUE); | 
|---|
| 185 | IncrThreadUsage(); | 
|---|
| 186 |  | 
|---|
| 187 | WinSendDlgItemMsg(hwnd, KILL_LISTBOX, LM_DELETEALL, MPVOID, MPVOID); | 
|---|
| 188 | rc = xDosAllocMem((PVOID) & pbh, USHRT_MAX + 4096, | 
|---|
| 189 | PAG_COMMIT | PAG_READ | PAG_WRITE, pszSrcFile, __LINE__); | 
|---|
| 190 | if (rc) | 
|---|
| 191 | Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__, | 
|---|
| 192 | GetPString(IDS_OUTOFMEMORY)); | 
|---|
| 193 | else { | 
|---|
| 194 | rc = DosQuerySysState(QS_PROCESS | QS_MTE, 0, 0, 0, pbh, USHRT_MAX); | 
|---|
| 195 | if (!rc) { | 
|---|
| 196 | ppi = pbh->pProcRec; | 
|---|
| 197 | while (ppi->RecType == 1) { | 
|---|
| 198 | if (ppi->pid != mypid) { | 
|---|
| 199 | pmi = pbh->pLibRec; | 
|---|
| 200 | while (pmi && ppi->hMte != pmi->hmte) | 
|---|
| 201 | pmi = pmi->pNextRec; | 
|---|
| 202 | if (pmi) { | 
|---|
| 203 | sprintf(s, "%04x ", ppi->pid); | 
|---|
| 204 | if (!stricmp((CHAR *) pmi->pName, "SYSINIT")) | 
|---|
| 205 | GetDosPgmName(ppi->pid, s + strlen(s)); | 
|---|
| 206 | else { | 
|---|
| 207 | if (*pmi->pName) | 
|---|
| 208 | strcat(s, (CHAR *) pmi->pName); | 
|---|
| 209 | else | 
|---|
| 210 | strcat(s, GetPString(IDS_UNKNOWNPROCTEXT)); | 
|---|
| 211 | } | 
|---|
| 212 | if (WinIsWindow(thab, hwnd)) { | 
|---|
| 213 | WinSendDlgItemMsg(hwnd, KILL_LISTBOX, LM_INSERTITEM, | 
|---|
| 214 | MPFROM2SHORT(LIT_SORTASCENDING, 0), | 
|---|
| 215 | MPFROMP(s)); | 
|---|
| 216 | } | 
|---|
| 217 | else | 
|---|
| 218 | break; | 
|---|
| 219 | } | 
|---|
| 220 | } | 
|---|
| 221 | ppi = (QSPREC *) (ppi->pThrdRec + ppi->cTCB);   // 22 Jun 08 SHL fixme to know why this looks odd | 
|---|
| 222 | }                                 // while | 
|---|
| 223 | } | 
|---|
| 224 | DosFreeMem(pbh); | 
|---|
| 225 | } | 
|---|
| 226 |  | 
|---|
| 227 | if (WinIsWindow(thab, hwnd)) | 
|---|
| 228 | PostMsg(hwnd, UM_CONTAINER_FILLED, MPVOID, MPVOID); | 
|---|
| 229 | WinDestroyMsgQueue(thmq); | 
|---|
| 230 | DecrThreadUsage(); | 
|---|
| 231 | WinTerminate(thab); | 
|---|
| 232 | # ifdef FORTIFY | 
|---|
| 233 | Fortify_LeaveScope(); | 
|---|
| 234 | #  endif | 
|---|
| 235 | } | 
|---|
| 236 |  | 
|---|
| 237 | static VOID FillKillListThread(VOID * arg) | 
|---|
| 238 | { | 
|---|
| 239 | HWND hwnd = *(HWND *) arg; | 
|---|
| 240 | CHAR s[1036], progname[1027], *p; | 
|---|
| 241 | HAB thab; | 
|---|
| 242 | HMQ thmq; | 
|---|
| 243 | FILE *fp; | 
|---|
| 244 | BOOL foundstart = FALSE; | 
|---|
| 245 | INT rc; | 
|---|
| 246 | CHAR *startstring = "Process and Thread Information"; | 
|---|
| 247 | CHAR *endstring = "System Semaphore Information"; | 
|---|
| 248 | PID pid; | 
|---|
| 249 | HFILE oldstdout, newstdout; | 
|---|
| 250 |  | 
|---|
| 251 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 252 |  | 
|---|
| 253 | # ifdef FORTIFY | 
|---|
| 254 | Fortify_EnterScope(); | 
|---|
| 255 | #  endif | 
|---|
| 256 | thab = WinInitialize(0); | 
|---|
| 257 | thmq = WinCreateMsgQueue(thab, 0); | 
|---|
| 258 | WinCancelShutdown(thmq, TRUE); | 
|---|
| 259 | IncrThreadUsage(); | 
|---|
| 260 |  | 
|---|
| 261 | WinSendDlgItemMsg(hwnd, KILL_LISTBOX, LM_DELETEALL, MPVOID, MPVOID); | 
|---|
| 262 | BldFullPathName(s, pTmpDir, "$PSTAT#$.#$#"); | 
|---|
| 263 | unlinkf(s); | 
|---|
| 264 | fp = fopen(s, "w"); | 
|---|
| 265 | if (!fp) { | 
|---|
| 266 | Win_Error(NULLHANDLE, HWND_DESKTOP, __FILE__, __LINE__, | 
|---|
| 267 | GetPString(IDS_REDIRECTERRORTEXT)); | 
|---|
| 268 | goto Abort; | 
|---|
| 269 | } | 
|---|
| 270 | else { | 
|---|
| 271 | newstdout = -1; | 
|---|
| 272 | rc = DosDupHandle(fileno(stdout), &newstdout); | 
|---|
| 273 | if (rc) | 
|---|
| 274 | Dos_Error(MB_CANCEL, rc, hwnd, __FILE__, __LINE__, PCSZ_DOSDUPHANDLE); | 
|---|
| 275 | oldstdout = fileno(stdout); | 
|---|
| 276 | DosDupHandle(fileno(fp), &oldstdout); | 
|---|
| 277 | rc = runemf2(SEPARATE | INVISIBLE | FULLSCREEN | BACKGROUND | WAIT, | 
|---|
| 278 | hwnd, pszSrcFile, __LINE__, NULL, NULL, | 
|---|
| 279 | "%s", "PSTAT.EXE /C"); | 
|---|
| 280 | oldstdout = fileno(stdout); | 
|---|
| 281 | DosDupHandle(newstdout, &oldstdout); | 
|---|
| 282 | DosClose(newstdout); | 
|---|
| 283 | fclose(fp); | 
|---|
| 284 | // fixme to be gone? | 
|---|
| 285 | if (rc == -1) { | 
|---|
| 286 | saymsg(MB_CANCEL, | 
|---|
| 287 | hwnd, | 
|---|
| 288 | GetPString(IDS_ARGHTEXT), GetPString(IDS_CANTRUNPSTATTEXT)); | 
|---|
| 289 | goto Abort; | 
|---|
| 290 | } | 
|---|
| 291 | } | 
|---|
| 292 | fp = fopen(s, "r"); | 
|---|
| 293 | if (fp) { | 
|---|
| 294 | while (!feof(fp)) { | 
|---|
| 295 | strset(s, 0); | 
|---|
| 296 | if (!xfgets(s, 1025, fp, pszSrcFile, __LINE__)) | 
|---|
| 297 | break; | 
|---|
| 298 | if (!foundstart) { | 
|---|
| 299 | if (*s == ' ' && strstr(s, startstring)) | 
|---|
| 300 | foundstart = TRUE; | 
|---|
| 301 | } | 
|---|
| 302 | else { | 
|---|
| 303 | if (*s == ' ' && strstr(s, endstring)) | 
|---|
| 304 | break; | 
|---|
| 305 | if (*s == ' ' && s[5] == ' ' && isxdigit(s[1]) && | 
|---|
| 306 | isxdigit(s[2]) && isxdigit(s[3]) && isxdigit(s[4])) { | 
|---|
| 307 | p = &s[1]; | 
|---|
| 308 | pid = strtol(&s[1], &p, 16); | 
|---|
| 309 | if (pid && pid != mypid) { | 
|---|
| 310 | strcpy(progname, &s[30]); | 
|---|
| 311 | p = strchr(progname, ' '); | 
|---|
| 312 | if (p) | 
|---|
| 313 | *p = 0; | 
|---|
| 314 | if (!stristr(progname, "\\PSTAT.EXE")) { | 
|---|
| 315 | sprintf(s, "%04x %s", pid, progname); | 
|---|
| 316 | WinSendDlgItemMsg(hwnd, | 
|---|
| 317 | KILL_LISTBOX, | 
|---|
| 318 | LM_INSERTITEM, | 
|---|
| 319 | MPFROM2SHORT(LIT_SORTASCENDING, 0), | 
|---|
| 320 | MPFROMP(s)); | 
|---|
| 321 | } | 
|---|
| 322 | } | 
|---|
| 323 | } | 
|---|
| 324 | } | 
|---|
| 325 | } | 
|---|
| 326 | fclose(fp); | 
|---|
| 327 | } | 
|---|
| 328 | Abort: | 
|---|
| 329 | BldFullPathName(s, pTmpDir, "$PSTAT#$.#$#"); | 
|---|
| 330 | DosForceDelete(s); | 
|---|
| 331 | PostMsg(hwnd, UM_CONTAINER_FILLED, MPVOID, MPVOID); | 
|---|
| 332 | WinDestroyMsgQueue(thmq); | 
|---|
| 333 | DecrThreadUsage(); | 
|---|
| 334 | WinTerminate(thab); | 
|---|
| 335 | # ifdef FORTIFY | 
|---|
| 336 | Fortify_LeaveScope(); | 
|---|
| 337 | #  endif | 
|---|
| 338 | } | 
|---|
| 339 |  | 
|---|
| 340 | MRESULT EXPENTRY KillDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 
|---|
| 341 | { | 
|---|
| 342 | SHORT sSelect; | 
|---|
| 343 | PID pid; | 
|---|
| 344 | static BOOL listdone; | 
|---|
| 345 | static HPOINTER hptrIcon = (HPOINTER) 0; | 
|---|
| 346 |  | 
|---|
| 347 | switch (msg) { | 
|---|
| 348 | case WM_INITDLG: | 
|---|
| 349 | hptrIcon = WinLoadPointer(HWND_DESKTOP, FM3ModHandle, KILL_FRAME); | 
|---|
| 350 | WinDefDlgProc(hwnd, WM_SETICON, MPFROMLONG(hptrIcon), MPVOID); | 
|---|
| 351 | WinCheckButton(hwnd, KILL_CHECKBOX, fUseQProcStat); | 
|---|
| 352 | WinCheckButton(hwnd, KILL2_CHECKBOX, fUseQSysState); | 
|---|
| 353 | if (WinQueryButtonCheckstate(hwnd, KILL2_CHECKBOX)) { | 
|---|
| 354 | WinCheckButton(hwnd, KILL_CHECKBOX, FALSE); | 
|---|
| 355 | WinEnableWindow(WinWindowFromID(hwnd, KILL_CHECKBOX), FALSE); | 
|---|
| 356 | } | 
|---|
| 357 | if (WinQueryButtonCheckstate(hwnd, KILL_CHECKBOX)) { | 
|---|
| 358 | WinCheckButton(hwnd, KILL2_CHECKBOX, FALSE); | 
|---|
| 359 | WinEnableWindow(WinWindowFromID(hwnd, KILL2_CHECKBOX), FALSE); | 
|---|
| 360 | } | 
|---|
| 361 | PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(KILL_RESCAN, 0), MPVOID); | 
|---|
| 362 | break; | 
|---|
| 363 |  | 
|---|
| 364 | case UM_CONTAINER_FILLED: | 
|---|
| 365 | listdone = TRUE; | 
|---|
| 366 | if ((SHORT) WinSendDlgItemMsg(hwnd, | 
|---|
| 367 | KILL_LISTBOX, | 
|---|
| 368 | LM_QUERYITEMCOUNT, MPVOID, MPVOID) == 0) { | 
|---|
| 369 | if (!fUseQProcStat) | 
|---|
| 370 | saymsg(MB_CANCEL, | 
|---|
| 371 | hwnd, | 
|---|
| 372 | GetPString(IDS_ICHOKEDTEXT), GetPString(IDS_ISPSTATTHERETEXT)); | 
|---|
| 373 | else | 
|---|
| 374 | saymsg(MB_CANCEL, | 
|---|
| 375 | hwnd, | 
|---|
| 376 | GetPString(IDS_ICHOKEDTEXT), | 
|---|
| 377 | GetPString(IDS_DOSQPROCSTATFAILEDTEXT)); | 
|---|
| 378 | } | 
|---|
| 379 | return 0; | 
|---|
| 380 |  | 
|---|
| 381 | case WM_CONTROL: | 
|---|
| 382 | switch (SHORT1FROMMP(mp1)) { | 
|---|
| 383 | case KILL_CHECKBOX: | 
|---|
| 384 | fUseQProcStat = WinQueryButtonCheckstate(hwnd, KILL_CHECKBOX); | 
|---|
| 385 | PrfWriteProfileData(fmprof, | 
|---|
| 386 | FM3Str, | 
|---|
| 387 | "UseQProcStat", &fUseQProcStat, sizeof(BOOL)); | 
|---|
| 388 | PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(KILL_RESCAN, 0), MPVOID); | 
|---|
| 389 | if (WinQueryButtonCheckstate(hwnd, KILL_CHECKBOX)) { | 
|---|
| 390 | WinCheckButton(hwnd, KILL2_CHECKBOX, FALSE); | 
|---|
| 391 | WinEnableWindow(WinWindowFromID(hwnd, KILL2_CHECKBOX), FALSE); | 
|---|
| 392 | } | 
|---|
| 393 | else | 
|---|
| 394 | WinEnableWindow(WinWindowFromID(hwnd, KILL2_CHECKBOX), TRUE); | 
|---|
| 395 | break; | 
|---|
| 396 | case KILL2_CHECKBOX: | 
|---|
| 397 | fUseQSysState = WinQueryButtonCheckstate(hwnd, KILL2_CHECKBOX); | 
|---|
| 398 | PrfWriteProfileData(fmprof, | 
|---|
| 399 | FM3Str, | 
|---|
| 400 | "UseQSysState", &fUseQSysState, sizeof(BOOL)); | 
|---|
| 401 | PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(KILL_RESCAN, 0), MPVOID); | 
|---|
| 402 | if (WinQueryButtonCheckstate(hwnd, KILL2_CHECKBOX)) { | 
|---|
| 403 | WinCheckButton(hwnd, KILL_CHECKBOX, FALSE); | 
|---|
| 404 | WinEnableWindow(WinWindowFromID(hwnd, KILL_CHECKBOX), FALSE); | 
|---|
| 405 | } | 
|---|
| 406 | else | 
|---|
| 407 | WinEnableWindow(WinWindowFromID(hwnd, KILL_CHECKBOX), TRUE); | 
|---|
| 408 | break; | 
|---|
| 409 |  | 
|---|
| 410 | case KILL_LISTBOX: | 
|---|
| 411 | switch (SHORT2FROMMP(mp2)) { | 
|---|
| 412 | case LN_ENTER: | 
|---|
| 413 | WinSendDlgItemMsg(hwnd, DID_OK, BM_CLICK, MPFROMSHORT(TRUE), MPVOID); | 
|---|
| 414 | break; | 
|---|
| 415 | } | 
|---|
| 416 | break; | 
|---|
| 417 |  | 
|---|
| 418 | default: | 
|---|
| 419 | break; | 
|---|
| 420 | } | 
|---|
| 421 | return 0; | 
|---|
| 422 |  | 
|---|
| 423 | case WM_ADJUSTWINDOWPOS: | 
|---|
| 424 | PostMsg(hwnd, UM_STRETCH, MPVOID, MPVOID); | 
|---|
| 425 | break; | 
|---|
| 426 |  | 
|---|
| 427 | case UM_STRETCH: | 
|---|
| 428 | { | 
|---|
| 429 | SWP swpC, swp, swpH; | 
|---|
| 430 |  | 
|---|
| 431 | WinQueryWindowPos(hwnd, &swp); | 
|---|
| 432 | if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE))) { | 
|---|
| 433 | WinQueryWindowPos(WinWindowFromID(hwnd, KILL_LISTBOX), &swpC); | 
|---|
| 434 | WinQueryWindowPos(WinWindowFromID(hwnd, KILL_HDR), &swpH); | 
|---|
| 435 | WinSetWindowPos(WinWindowFromID(hwnd, KILL_LISTBOX), HWND_TOP, | 
|---|
| 436 | SysVal(SV_CXSIZEBORDER), | 
|---|
| 437 | swpC.y, | 
|---|
| 438 | swp.cx - (SysVal(SV_CXSIZEBORDER) * 2), | 
|---|
| 439 | ((swp.cy - swpC.y) - (SysVal(SV_CYTITLEBAR) + | 
|---|
| 440 | SysVal(SV_CYSIZEBORDER)) - | 
|---|
| 441 | (swpH.cy + 8)), SWP_MOVE | SWP_SIZE); | 
|---|
| 442 | WinSetWindowPos(WinWindowFromID(hwnd, KILL_HDR), HWND_TOP, | 
|---|
| 443 | SysVal(SV_CXSIZEBORDER) + 4, | 
|---|
| 444 | swpC.y + ((swp.cy - swpC.y) - | 
|---|
| 445 | (SysVal(SV_CYTITLEBAR) + | 
|---|
| 446 | SysVal(SV_CYSIZEBORDER)) - | 
|---|
| 447 | (swpH.cy + 4)), swpH.cx, swpH.cy, SWP_MOVE); | 
|---|
| 448 | } | 
|---|
| 449 | } | 
|---|
| 450 | return 0; | 
|---|
| 451 |  | 
|---|
| 452 | case WM_COMMAND: | 
|---|
| 453 | switch (SHORT1FROMMP(mp1)) { | 
|---|
| 454 | case KILL_RESCAN: | 
|---|
| 455 | listdone = FALSE; | 
|---|
| 456 | if (fUseQProcStat) { | 
|---|
| 457 | if (xbeginthread(FillKillListThread2, | 
|---|
| 458 | 65536 + 8192, | 
|---|
| 459 | &hwnd, | 
|---|
| 460 | pszSrcFile, | 
|---|
| 461 | __LINE__) == -1) | 
|---|
| 462 | { | 
|---|
| 463 | WinDismissDlg(hwnd, 0); | 
|---|
| 464 | } | 
|---|
| 465 | else | 
|---|
| 466 | DosSleep(100);                // 05 Aug 07 GKY 250 | 
|---|
| 467 | } | 
|---|
| 468 | else if (fUseQSysState) | 
|---|
| 469 | if (xbeginthread(FillKillListThread3, | 
|---|
| 470 | 65536, | 
|---|
| 471 | &hwnd, | 
|---|
| 472 | pszSrcFile, | 
|---|
| 473 | __LINE__) == -1) | 
|---|
| 474 | { | 
|---|
| 475 | WinDismissDlg(hwnd, 0); | 
|---|
| 476 | } | 
|---|
| 477 | else | 
|---|
| 478 | DosSleep(100);//05 Aug 07 GKY 250 | 
|---|
| 479 | else { | 
|---|
| 480 | if (xbeginthread(FillKillListThread, | 
|---|
| 481 | 65536, | 
|---|
| 482 | &hwnd, | 
|---|
| 483 | pszSrcFile, | 
|---|
| 484 | __LINE__) == -1) | 
|---|
| 485 | { | 
|---|
| 486 | WinDismissDlg(hwnd, 0); | 
|---|
| 487 | } | 
|---|
| 488 | else | 
|---|
| 489 | DosSleep(100);                // 05 Aug 07 GKY 250 | 
|---|
| 490 | } | 
|---|
| 491 | break; | 
|---|
| 492 |  | 
|---|
| 493 | case KILL_SHOW: | 
|---|
| 494 | case DID_OK: | 
|---|
| 495 | sSelect = (USHORT) WinSendDlgItemMsg(hwnd, | 
|---|
| 496 | KILL_LISTBOX, | 
|---|
| 497 | LM_QUERYSELECTION, | 
|---|
| 498 | MPFROMSHORT(LIT_FIRST), MPVOID); | 
|---|
| 499 | if (sSelect >= 0) { | 
|---|
| 500 |  | 
|---|
| 501 | CHAR s[31], *p; | 
|---|
| 502 | APIRET error; | 
|---|
| 503 |  | 
|---|
| 504 | *s = 0; | 
|---|
| 505 | WinSendDlgItemMsg(hwnd, | 
|---|
| 506 | KILL_LISTBOX, | 
|---|
| 507 | LM_QUERYITEMTEXT, | 
|---|
| 508 | MPFROM2SHORT(sSelect, 30), MPFROMP(s)); | 
|---|
| 509 | if (*s) { | 
|---|
| 510 | p = s; | 
|---|
| 511 | pid = strtol(s, &p, 16); | 
|---|
| 512 | if (pid) { | 
|---|
| 513 | if (SHORT1FROMMP(mp1) == DID_OK) { | 
|---|
| 514 | error = DosKillProcess(DKP_PROCESS, pid); | 
|---|
| 515 | if (error && error != ERROR_INVALID_PROCID) { | 
|---|
| 516 | Dos_Error(MB_CANCEL, | 
|---|
| 517 | error, | 
|---|
| 518 | hwnd, | 
|---|
| 519 | __FILE__, | 
|---|
| 520 | __LINE__, GetPString(IDS_DOSKILLFAILEDTEXT)); | 
|---|
| 521 | } | 
|---|
| 522 | else | 
|---|
| 523 | WinSendDlgItemMsg(hwnd, | 
|---|
| 524 | KILL_LISTBOX, | 
|---|
| 525 | LM_DELETEITEM, | 
|---|
| 526 | MPFROM2SHORT(sSelect, 0), MPVOID); | 
|---|
| 527 | } | 
|---|
| 528 | else if (!ShowSession(hwnd, pid)) | 
|---|
| 529 | Notify(GetPString(IDS_SORRYCANTSHOWTEXT)); | 
|---|
| 530 | } | 
|---|
| 531 | } | 
|---|
| 532 | } | 
|---|
| 533 | break; | 
|---|
| 534 |  | 
|---|
| 535 | case DID_CANCEL: | 
|---|
| 536 | if (!listdone) | 
|---|
| 537 | Runtime_Error(pszSrcFile, __LINE__, "busy"); | 
|---|
| 538 | else | 
|---|
| 539 | WinDismissDlg(hwnd, 0); | 
|---|
| 540 | break; | 
|---|
| 541 |  | 
|---|
| 542 | case IDM_HELP: | 
|---|
| 543 | saymsg(MB_ENTER | MB_ICONASTERISK, | 
|---|
| 544 | hwnd, | 
|---|
| 545 | GetPString(IDS_KILLPROCHELPTITLETEXT), | 
|---|
| 546 | GetPString(IDS_KILLPROCHELPTEXT)); | 
|---|
| 547 | break; | 
|---|
| 548 | } | 
|---|
| 549 | return 0; | 
|---|
| 550 |  | 
|---|
| 551 | case WM_CLOSE: | 
|---|
| 552 | if (!listdone) { | 
|---|
| 553 | Runtime_Error(pszSrcFile, __LINE__, "busy"); | 
|---|
| 554 | return 0; | 
|---|
| 555 | } | 
|---|
| 556 | break; | 
|---|
| 557 |  | 
|---|
| 558 | case WM_DESTROY: | 
|---|
| 559 | if (hptrIcon) | 
|---|
| 560 | WinDestroyPointer(hptrIcon); | 
|---|
| 561 | hptrIcon = (HPOINTER) 0; | 
|---|
| 562 | break; | 
|---|
| 563 | } | 
|---|
| 564 | return WinDefDlgProc(hwnd, msg, mp1, mp2); | 
|---|
| 565 | } | 
|---|
| 566 |  | 
|---|
| 567 | #pragma alloc_text(KILLPROC,FillKillListThread,FillKillListThread2,GetDosPgmName,KillDlgProc) | 
|---|
| 568 | #pragma alloc_text(KILLPROC,FillKillListThread3) | 
|---|