Annotation of os232sdk/toolkt20/c/samples/spy/message.c, revision 1.1

1.1     ! root        1: 
        !             2: /****************************** Module Header ******************************\
        !             3: * Module Name:  message.c - procecures to process the message dialog
        !             4: *
        !             5: * Created: Microsoft, IBM Corporation 1990
        !             6: *
        !             7: \***************************************************************************/
        !             8: 
        !             9: #define INCL_WIN
        !            10: #define INCL_WINSYS
        !            11: #define INCL_DOSPROCESS
        !            12: #include <os2.h>
        !            13: #include <stdio.h>
        !            14: #include <string.h>
        !            15: #include "spy.h"
        !            16: #include "spyhk32.h"
        !            17: #include <time.h>
        !            18: #include <stdlib.h>
        !            19: 
        !            20: /* This is a real hack, estimate size of WND Structure */
        !            21: #define SIZEOFWND   34
        !            22: #define MAXMSGBYTES 100
        !            23: 
        !            24: /************* GLOBAL VARIABLES         */
        !            25: 
        !            26: 
        !            27: /************* PROCEDURE DECLARATIONS   */
        !            28: 
        !            29: 
        !            30: 
        !            31: void    UpdMsgsLBSels (USHORT, BOOL);
        !            32: void    UpdMsgTblFromLB (HWND);
        !            33: void    ProcessQueueMsg(QMSGSPY *);
        !            34: void    SelOrDeselWithMouse(BOOL);
        !            35: void    UpdateMsgBoxCurMsgText(HWND);
        !            36: 
        !            37: void    SelectMessageFromText(HWND);
        !            38: void    SendMsgProcCmd(HWND, USHORT);
        !            39: void    SetItemHexNum(HWND, USHORT, ULONG);
        !            40: ULONG   GetItemVal(HWND, USHORT, BOOL, PSZ, PSZ);
        !            41: 
        !            42: 
        !            43: 
        !            44: 
        !            45: 
        !            46: /**************************** Public Function ******************************\
        !            47: * MRESULT EXPENTRY SpyMsgDlgProc (hwnd, msg, mp1, mp2)
        !            48: *
        !            49: * Effects: Message List dialog procedure
        !            50: *
        !            51: *
        !            52: * Return value:
        !            53: \***************************************************************************/
        !            54: MRESULT EXPENTRY SpyMsgDlgProc(hwnd, msg, mp1, mp2)
        !            55: HWND            hwnd;
        !            56: USHORT          msg;
        !            57: MPARAM          mp1;
        !            58: MPARAM          mp2;
        !            59: {
        !            60:     SHORT       i;
        !            61:     MSGI        *pmsgi;
        !            62:     USHORT      item;
        !            63:     SHORT       bHooksNew;
        !            64:     USHORT      iItemFocus; /* Index to item that has the focus */
        !            65: 
        !            66:     switch (msg) {
        !            67: 
        !            68:     case WM_INITDLG:
        !            69:         /*
        !            70:          * Initialize the list box with the list of messages that are
        !            71:          * defined in our message table
        !            72:          */
        !            73:         iCurItemFocus = -1;
        !            74:         pmsgi = rgmsgi; /* Point to start of list */
        !            75:         hwndMessageLB = WinWindowFromID(hwnd, DID_OMSGLIST);
        !            76:         for (i = 0; i < cmsgi; i++) {
        !            77:             pmsgi->iListBox = item = (USHORT)WinSendMsg(hwndMessageLB,
        !            78:                     LM_INSERTITEM,
        !            79:                     (MPARAM)(spyopt.fAlphaSortMsgList? LIT_SORTASCENDING : LIT_END),
        !            80:                     (MPARAM)(PSZ)pmsgi->szMsg);
        !            81:             WinSendMsg(hwndMessageLB, LM_SETITEMHANDLE, (MPARAM)item,
        !            82:                 (MPARAM)i);
        !            83:             if (pmsgi->wOptions & MSGI_ENABLED) {
        !            84:                 WinSendMsg(hwndMessageLB, LM_SELECTITEM, (MPARAM)item,
        !            85:                 (MPARAM)TRUE);
        !            86:             }
        !            87:             pmsgi++;
        !            88:         }
        !            89: 
        !            90:         /*
        !            91:          * If alpha Sort, we need to make a second pass through, and update
        !            92:          * our indexes of where each message is in the list box
        !            93:          */
        !            94:         if (spyopt.fAlphaSortMsgList) {
        !            95:             for (i = 0; i < cmsgi; i++) {
        !            96:                 item = (USHORT)WinSendMsg(hwndMessageLB, LM_QUERYITEMHANDLE,
        !            97:                         MPFROMSHORT(i), 0L);
        !            98:                 rgmsgi[item].iListBox = i;
        !            99:             }
        !           100:         }
        !           101: 
        !           102: 
        !           103: 
        !           104:         /* Initialize the Hook type record */
        !           105:         WinSendDlgItemMsg(hwnd, DID_OINPUT, BM_SETCHECK,
        !           106:                 (MPARAM)(spyopt.bHooks & SPYH_INPUT)?1 : 0, 0L);
        !           107: 
        !           108:         WinSendDlgItemMsg(hwnd, DID_OSENDMSG, BM_SETCHECK,
        !           109:                 (MPARAM)(spyopt.bHooks & SPYH_SENDMSG)?1 : 0, 0L);
        !           110: 
        !           111:         WinSendDlgItemMsg(hwnd, DID_OTHERMSGS, BM_SETCHECK,
        !           112:                 (MPARAM)(spyopt.fDispOtherMsgs), 0L);
        !           113: 
        !           114:         WinSetFocus(HWND_DESKTOP, hwndMessageLB);
        !           115:         fTrackingListBox = TRUE;
        !           116:         return ((MRESULT)TRUE);  /* We set the focus */
        !           117: 
        !           118:         break;
        !           119: 
        !           120:     case WM_CHAR:
        !           121:         /*
        !           122:          * Handle VK_ENTER and VK_NEWLINE if our Edit control has
        !           123:          * the focus and it is a keydown
        !           124:          */
        !           125:         if (!(SHORT1FROMMP(mp1) & KC_KEYUP) &&
        !           126:                 (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) &&
        !           127:                 ( (SHORT2FROMMP(mp2) == VK_ENTER) ||
        !           128:                   (SHORT2FROMMP(mp2) == VK_NEWLINE) )) {
        !           129: 
        !           130: 
        !           131:             if (WinQueryFocus(HWND_DESKTOP, FALSE) ==
        !           132:                     WinWindowFromID(hwnd, DID_MSGEDIT)) {
        !           133:                 SelectMessageFromText(hwnd);
        !           134:                 break;
        !           135:             }
        !           136:         }
        !           137: 
        !           138:         /* Normaly pass to dialog procedure to handle message */
        !           139:         return(WinDefDlgProc(hwnd, msg, mp1, mp2));
        !           140:         break;
        !           141: 
        !           142:     case WM_COMMAND:
        !           143:         switch (SHORT1FROMMP(mp1)) {
        !           144:         case DID_OK:
        !           145: 
        !           146:             /*
        !           147:              * Call to update the Message table select bits
        !           148:              */
        !           149: 
        !           150:             UpdMsgTblFromLB (hwnd);
        !           151: 
        !           152:             /* Setup new hook options */
        !           153:             bHooksNew = 0;
        !           154: 
        !           155:             if ((BOOL)WinSendDlgItemMsg(hwnd,
        !           156:                     DID_OINPUT, BM_QUERYCHECK, 0L, 0L))
        !           157:                 bHooksNew = SPYH_INPUT;
        !           158: 
        !           159:             if ((BOOL)WinSendDlgItemMsg(hwnd,
        !           160:                     DID_OSENDMSG, BM_QUERYCHECK, 0L, 0L))
        !           161:                 bHooksNew |= SPYH_SENDMSG;
        !           162: 
        !           163:             if (bHooksNew != spyopt.bHooks) {
        !           164:                 SpyReleaseHook (FALSE);     /* Dont clear queue */
        !           165:                 spyopt.bHooks = bHooksNew;
        !           166:                 SpyInstallHook(hab, hmqSpy, spyopt.bHooks); /* Install hook again */
        !           167:                 WinSendMsg(WinWindowFromID(hwndSpyFrame, FID_MENU),
        !           168:                     MM_SETITEMATTR, MPFROM2SHORT(CMD_INPUTHOOK, TRUE),
        !           169:                     MPFROM2SHORT(MIA_CHECKED,
        !           170:                          (spyopt.bHooks & SPYH_INPUT) ? MIA_CHECKED : 0));
        !           171:                 WinSendMsg(WinWindowFromID(hwndSpyFrame, FID_MENU),
        !           172:                     MM_SETITEMATTR, MPFROM2SHORT(CMD_SENDMSGHOOK, TRUE),
        !           173:                     MPFROM2SHORT(MIA_CHECKED,
        !           174:                          (spyopt.bHooks & SPYH_SENDMSG) ? MIA_CHECKED : 0));
        !           175:             }
        !           176: 
        !           177:             /* Fall through to DID_CANCEL */
        !           178:         case DID_CANCEL:
        !           179:             /* Now dismiss the dialog */
        !           180:             hwndMessageLB = NULL;   /* Not here anymore to process */
        !           181:             fTrackingListBox = FALSE;
        !           182:             WinDismissDlg(hwnd, SHORT1FROMMP(mp1));
        !           183:             break;
        !           184: 
        !           185:         /*
        !           186:          * These case simply update the listbox with which messages are
        !           187:          * enabled
        !           188:          */
        !           189:         case DID_MALL:
        !           190:             UpdMsgsLBSels (0, TRUE);
        !           191:             break;
        !           192:         case DID_MNONE:
        !           193:             UpdMsgsLBSels (0, FALSE);
        !           194:             break;
        !           195:         case DID_MCON:
        !           196:             UpdMsgsLBSels (MSGI_KEY, TRUE);
        !           197:             break;
        !           198:         case DID_MCOFF:
        !           199:             UpdMsgsLBSels (MSGI_KEY, FALSE);
        !           200:             break;
        !           201:         case DID_MMON:
        !           202:             UpdMsgsLBSels (MSGI_MOUSE, TRUE);
        !           203:             break;
        !           204:         case DID_MMOFF:
        !           205:             UpdMsgsLBSels (MSGI_MOUSE, FALSE);
        !           206:             break;
        !           207:         case DID_MFON:
        !           208:             UpdMsgsLBSels (MSGI_FREQ, TRUE);
        !           209:             break;
        !           210:         case DID_MFOFF:
        !           211:             UpdMsgsLBSels (MSGI_FREQ, FALSE);
        !           212:             break;
        !           213:         }
        !           214:         break;
        !           215: 
        !           216:     default:
        !           217:         /*
        !           218:          * Default is to see if the listbox has changed its focus
        !           219:          * item number.  If it has, then we want to display the information
        !           220:          * about the window that the listbox cursor is over.  There is no
        !           221:          * legal way to do this, except to temporarily put the listbox into
        !           222:          * single selection mode and query the selection.
        !           223:          */
        !           224:         if (fTrackingListBox && (hwndMessageLB != NULL)) {
        !           225:             WinSetWindowBits(hwndMessageLB, QWL_STYLE, 0L, LS_MULTIPLESEL);
        !           226:             iItemFocus = (USHORT)WinSendMsg(hwndMessageLB, LM_QUERYSELECTION,
        !           227:                     (MPARAM)LIT_FIRST, 0L);
        !           228:             WinSetWindowBits(hwndMessageLB, QWL_STYLE, LS_MULTIPLESEL,
        !           229:                     LS_MULTIPLESEL);
        !           230:             if (iItemFocus != iCurItemFocus) {
        !           231:                 iCurItemFocus = iItemFocus;
        !           232:                 UpdateMsgBoxCurMsgText(hwnd);
        !           233:             }
        !           234:         }
        !           235:         return(WinDefDlgProc(hwnd, msg, mp1, mp2));
        !           236:         break;
        !           237:     }
        !           238:     return 0L;
        !           239: }
        !           240: 
        !           241: 
        !           242: 
        !           243: /***************************** Private Function ****************************\
        !           244: * void UpdateMsgBoxCurMsgText()
        !           245: *
        !           246: * Effects:
        !           247: *   Updates the text that is displayed in the message text line
        !           248: *
        !           249: * History:
        !           250: *   27-September-1988 KurtE
        !           251: \***************************************************************************/
        !           252: void UpdateMsgBoxCurMsgText(hwndDlg)
        !           253: HWND    hwndDlg;
        !           254: {
        !           255:     SHORT   sMsgI;
        !           256:     char    szTemp[80];
        !           257: 
        !           258: 
        !           259:     if (iCurItemFocus >= 0) {
        !           260:         /* Get the messge index */
        !           261:         sMsgI = (SHORT)WinSendMsg(hwndMessageLB, LM_QUERYITEMHANDLE,
        !           262:                 (MPARAM)iCurItemFocus, 0L);
        !           263:         sprintf(szTemp, "0x%04x  - %s", rgmsgi[sMsgI].msg,
        !           264:                 rgmsgi[sMsgI].szMsg);
        !           265:         WinSetDlgItemText(hwndDlg, DID_MSGEDIT, (PSZ)szTemp);
        !           266:     } else {
        !           267:         WinSetDlgItemText(hwndDlg, DID_MSGEDIT, (PSZ)"");
        !           268:     }
        !           269: 
        !           270: }
        !           271: 
        !           272: 
        !           273: 
        !           274: 
        !           275: /***************************** Private Function ****************************\
        !           276: * void SelectMessageFromText(hwndDlg)
        !           277: *
        !           278: * Effects:
        !           279: *   Updates the text that is displayed in the message text line
        !           280: *
        !           281: * History:
        !           282: *   27-September-1988 KurtE
        !           283: \***************************************************************************/
        !           284: void SelectMessageFromText(hwndDlg)
        !           285: HWND    hwndDlg;
        !           286: {
        !           287:     char    szTemp[80];
        !           288:     USHORT  msg;
        !           289:     MSGI    *pmsgi;
        !           290:     int     i;
        !           291: 
        !           292: 
        !           293:     /* First get the edit text from the string */
        !           294:     WinQueryDlgItemText(hwndDlg, DID_MSGEDIT, sizeof(szTemp),
        !           295:             (PSZ)szTemp);
        !           296: 
        !           297:     if ((msg = UConvertStringToNum(szTemp)) != 0xffff) {
        !           298: 
        !           299:         /* We have a number, now try to find message in message table */
        !           300:         pmsgi = PmsgiFromMsg(msg);
        !           301: 
        !           302:     } else {
        !           303:         /* Assume String, Try to locate string in our table */
        !           304:         pmsgi = rgmsgi; /* Start at beginning of table */
        !           305:         /*
        !           306:          * This does simple string compares, it does not map case, nor
        !           307:          * does it trim the string.
        !           308:          */
        !           309:         for (i=0; i < cmsgi; i++) {
        !           310:             if (strcmpi(pmsgi->szMsg, szTemp) == 0)
        !           311:                 break;
        !           312:             pmsgi++;
        !           313:         };
        !           314: 
        !           315:         if (i >= cmsgi)
        !           316:             pmsgi = NULL;
        !           317:     }
        !           318: 
        !           319:     /*
        !           320:      * Have a pointer to MSGI of message, or NULL if not in list.
        !           321:      */
        !           322:     if(pmsgi != NULL) {
        !           323:         /* First make sure it is visible */
        !           324:         WinSendMsg(hwndMessageLB, LM_SETTOPINDEX,
        !           325:                 MPFROMSHORT(pmsgi->iListBox),  (MPARAM)0L);
        !           326: 
        !           327:         /* Always set it on */
        !           328:         WinSendMsg(hwndMessageLB, LM_SELECTITEM,
        !           329:                 MPFROMSHORT(pmsgi->iListBox), MPFROMSHORT(TRUE));
        !           330: 
        !           331:     } else {
        !           332:         WinAlarm(HWND_DESKTOP, WA_WARNING);
        !           333:         WinSetDlgItemText(hwndDlg, DID_MSGEDIT, (PSZ)"");
        !           334:     }
        !           335: }
        !           336: 
        !           337: 
        !           338: 
        !           339: 
        !           340: 
        !           341: /**************************** Public Function ******************************\
        !           342: * void UpdMsgsLBSels (USHORT uMask, fOnOrOff);
        !           343: *
        !           344: * Effects: Will update the selected items in the message listbox, that is
        !           345: *   displayed in the options dialog
        !           346: *
        !           347: * Return value: none
        !           348: \***************************************************************************/
        !           349: void UpdMsgsLBSels (uMask, fOnOrOff)
        !           350: USHORT      uMask;
        !           351: BOOL        fOnOrOff;
        !           352: {
        !           353: 
        !           354:     SHORT       i;
        !           355:     MSGI        *pmsgi;
        !           356: 
        !           357:     /*
        !           358:      * Loop through all of the items in our list, if the mask is 0 or
        !           359:      * the bit is on in the item, then update the select state in listbox
        !           360:      * defined in our message table
        !           361:      */
        !           362:     fTrackingListBox = FALSE;
        !           363:     pmsgi = rgmsgi; /* Point to start of list */
        !           364:     for (i = 0; i < cmsgi; i++) {
        !           365:         if ((uMask == 0) || (pmsgi->wOptions & uMask)) {
        !           366:             WinSendMsg(hwndMessageLB, LM_SELECTITEM,
        !           367:         (MPARAM)pmsgi->iListBox,  (MPARAM)fOnOrOff);
        !           368:         }
        !           369:         pmsgi++;
        !           370:     }
        !           371:     fTrackingListBox = TRUE;
        !           372: }
        !           373: 
        !           374: 
        !           375: 
        !           376: /**************************** Public Function ******************************\
        !           377: * void UpdMsgsLBSels (HWND hwndDialog, USHORT uMask, fOnOrOff);
        !           378: *
        !           379: * Effects: Will update the selected items in the message listbox, that is
        !           380: *   displayed in the options dialog
        !           381: *
        !           382: * Return value: none
        !           383: \***************************************************************************/
        !           384: void UpdMsgTblFromLB (hwndDialog)
        !           385: HWND            hwndDialog;
        !           386: {
        !           387: 
        !           388:     USHORT       i;
        !           389:     register MSGI *pmsgi;
        !           390:     USHORT      itemSel;
        !           391: 
        !           392:     /*
        !           393:      * Loop through all of the items in the list and update the selection
        !           394:      * status depending of if the item is selected in the list box or
        !           395:      * not.
        !           396:      */
        !           397:     /* First simply turn off all of the bits */
        !           398:     pmsgi = rgmsgi;
        !           399:     for (i = 0; i < cmsgi; i++) {
        !           400:         pmsgi->wOptions &= ~MSGI_ENABLED;
        !           401:         pmsgi++;
        !           402:     }
        !           403: 
        !           404:     /* Then turn on all of the selected items */
        !           405:     itemSel = (USHORT)LIT_FIRST;
        !           406: 
        !           407:     while ((itemSel = (USHORT)WinSendMsg(hwndMessageLB, LM_QUERYSELECTION,
        !           408:             (MPARAM)itemSel, 0L)) != (USHORT)LIT_NONE) {
        !           409: 
        !           410:         /* The item handle contains index in our array */
        !           411:         i = (USHORT)WinSendMsg(hwndMessageLB, LM_QUERYITEMHANDLE,
        !           412:             (MPARAM)itemSel, 0L);
        !           413: 
        !           414:         rgmsgi[i].wOptions |= MSGI_ENABLED;
        !           415:     }
        !           416: 
        !           417:     /* Get the Other message option from checkmark */
        !           418:     spyopt.fDispOtherMsgs = ((BOOL)WinSendDlgItemMsg(hwndDialog, DID_OTHERMSGS,
        !           419:             BM_QUERYCHECK, 0L, 0L));
        !           420: 
        !           421:     /* Now call function to update the hooks message list */
        !           422:     UpdateHooksMsgTable();
        !           423: }
        !           424: 
        !           425: 
        !           426: 
        !           427: 
        !           428: /**************************** Public Function ******************************\
        !           429: * void UpdateHooksMsgTable(void)
        !           430: *
        !           431: * Effects: Set the message bitmask to the hook, for interested messages.
        !           432: *   displayed in the options dialog
        !           433: *
        !           434: * Return value: none
        !           435: \***************************************************************************/
        !           436: void  UpdateHooksMsgTable()
        !           437: {
        !           438:     MSGI            *pmsgi;
        !           439:     UCHAR           rgb[MAXMSGFILTERBYTES];
        !           440:     int             i;
        !           441:     UCHAR           *prgb;
        !           442:     unsigned char   mask;
        !           443: 
        !           444:     /*
        !           445:      * First zero the bitmask
        !           446:      */
        !           447:     memset(rgb,'\0', MAXMSGFILTERBYTES);
        !           448:     mask = 1;
        !           449:     prgb = rgb;
        !           450: 
        !           451:     /*
        !           452:      * Quick and dirty loop to set the bits
        !           453:      */
        !           454:     pmsgi = rgmsgi;
        !           455:     for (i = 0; i <= MAXMSGFILTER; i++) {
        !           456:         /* If enabled, set bit in bit table */
        !           457: 
        !           458:         if (pmsgi->msg == i) {
        !           459:             if (pmsgi->wOptions & MSGI_ENABLED)
        !           460:                 *prgb = pmsgi->bMPTypes | MP_ENABLED;
        !           461: 
        !           462:             pmsgi++;
        !           463:         } else {
        !           464:             /* Hole in range, set it true */
        !           465:             *prgb |= mask;
        !           466:         }
        !           467: 
        !           468:         prgb++;
        !           469:     }
        !           470: 
        !           471:     /* Now call the hook function with the new mask */
        !           472:     SpySetMessageList((char FAR *)rgb, spyopt.fDispOtherMsgs);
        !           473: }
        !           474: 
        !           475: 
        !           476: 
        !           477: 
        !           478: /**************************** Public Function ******************************\
        !           479: * EnableOrDisableMsg(BOOL fEnable)
        !           480: *
        !           481: * Effects: Fastway to enable or disable a particular message code.  The one
        !           482: *           that is currently selected in the output listbox.
        !           483: *
        !           484: * Return value: none
        !           485: \***************************************************************************/
        !           486: 
        !           487: void EnableOrDisableMsg(fEnable)
        !           488: BOOL            fEnable;
        !           489: {
        !           490:     USHORT      itemSel;
        !           491:     char        szTemp[100];
        !           492:     char        *psz;
        !           493:     MSGI        *pmsgi;
        !           494:     SHORT       i;
        !           495: 
        !           496:     itemSel = (USHORT)WinSendMsg(hwndSpyList, LM_QUERYSELECTION,
        !           497:             (MPARAM)LIT_FIRST, 0L);
        !           498:     if (itemSel == (USHORT)LIT_NONE)
        !           499:         return;    /* None to process */
        !           500: 
        !           501:     /* Get the message text */
        !           502:     WinSendMsg(hwndSpyList, LM_QUERYITEMTEXT,
        !           503:             MPFROM2SHORT(itemSel, sizeof(szTemp)), (MPARAM)(PSZ)szTemp);
        !           504: 
        !           505:     /* Now lets extract the messgae string from the line */
        !           506:     psz = &szTemp[3];
        !           507:     while (*psz != ' ')
        !           508:         psz++;    /* locate first blank */
        !           509:     *psz = '\0';    /* Zero terminate string */
        !           510: 
        !           511: 
        !           512:     /*
        !           513:      * Loop through all of the items in our list, until we find a
        !           514:      * string that matches our string.
        !           515:      */
        !           516:     pmsgi = rgmsgi; /* Point to start of list */
        !           517:     for (i = 0; i < cmsgi; i++) {
        !           518:         if (strcmpi(&szTemp[2], pmsgi->szMsg) == 0) {
        !           519:             /*
        !           520:              * Found our message, update the bit of the message, and
        !           521:              * call the function to let the hook know the new results
        !           522:              */
        !           523:             if (fEnable)
        !           524:                 pmsgi->wOptions |= MSGI_ENABLED;
        !           525:             else
        !           526:                 pmsgi->wOptions &= ~MSGI_ENABLED;
        !           527: 
        !           528:                UpdateHooksMsgTable();      /* Set Spys Msg table */
        !           529:             return;
        !           530:         }
        !           531:         pmsgi++;
        !           532:     }
        !           533: }
        !           534: 
        !           535: 
        !           536: /**************************** Public Function ******************************\
        !           537: * MRESULT SendMsgDlgProc(...)
        !           538: *
        !           539: * Effects: This is the dialog procedure for the Send Message facility of spy
        !           540: *
        !           541: * Return value: none
        !           542: \***************************************************************************/
        !           543: extern MRESULT EXPENTRY SendMsgDlgProc(hwnd, msg, mp1, mp2)
        !           544: HWND    hwnd;
        !           545: USHORT  msg;
        !           546: MPARAM  mp1;
        !           547: MPARAM  mp2;
        !           548: {
        !           549: 
        !           550: 
        !           551:     switch (msg) {
        !           552: 
        !           553:     case WM_INITDLG:
        !           554:         break;
        !           555: 
        !           556:     case WM_COMMAND:
        !           557:         SendMsgProcCmd(hwnd, LOUSHORT(mp1));
        !           558:         break;
        !           559: 
        !           560:     default:
        !           561:         return(WinDefDlgProc(hwnd, msg, mp1, mp2));
        !           562:         break;
        !           563:     }
        !           564: 
        !           565:     return 0L;
        !           566: }
        !           567: 
        !           568: 
        !           569: void SendMsgProcCmd(hwnd, id)
        !           570: HWND    hwnd;
        !           571: USHORT  id;
        !           572: {
        !           573:     HWND hwndPoint;
        !           574:     BOOL fPostMsg;
        !           575:     USHORT msg;
        !           576:     MPARAM mp1;
        !           577:     MPARAM mp2;
        !           578:     MRESULT mresult;
        !           579:     char szLine1[80];
        !           580:     char szLine2[80];
        !           581:     char szTemp[12];
        !           582: 
        !           583: 
        !           584:     fPostMsg = TRUE;
        !           585: 
        !           586:     switch (id) {
        !           587:     case DID_SELHWND:
        !           588:         //  Call function to allow the user to point at a window.
        !           589:         hwndPoint = HwndSelWinWithMouse(hwnd, NULL, FALSE);
        !           590:         sprintf(szTemp, "%p", hwndPoint);
        !           591:         WinSetDlgItemText(hwnd, DID_HWND, (PSZ)szTemp);
        !           592:         break;
        !           593: 
        !           594:     case DID_SEND:
        !           595:         fPostMsg = FALSE;
        !           596:     case DID_POST:
        !           597:         /* Send or post, setup to send the message */
        !           598:         /* First setup the Hwnd */
        !           599:         hwndPoint = (HWND)GetItemVal(hwnd, DID_HWND, FALSE, szLine1, szLine2);
        !           600:         sprintf(szTemp, "%p", hwndPoint);
        !           601:         WinSetDlgItemText(hwnd, DID_HWND, (PSZ)szTemp);
        !           602: 
        !           603:         /* Now the MSG */
        !           604:         msg = (USHORT)GetItemVal(hwnd, DID_COMMAND, TRUE, szLine1, szLine2);
        !           605:         SetItemHexNum(hwnd, DID_COMMAND, (ULONG)msg);
        !           606: 
        !           607:         /* Now the mp1 */
        !           608:         mp1 = (MPARAM)GetItemVal(hwnd, DID_MPARAM1, TRUE, szLine1, szLine2);
        !           609:         SetItemHexNum(hwnd, DID_MPARAM1, (ULONG)mp1);
        !           610: 
        !           611:         /* Now the mp2 */
        !           612:         mp2 = (MPARAM)GetItemVal(hwnd, DID_MPARAM2, TRUE, szLine1, szLine2);
        !           613:         SetItemHexNum(hwnd, DID_MPARAM2, (ULONG)mp2);
        !           614: 
        !           615:         /* Get initial values of two string variables */
        !           616:         WinQueryDlgItemText(hwnd, DID_STRING1, sizeof(szLine1), (PSZ)szLine1);
        !           617:         WinQueryDlgItemText(hwnd, DID_STRING2, sizeof(szLine2), (PSZ)szLine2);
        !           618: 
        !           619:         /* Now Send or post the message */
        !           620:         if (fPostMsg)
        !           621:             mresult = (MRESULT)WinPostMsg(hwndPoint, msg, mp1, mp2);
        !           622:         else
        !           623:             mresult = WinSendMsg(hwndPoint, msg, mp1, mp2);
        !           624: 
        !           625:         SetItemHexNum(hwnd, DID_RESULT, (ULONG)mresult);
        !           626: 
        !           627:         /* Set the Ending values for the strings */
        !           628:         WinSetDlgItemText(hwnd, DID_STRING1, (PSZ)szLine1);
        !           629:         WinSetDlgItemText(hwnd, DID_STRING2, (PSZ)szLine2);
        !           630:         break;
        !           631: 
        !           632:     case DID_CANCEL:
        !           633:         WinDismissDlg(hwnd, 1234);
        !           634:         WinDestroyWindow(hwnd);
        !           635:         WinSendMsg(WinWindowFromID(hwndSpyFrame, FID_MENU),
        !           636:             MM_SETITEMATTR, MPFROM2SHORT(CMD_SENDMSG, TRUE),
        !           637:             MPFROM2SHORT(MIA_DISABLED, 0));
        !           638: 
        !           639:         break;
        !           640:     }
        !           641: }
        !           642: 
        !           643: void SetItemHexNum(hwnd, idItem, lVal)
        !           644: HWND    hwnd;
        !           645: USHORT  idItem;
        !           646: ULONG    lVal;
        !           647: {
        !           648:     char    szTemp[20];
        !           649: 
        !           650:     sprintf (szTemp, "0x%lx", lVal);
        !           651:     WinSetDlgItemText(hwnd, idItem, (PSZ)szTemp);
        !           652: }
        !           653: 
        !           654: ULONG GetItemVal(hwnd, idItem, fLookup, psz1, psz2)
        !           655: HWND    hwnd;
        !           656: USHORT  idItem;
        !           657: BOOL    fLookup;
        !           658: PSZ     psz1;
        !           659: PSZ     psz2;
        !           660: {
        !           661:     ULONG   lVal;
        !           662:     char    szTemp[80];
        !           663:     register char *psz;
        !           664:     MSGI    *pmsgi;
        !           665:     SHORT   i;
        !           666:     USHORT  usSel;
        !           667:     USHORT  usOffset;
        !           668: 
        !           669:     WinQueryDlgItemText(hwnd, idItem, sizeof(szTemp), (PSZ)szTemp);
        !           670: 
        !           671:     /* Quick and dirty convert string to uppercase */
        !           672:     for (psz = szTemp; *psz; psz++) {
        !           673:         if ((*psz >= 'a') && (*psz <= 'z'))
        !           674:             *psz = *psz - 'a' + 'A';
        !           675:     }
        !           676: 
        !           677:     if (fLookup) {
        !           678:         // Try to find the string in our table.
        !           679:         pmsgi = rgmsgi; /* Start at beginning of table */
        !           680:         /*
        !           681:          * This does simple string compares, it does not map case, nor
        !           682:          * does it trim the string.
        !           683:          */
        !           684:         for (i=0; i < cmsgi; i++) {
        !           685:             if (strcmpi(pmsgi->szMsg, szTemp) == 0)
        !           686:                 break;
        !           687:             pmsgi++;
        !           688:         }
        !           689: 
        !           690:         if (i < cmsgi)
        !           691:             return ((ULONG)pmsgi->msg);
        !           692: 
        !           693:     }
        !           694: 
        !           695:     /* Simple Test for &1 and &2 */
        !           696:     if (szTemp[0] == '&') {
        !           697:         if (szTemp[1] == '2')
        !           698:             return ((LONG)psz2);
        !           699:         else
        !           700:             return ((LONG)psz1);
        !           701:     }
        !           702: 
        !           703:     // Now test for pointers to convert
        !           704:     if (strchr(szTemp, ':') != NULL) {
        !           705:         // This NEEDS to be rewritten!!!!!
        !           706:         usOffset = 0;
        !           707:         for (psz = szTemp; *psz; psz++) {
        !           708:             if ((*psz >= '0') && (*psz <= '9'))
        !           709:                 usOffset = (usOffset << 4) + (USHORT)(*psz - '0');
        !           710:             else if ((*psz >= 'A') && (*psz <= 'F'))
        !           711:                 usOffset = (usOffset << 4) + (USHORT)(*psz - 'A' + 10 );
        !           712:             else if (*psz == ':') {
        !           713:                 usSel = usOffset;
        !           714:                 usOffset = 0;
        !           715:             }
        !           716:             else
        !           717:                 break;
        !           718:         }
        !           719: 
        !           720:         // Finally return the value
        !           721:         return (MAKEULONG(usOffset, usSel));
        !           722: 
        !           723:     }
        !           724: 
        !           725:     /* Quick and Dirty conversion functions */
        !           726:     lVal = 0;
        !           727:     if (szTemp[0] == '0' && szTemp[1] == 'X') {
        !           728:         /* Hex values */
        !           729:         for (psz = &szTemp[2]; *psz; psz++) {
        !           730:             if ((*psz >= '0') && (*psz <= '9'))
        !           731:                 lVal = (lVal << 4) + (ULONG)(*psz - '0');
        !           732:             else if ((*psz >= 'A') && (*psz <= 'F'))
        !           733:                 lVal = (lVal << 4) + (ULONG)(*psz - 'A' + 10 );
        !           734:             else
        !           735:                 return (lVal);
        !           736:         }
        !           737: 
        !           738:     } else {
        !           739:         /* Base 10 */
        !           740:         for (psz = szTemp; *psz; psz++) {
        !           741:             if ((*psz >= '0') && (*psz <= '9'))
        !           742:                 lVal = lVal * 10 + (ULONG)(*psz - '0');
        !           743:             else
        !           744:                 return (lVal);
        !           745:         }
        !           746:     }
        !           747: 
        !           748:     return (lVal);
        !           749: }
        !           750: 
        !           751: 

unix.superglobalmegacorp.com

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