home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / rwp15.zip / PIBTIB.C < prev    next >
C/C++ Source or Header  |  1993-03-24  |  4KB  |  119 lines

  1. /* --------------------------------------------------------------------
  2.                           Thread Information
  3.                               Chapter 15
  4.  
  5.                     Real World Programming for OS/2
  6.              Copyright (c) 1993 Blain, Delimon, and English
  7. -------------------------------------------------------------------- */
  8.  
  9. #define INCL_DOS
  10. #define INCL_WIN
  11.  
  12. #include <os2.h>
  13. #include <string.h>
  14. #include <stdio.h>
  15. #include "pibtib.h"
  16.  
  17. /* External variables */
  18. extern HAB      hab;                    /* Handle to anchor block       */
  19.  
  20. /* Local Functions    */
  21. VOID ParseEnvironment (HWND,PCHAR,USHORT);
  22. VOID SetNumberField   (HWND,ULONG,USHORT);
  23.  
  24. char szProcType[4][18] =
  25.     {
  26.         "Unknown",
  27.         "Not Window Compat",
  28.         "Window Compat",
  29.         "Window API"
  30.     };
  31.  
  32. /* ----------------------- Local Functions ----------------------- */
  33.  
  34. VOID ParseEnvironment (HWND hWnd, PCHAR pEnv, USHORT usCtlID)
  35. {
  36.     /* Parse the environment buffer.  Each line is terminated by a NULL
  37.        byte and the last line in the buffer includes an additional NULL
  38.        byte */
  39.     while (*pEnv)
  40.     {
  41.         WinSendDlgItemMsg (hWnd, usCtlID, LM_INSERTITEM, (MPARAM)LIT_END, pEnv);
  42.         pEnv += strlen(pEnv) + 1;
  43.     }
  44.  
  45.     return;
  46. }
  47.  
  48. VOID SetNumberField (HWND hWnd, ULONG ulNumber, USHORT usCtlID)
  49. {
  50.     CHAR    szNumber[9];
  51.  
  52.     /* Convert number to hexadecimal string */
  53.     sprintf (szNumber, "%8lx", ulNumber);
  54.     WinUpper (hab, 0, 0, szNumber);
  55.  
  56.     /* Set the text of the control */
  57.     WinSetDlgItemText (hWnd, usCtlID, szNumber);
  58.  
  59.     return;
  60. }
  61.  
  62. /* ----------------------  Dialog Function ----------------------- */
  63.  
  64. MRESULT EXPENTRY PIBTIBDlgProc (HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  65. {
  66.     BOOL    bHandled = TRUE;
  67.     MRESULT mReturn  = 0;
  68.     PPIB    ppib;
  69.     PTIB    ptib;
  70.  
  71.                                          
  72.     switch (msg)
  73.     {           
  74.         case WM_INITDLG:
  75.             /* Query the thread information */
  76.             DosGetInfoBlocks (&ptib, &ppib);
  77.  
  78.             SetNumberField (hWnd, ppib->pib_ulpid,                IDC_PID);
  79.             SetNumberField (hWnd, ppib->pib_ulppid,               IDC_PPID);
  80.             SetNumberField (hWnd, ppib->pib_hmte,                 IDC_MODULEHANDLE);
  81.             SetNumberField (hWnd, ppib->pib_flstatus,             IDC_STATUS);
  82.             WinSetDlgItemText (hWnd, IDC_TYPE, szProcType[ppib->pib_ultype & 0x03]);
  83.             SetNumberField (hWnd, (ptib->tib_ptib2)->tib2_ultid,  IDC_TID);
  84.             SetNumberField (hWnd, (ptib->tib_ptib2)->tib2_ulpri,  IDC_PRIORITY);
  85.  
  86.             /* The OS/2 2.0 Toolkit defines this field as tib_arbpointer */
  87.             /* The OS/2 2.1 Toolkit defines this field as tib_ordinal    */
  88.             SetNumberField (hWnd, (ULONG)ptib->tib_ordinal,       IDC_SLOT);
  89.  
  90.             SetNumberField (hWnd, (ULONG)ptib->tib_pstack,        IDC_STACKBASE);
  91.             SetNumberField (hWnd, (ULONG)ptib->tib_pstacklimit,   IDC_STACKEND);
  92.             WinSendDlgItemMsg (hWnd, IDC_COMMANDLINE, EM_SETTEXTLIMIT, 
  93.                 MPFROMSHORT(255), 0L);
  94.             WinSetDlgItemText (hWnd, IDC_COMMANDLINE, ppib->pib_pchcmd);
  95.             ParseEnvironment (hWnd, ppib->pib_pchenv, IDC_ENVIRONMENT);
  96.             break;
  97.  
  98.         case WM_SYSCOMMAND:
  99.               switch (SHORT1FROMMP(mp1))
  100.             {
  101.                     case SC_CLOSE:
  102.                     WinDismissDlg (hWnd, FALSE);
  103.                     bHandled = TRUE;
  104.                     break;
  105.             }
  106.             break;
  107.  
  108.         default:
  109.             bHandled = FALSE;
  110.             break;
  111.     }
  112.  
  113.     if (!bHandled)
  114.         mReturn = WinDefDlgProc (hWnd, msg, mp1, mp2);
  115.  
  116.     return (mReturn);
  117. }
  118.  
  119.