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