home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / samprog1.zip / qswlist.c < prev    next >
C/C++ Source or Header  |  1999-03-01  |  8KB  |  133 lines

  1. /********************************************************************/
  2. /*                                                                  */
  3. /* (C) Copyright IBM UK Ltd. 1996                                   */
  4. /*                                                                  */
  5. /* QSWLIST - Example of WinHAPPfromPID and WinHSWITCHfromHAPP       */
  6. /*                                                                  */
  7. /* Query an application switch list entry from its PID.             */
  8. /* Richard Moore 1st March                                          */
  9. /* Version 1.0                                                      */
  10. /*                                                                  */
  11. /* Syntax QSWLIST                                                   */
  12. /*                                                                  */
  13. /*                                                                  */
  14. /********************************************************************/
  15.  
  16. #define INCL_PMAPI
  17. #include <os2.h>
  18. #include <conio.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <stdlib.h>
  22. #include "apis.h"          /* include this if not using the toolkit for Warp E-Server */
  23.  
  24. /*************************************************************************************/
  25. /*                                                                                   */
  26. /* Purpose:                                                                          */
  27. /*                                                                                   */
  28. /* WinHAPPfromPID returns the PM Application Handle (HAPP) from the process Id.      */
  29. /* If the process Id is not a valid PM application then 0 is returned.               */
  30. /*                                                                                   */
  31. /* WinHSWITCHfromHAPP returns the handle of the switch list entry from the           */
  32. /* application handle. If the application handle is invalid or no switch list        */
  33. /* entrt exists then 0 is returned.                                                  */
  34. /*                                                                                   */
  35. /*************************************************************************************/
  36.  
  37. /*************************************************************************************/
  38. /*                                                                                   */
  39. /*        Prototype definitions for WinHAPPfromPID and WinHSWITCHfromHAPP            */
  40. /*                                                                                   */
  41. /*************************************************************************************/
  42. /*                                                                                   */
  43. /*         HAPP     APIENTRY  WinHAPPfromPID(PID pid);                               */
  44. /*                                                                                   */
  45. /*         HSWITCH  APIENTRY  WinHSWITCHfromHAPP(HAPP happ);                         */
  46. /*                                                                                   */
  47. /*************************************************************************************/
  48.  
  49. /*************************************************************************************/
  50. /*                                                                                   */
  51. /*                       Parameters to WinHAPPfromPID                                */
  52. /*                                                                                   */
  53. /*************************************************************************************/
  54. /*                                                                                   */
  55. /* pid: Process Id.                                                                  */
  56. /*                                                                                   */
  57. /*************************************************************************************/
  58.  
  59. /*************************************************************************************/
  60. /*                                                                                   */
  61. /*                       Parameters to WinHSWITCHfromHAPP                            */
  62. /*                                                                                   */
  63. /*************************************************************************************/
  64. /*                                                                                   */
  65. /* happ: Application Handle.                                                         */
  66. /*                                                                                   */
  67. /*************************************************************************************/
  68.  
  69. /*************************************************************************************/
  70. /*                                                                                   */
  71. /* WinHAPPfromPID returns a HAPP or zero.                                            */
  72. /*                                                                                   */
  73. /*************************************************************************************/
  74. /*                                                                                   */
  75. /* WinHSWITCHfromHAPP returns a HSWITCH or zero.                                     */
  76. /*                                                                                   */
  77. /*************************************************************************************/
  78.  
  79. /*************************************************************************************/
  80. /*                                                                                   */
  81. /* Remarks.                                                                          */
  82. /*                                                                                   */
  83. /*************************************************************************************/
  84. /*                                                                                   */
  85. /* WinHAPPfromHSWITCH and WinHSWITCHfromHAPP may be called from non-PM programs.     */
  86. /*                                                                                   */
  87. /* For some versions of OS/2 it may be necessary to import explicitly these APIs     */
  88. /* using the following ordinals:                                                     */
  89. /*                                                                                   */
  90. /* WinHAPPfromPID        = PMMERGE.5198                                              */
  91. /* WinHSWITCHfromHAPP    = PMMERGE.5199                                              */
  92. /*                                                                                   */
  93. /*************************************************************************************/
  94.  
  95. int main (int argc, char *argv[], char *envp[])
  96. {
  97.  
  98.    APIRET rc;
  99.    HAPP happ;
  100.    HSWITCH hswitch;
  101.    SWCNTRL swcntrl;
  102.    PID pid;
  103.  
  104.    if (argc==1) {
  105.       printf("QSWLIST pid\n");
  106.       return 0;
  107.    } /* endif */
  108.  
  109.    pid=strtoul(argv[1],NULL,0);
  110.  
  111.    happ=WinHAPPfromPID(pid);          /* get HAPP from PID */
  112.  
  113.    hswitch=WinHSWITCHfromHAPP(happ);  /* get HSWITCH from HAPP */
  114.  
  115.    rc=WinQuerySwitchEntry(hswitch,&swcntrl); /* interpret HSWITCH */
  116.    if (rc) {
  117.       printf("WinQuerySwitchEntry returned %u\n",rc);
  118.       return rc;
  119.    } /* endif */
  120.  
  121.    printf("Pid: %04x, Happ: %08x, Hswitch: %08x\n", pid, happ, hswitch);
  122.    printf("swcntrl.hwnd:     \t%08x,   swcntrl.hwndIcon:    \t%08x\n",swcntrl.hwnd, swcntrl.hwndIcon);
  123.    printf("swcntrl.hprog:    \t%08x,   swcntrl.idProcess:   \t%08x\n",swcntrl.hprog, swcntrl.idProcess);
  124.    printf("swcntrl.idSession:\t%08x,   swcntrl.uchVisbility:\t%08x\n",swcntrl.idSession, swcntrl.uchVisibility);
  125.    printf("swcntrl.fbJump:   \t%08x,   swcntrl.bProgType:   \t%08x\n",swcntrl.fbJump, swcntrl.bProgType);
  126.    printf("swcntrl.szSwtitle %s\n",&swcntrl.szSwtitle);
  127.    
  128.  
  129.    return 0;
  130.  
  131. }
  132.  
  133.