[5024] | 1 | #define INCL_WIN
|
---|
| 2 | #define INCL_DOS
|
---|
| 3 | #define INCL_VIO
|
---|
| 4 | #define INCL_SUB
|
---|
| 5 | #define INCL_DOSERRORS
|
---|
| 6 | #define INCL_WINSWITCHLIST
|
---|
| 7 | #include <os2.h>
|
---|
| 8 | #include "DosQuerySysState2.h"
|
---|
| 9 | #include <stdio.h>
|
---|
| 10 | #include <stdlib.h>
|
---|
| 11 |
|
---|
| 12 | #include "vio32Utils.h"
|
---|
| 13 |
|
---|
| 14 | //
|
---|
| 15 | ULONG getParentPID(ULONG pid){
|
---|
| 16 | union {
|
---|
| 17 | struct {
|
---|
| 18 | int extra[11];
|
---|
| 19 | qsPrec_s process;
|
---|
| 20 | } formatted;
|
---|
| 21 | char raw[256];
|
---|
| 22 | int intRaw[64];
|
---|
| 23 | } data;
|
---|
| 24 | APIRET rc = DosQuerySysState(QS_PROCESS, 0,pid, 0, &data, sizeof(data));
|
---|
| 25 | if (rc != 0) return 0;
|
---|
| 26 | return data.formatted.process.ppid;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | // returns the window id of the client window of the VIO that is hosting the current program
|
---|
| 30 | HWND VIOWindowClient(){
|
---|
| 31 | PPIB pib;
|
---|
| 32 | PTIB tib;
|
---|
| 33 | DosGetInfoBlocks(&tib, &pib);
|
---|
| 34 |
|
---|
| 35 | // now search for the window frame of this VIO window
|
---|
| 36 | USHORT num = WinQuerySwitchList(0L, NULL, 0);
|
---|
| 37 | if(!num) return 0;
|
---|
| 38 |
|
---|
| 39 | SWBLOCK *pSwb = (SWBLOCK *)malloc(sizeof(HSWITCH) + sizeof(SWENTRY) * num );
|
---|
| 40 | num = WinQuerySwitchList(0L, pSwb, sizeof(HSWITCH) + sizeof(SWENTRY) * num );
|
---|
| 41 | BOOL found = FALSE;
|
---|
| 42 | ULONG pid = pib->pib_ulpid;
|
---|
| 43 | ULONG level = 0;
|
---|
| 44 | HWND hwndFrame;
|
---|
| 45 | while (!found){
|
---|
| 46 | //printf ("searching pid %i\n",pid);
|
---|
| 47 | for(USHORT i=0; i<num; i++){
|
---|
| 48 | if (pSwb->aswentry[i].swctl.idProcess == pid){
|
---|
| 49 | //printf("LEVEL %i %04x %08x %s\n", level,pSwb->aswentry[i].swctl.idProcess,pSwb->aswentry[i].swctl.hwnd,pSwb->aswentry[i].swctl.szSwtitle);
|
---|
| 50 | found = TRUE;
|
---|
| 51 | hwndFrame = pSwb->aswentry[i].swctl.hwnd;
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | level++;
|
---|
| 55 | if (!found ) pid = getParentPID(pid);
|
---|
| 56 | if (pid == 1) break;
|
---|
| 57 | if (pid == 0) break;
|
---|
| 58 | }
|
---|
| 59 | free(pSwb);
|
---|
| 60 |
|
---|
| 61 | if (!found) return 0;
|
---|
| 62 |
|
---|
| 63 | // now get the client window id
|
---|
| 64 | HWND hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
|
---|
| 65 | //printf ("window frame %x client %x\n",hwndFrame,hwndClient);
|
---|
| 66 |
|
---|
| 67 | return hwndClient;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 | // returns the window id of the client window of the VIO that is hosting the current program
|
---|
| 72 | HWND VIOWindowFrame(){
|
---|
| 73 | PPIB pib;
|
---|
| 74 | PTIB tib;
|
---|
| 75 | DosGetInfoBlocks(&tib, &pib);
|
---|
| 76 |
|
---|
| 77 | // now search for the window frame of this VIO window
|
---|
| 78 | USHORT num = WinQuerySwitchList(0L, NULL, 0);
|
---|
| 79 | if(!num) return 0;
|
---|
| 80 |
|
---|
| 81 | SWBLOCK *pSwb = (SWBLOCK *)malloc(sizeof(HSWITCH) + sizeof(SWENTRY) * num );
|
---|
| 82 | num = WinQuerySwitchList(0L, pSwb, sizeof(HSWITCH) + sizeof(SWENTRY) * num );
|
---|
| 83 | BOOL found = FALSE;
|
---|
| 84 | ULONG pid = pib->pib_ulpid;
|
---|
| 85 | ULONG level = 0;
|
---|
| 86 | HWND hwndFrame;
|
---|
| 87 | while (!found){
|
---|
| 88 | //printf ("searching pid %i\n",pid);
|
---|
| 89 | for(USHORT i=0; i<num; i++){
|
---|
| 90 | if (pSwb->aswentry[i].swctl.idProcess == pid){
|
---|
| 91 | //printf("LEVEL %i %04x %08x %s\n", level,pSwb->aswentry[i].swctl.idProcess,pSwb->aswentry[i].swctl.hwnd,pSwb->aswentry[i].swctl.szSwtitle);
|
---|
| 92 | found = TRUE;
|
---|
| 93 | hwndFrame = pSwb->aswentry[i].swctl.hwnd;
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 | level++;
|
---|
| 97 | if (!found ) pid = getParentPID(pid);
|
---|
| 98 | if (pid == 1) break;
|
---|
| 99 | if (pid == 0) break;
|
---|
| 100 | }
|
---|
| 101 | free(pSwb);
|
---|
| 102 |
|
---|
| 103 | if (!found) return 0;
|
---|
| 104 |
|
---|
| 105 | return hwndFrame;
|
---|
| 106 | }
|
---|
| 107 |
|
---|