Annotation of pmsdk/samples/spy/options.c, revision 1.1

1.1     ! root        1: /***************************************************************************\
        !             2: * options.c - Spy code for several options type dialogs
        !             3: *
        !             4: * Created by Microsoft Corporation, 1989
        !             5: \***************************************************************************/
        !             6: 
        !             7: #define        INCL_WINBUTTONS
        !             8: #define        INCL_WINDIALOGS
        !             9: #define        INCL_WINHEAP            /* needed for spy.h */
        !            10: #define        INCL_WINLISTBOXES
        !            11: #define        INCL_WINMESSAGEMGR
        !            12: #define        INCL_WINPOINTERS        /* needed for spy.h */
        !            13: #include <os2.h>
        !            14: #include <spyhook.h>
        !            15: #include <stdio.h>
        !            16: #include <stdlib.h>
        !            17: #include <string.h>
        !            18: #include <time.h>
        !            19: #include "spy.h"
        !            20: 
        !            21: /* Prototypes */
        !            22: MRESULT CALLBACK SpyOutputsDlgProc(HWND, USHORT, MPARAM, MPARAM);
        !            23: MRESULT CALLBACK SpySaveListDlgProc(HWND, USHORT, MPARAM, MPARAM);
        !            24: MRESULT CALLBACK AboutWndProc(HWND, USHORT, MPARAM, MPARAM);
        !            25: 
        !            26: /***************************************************************************\
        !            27: * MRESULT CALLBACK SpyOutputsDlgProc (hwnd, msg, mp1, mp2)
        !            28: \***************************************************************************/
        !            29: MRESULT CALLBACK SpyOutputsDlgProc(hwnd, msg, mp1, mp2)
        !            30: HWND            hwnd;
        !            31: USHORT          msg;
        !            32: MPARAM          mp1;
        !            33: MPARAM          mp2;
        !            34: {
        !            35:     USHORT      wAction;
        !            36: 
        !            37:     switch (msg) {
        !            38: 
        !            39:     case WM_INITDLG:
        !            40:         /*
        !            41:          * Now initialize the output options in the dialog
        !            42:          */
        !            43:         WinSendDlgItemMsg(hwnd, DID_WINDOW, BM_SETCHECK,
        !            44:             (MPARAM)spyopt.fWindow, 0L);
        !            45:         WinSendDlgItemMsg(hwnd, DID_FILE, BM_SETCHECK,
        !            46:             (MPARAM)spyopt.fFile, 0L);
        !            47: 
        !            48:         WinSetDlgItemShort(hwnd, DID_WINDOWLINES, spyopt.cWindowLines, FALSE);
        !            49:         WinSetDlgItemText(hwnd, DID_FILENAME, spystr.szFileName);
        !            50: 
        !            51: 
        !            52:         break;
        !            53: 
        !            54:     case WM_COMMAND:
        !            55:         switch (SHORT1FROMMP(mp1)) {
        !            56:         case DID_OK:
        !            57: 
        !            58:             /*
        !            59:              * Now retrieve the output options from the
        !            60:              * dialog
        !            61:              */
        !            62:             spyopt.fWindow = (BOOL)WinSendDlgItemMsg(hwnd,
        !            63:                 DID_WINDOW, BM_QUERYCHECK, 0L, 0L);
        !            64:             spyopt.fFile = (BOOL)WinSendDlgItemMsg(hwnd,
        !            65:                 DID_FILE, BM_QUERYCHECK, 0L, 0L);
        !            66: 
        !            67:             WinQueryDlgItemShort(hwnd, DID_WINDOWLINES, &spyopt.cWindowLines, FALSE);
        !            68:             WinQueryDlgItemText(hwnd, DID_FILENAME,
        !            69:                 sizeof(spystr.szFileName), spystr.szFileName);
        !            70: 
        !            71:             /*
        !            72:              * Now take care of file operations
        !            73:              * If a file is already active, we will continue to use it, and
        !            74:              * ignore the case where the user may have changed file names
        !            75:              * Will truncate any file.
        !            76:              */
        !            77:             if (spyopt.fFile) {
        !            78:                  if (spyopt.hfileSpy == NULL)
        !            79:                     if (DosOpen((PSZ)spystr.szFileName, &spyopt.hfileSpy,
        !            80:                             (USHORT far *)&wAction, 0L, 0,
        !            81:                             0x0012, 0x00C1, 0L) != 0)
        !            82:                         spyopt.hfileSpy = NULL; /* Failed on open */
        !            83:             } else {
        !            84:                 if (spyopt.hfileSpy != NULL) {
        !            85:                     /* file open, not outputing, close it now */
        !            86:                     DosClose (spyopt.hfileSpy);
        !            87:                     spyopt.hfileSpy = NULL;
        !            88:                 }
        !            89:             }
        !            90:             /* Fall through to DID_CANCEL */
        !            91:         case DID_CANCEL:
        !            92:             /* Now dismiss the dialog */
        !            93:             WinDismissDlg(hwnd, SHORT1FROMMP(mp1));
        !            94:             break;
        !            95:         }
        !            96:         break;
        !            97: 
        !            98:     default:
        !            99:         return(WinDefDlgProc(hwnd, msg, mp1, mp2));
        !           100:         break;
        !           101:     }
        !           102:     return 0L;
        !           103: }
        !           104: 
        !           105: 
        !           106: 
        !           107: 
        !           108: /***************************************************************************\
        !           109: * MRESULT CALLBACK SpySaveListDlgProc(hwnd, msg, mp1, mp2)
        !           110: *
        !           111: * The Spy Windows Dialog procedure
        !           112: \***************************************************************************/
        !           113: MRESULT CALLBACK SpySaveListDlgProc(hwnd, msg, mp1, mp2)
        !           114: HWND hwnd;
        !           115: USHORT msg;
        !           116: MPARAM mp1;
        !           117: MPARAM mp2;
        !           118: {
        !           119:     HFILE   hfileOut;
        !           120:     char    szTemp[100];
        !           121:     char    szTime[10];
        !           122:     char    szDate[10];
        !           123:     SHORT   cItems;
        !           124:     SHORT   iItem;
        !           125:     USHORT  cch;
        !           126:     USHORT  cchWritten;
        !           127:     USHORT  wAction;
        !           128:     ULONG   lTemp;
        !           129: 
        !           130:     switch (msg) {
        !           131: 
        !           132:     case WM_INITDLG:
        !           133:         WinSendDlgItemMsg(hwnd, DID_APPEND, BM_SETCHECK,
        !           134:             (MPARAM)spyopt.fAppend, 0L);
        !           135:         /* Initialize the dialog items */
        !           136:         WinSetDlgItemText(hwnd, DID_FILENAME, spystr.szSaveFileName);
        !           137:         break;
        !           138: 
        !           139:     case WM_COMMAND:
        !           140:         switch (SHORT1FROMMP(mp1)) {
        !           141:         case DID_OK:
        !           142:             /*
        !           143:              * Get the file name, and try to open the file,
        !           144:              * Then loop through and dump the listbox contents to the
        !           145:              * file.
        !           146:              */
        !           147:             spyopt.fAppend = (BOOL)WinSendDlgItemMsg(hwnd,
        !           148:                 DID_APPEND, BM_QUERYCHECK, 0L, 0L);
        !           149: 
        !           150:             WinQueryDlgItemText(hwnd, DID_FILENAME,
        !           151:                 sizeof(spystr.szSaveFileName), spystr.szSaveFileName);
        !           152: 
        !           153:             if (DosOpen((PSZ)spystr.szSaveFileName, (HFILE far *)&hfileOut,
        !           154:                     (USHORT far *)&wAction, 0L, 0,
        !           155:                     spyopt.fAppend? 0x0011 : 0x0012, 0x00C1, 0L) == 0) {
        !           156: 
        !           157:                 /* If append, get to the end of the file */
        !           158:                 if (spyopt.fAppend)
        !           159:                     DosChgFilePtr(hfileOut, 0L, 2, (PULONG)&lTemp);
        !           160: 
        !           161:                 /* Get count of items */
        !           162:                 cItems = (SHORT)WinSendMsg(hwndSpyList, LM_QUERYITEMCOUNT,
        !           163:                             0L, 0L);
        !           164: 
        !           165:                 /* Write out a title block to the file */
        !           166:                 _strdate(szDate);
        !           167:                 _strtime(szTime);
        !           168:                 DosWrite(hfileOut,
        !           169:                         (PSZ)"***************************************\r\n",
        !           170:                                 41, (PUSHORT)&cchWritten);
        !           171:                 cch = sprintf(szTemp, "* Spy: %-10s %-10s          *\r\n",
        !           172:                     szDate, szTime);
        !           173:                 DosWrite(hfileOut, (PSZ)szTemp, cch, (PUSHORT)&cchWritten);
        !           174: 
        !           175:                 DosWrite(hfileOut,
        !           176:                         (PSZ)"***************************************\r\n",
        !           177:                                 41, (PUSHORT)&cchWritten);
        !           178: 
        !           179: 
        !           180:                         /* Now output the list to the file */
        !           181:                 for (iItem = 0; iItem < cItems; iItem++) {
        !           182:                     cch = (SHORT)WinSendMsg(hwndSpyList, LM_QUERYITEMTEXT,
        !           183:                             MPFROM2SHORT(iItem, sizeof(szTemp)),
        !           184:                             (MPARAM)(PSZ)szTemp);
        !           185:                     /* Add Newline at end of string */
        !           186:                     szTemp[cch++] = '\r';
        !           187:                     szTemp[cch++] = '\n';
        !           188:                     szTemp[cch] = '\0';
        !           189:                     DosWrite(hfileOut, (PSZ)szTemp, cch,
        !           190:                             (PUSHORT)&cchWritten);
        !           191:                 }
        !           192:                 DosClose(hfileOut);
        !           193:             }
        !           194: 
        !           195:         case DID_CANCEL:
        !           196:             /* Now dismiss the dialog */
        !           197:             WinDismissDlg(hwnd, SHORT1FROMMP(mp1));
        !           198:             break;
        !           199:         break;
        !           200:     }
        !           201: 
        !           202:     default:
        !           203:         return(WinDefDlgProc(hwnd, msg, mp1, mp2));
        !           204:     }
        !           205:     return 0L;
        !           206: }
        !           207: 
        !           208: 
        !           209: 
        !           210: 
        !           211: /**************************************************************************\
        !           212: * AboutWndProc(HWND hwnd, USHORT message, MPARAM mp1, MPARAM mp2)
        !           213: *
        !           214: * About Spy... Dialog procedure
        !           215: \***************************************************************************/
        !           216: MRESULT CALLBACK AboutWndProc(hwnd, message, mp1, mp2)
        !           217: HWND    hwnd;
        !           218: USHORT  message;
        !           219: MPARAM   mp1;
        !           220: MPARAM   mp2;
        !           221: {
        !           222:     switch (message) {
        !           223:         case WM_COMMAND:
        !           224:             WinDismissDlg(hwnd, TRUE);
        !           225:             break;
        !           226:         default:
        !           227:             return(WinDefDlgProc(hwnd, message, mp1, mp2));
        !           228:             break;
        !           229:     }
        !           230:     return 0L;
        !           231: 
        !           232: } /* end aboutwndproc */
        !           233: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.