|
|
Microsoft OS/2 SDK 2.0 05-30-1990
/****************************** Module Header ******************************\
* Module Name: message.c - procecures to process the message dialog
*
* Created: Microsoft, IBM Corporation 1990
*
\***************************************************************************/
#define INCL_WIN
#define INCL_WINSYS
#define INCL_DOSPROCESS
#include <os2.h>
#include <stdio.h>
#include <string.h>
#include "spy.h"
#include "spyhk32.h"
#include <time.h>
#include <stdlib.h>
/* This is a real hack, estimate size of WND Structure */
#define SIZEOFWND 34
#define MAXMSGBYTES 100
/************* GLOBAL VARIABLES */
/************* PROCEDURE DECLARATIONS */
void UpdMsgsLBSels (USHORT, BOOL);
void UpdMsgTblFromLB (HWND);
void ProcessQueueMsg(QMSGSPY *);
void SelOrDeselWithMouse(BOOL);
void UpdateMsgBoxCurMsgText(HWND);
void SelectMessageFromText(HWND);
void SendMsgProcCmd(HWND, USHORT);
void SetItemHexNum(HWND, USHORT, ULONG);
ULONG GetItemVal(HWND, USHORT, BOOL, PSZ, PSZ);
/**************************** Public Function ******************************\
* MRESULT EXPENTRY SpyMsgDlgProc (hwnd, msg, mp1, mp2)
*
* Effects: Message List dialog procedure
*
*
* Return value:
\***************************************************************************/
MRESULT EXPENTRY SpyMsgDlgProc(hwnd, msg, mp1, mp2)
HWND hwnd;
USHORT msg;
MPARAM mp1;
MPARAM mp2;
{
SHORT i;
MSGI *pmsgi;
USHORT item;
SHORT bHooksNew;
USHORT iItemFocus; /* Index to item that has the focus */
switch (msg) {
case WM_INITDLG:
/*
* Initialize the list box with the list of messages that are
* defined in our message table
*/
iCurItemFocus = -1;
pmsgi = rgmsgi; /* Point to start of list */
hwndMessageLB = WinWindowFromID(hwnd, DID_OMSGLIST);
for (i = 0; i < cmsgi; i++) {
pmsgi->iListBox = item = (USHORT)WinSendMsg(hwndMessageLB,
LM_INSERTITEM,
(MPARAM)(spyopt.fAlphaSortMsgList? LIT_SORTASCENDING : LIT_END),
(MPARAM)(PSZ)pmsgi->szMsg);
WinSendMsg(hwndMessageLB, LM_SETITEMHANDLE, (MPARAM)item,
(MPARAM)i);
if (pmsgi->wOptions & MSGI_ENABLED) {
WinSendMsg(hwndMessageLB, LM_SELECTITEM, (MPARAM)item,
(MPARAM)TRUE);
}
pmsgi++;
}
/*
* If alpha Sort, we need to make a second pass through, and update
* our indexes of where each message is in the list box
*/
if (spyopt.fAlphaSortMsgList) {
for (i = 0; i < cmsgi; i++) {
item = (USHORT)WinSendMsg(hwndMessageLB, LM_QUERYITEMHANDLE,
MPFROMSHORT(i), 0L);
rgmsgi[item].iListBox = i;
}
}
/* Initialize the Hook type record */
WinSendDlgItemMsg(hwnd, DID_OINPUT, BM_SETCHECK,
(MPARAM)(spyopt.bHooks & SPYH_INPUT)?1 : 0, 0L);
WinSendDlgItemMsg(hwnd, DID_OSENDMSG, BM_SETCHECK,
(MPARAM)(spyopt.bHooks & SPYH_SENDMSG)?1 : 0, 0L);
WinSendDlgItemMsg(hwnd, DID_OTHERMSGS, BM_SETCHECK,
(MPARAM)(spyopt.fDispOtherMsgs), 0L);
WinSetFocus(HWND_DESKTOP, hwndMessageLB);
fTrackingListBox = TRUE;
return ((MRESULT)TRUE); /* We set the focus */
break;
case WM_CHAR:
/*
* Handle VK_ENTER and VK_NEWLINE if our Edit control has
* the focus and it is a keydown
*/
if (!(SHORT1FROMMP(mp1) & KC_KEYUP) &&
(SHORT1FROMMP(mp1) & KC_VIRTUALKEY) &&
( (SHORT2FROMMP(mp2) == VK_ENTER) ||
(SHORT2FROMMP(mp2) == VK_NEWLINE) )) {
if (WinQueryFocus(HWND_DESKTOP, FALSE) ==
WinWindowFromID(hwnd, DID_MSGEDIT)) {
SelectMessageFromText(hwnd);
break;
}
}
/* Normaly pass to dialog procedure to handle message */
return(WinDefDlgProc(hwnd, msg, mp1, mp2));
break;
case WM_COMMAND:
switch (SHORT1FROMMP(mp1)) {
case DID_OK:
/*
* Call to update the Message table select bits
*/
UpdMsgTblFromLB (hwnd);
/* Setup new hook options */
bHooksNew = 0;
if ((BOOL)WinSendDlgItemMsg(hwnd,
DID_OINPUT, BM_QUERYCHECK, 0L, 0L))
bHooksNew = SPYH_INPUT;
if ((BOOL)WinSendDlgItemMsg(hwnd,
DID_OSENDMSG, BM_QUERYCHECK, 0L, 0L))
bHooksNew |= SPYH_SENDMSG;
if (bHooksNew != spyopt.bHooks) {
SpyReleaseHook (FALSE); /* Dont clear queue */
spyopt.bHooks = bHooksNew;
SpyInstallHook(hab, hmqSpy, spyopt.bHooks); /* Install hook again */
WinSendMsg(WinWindowFromID(hwndSpyFrame, FID_MENU),
MM_SETITEMATTR, MPFROM2SHORT(CMD_INPUTHOOK, TRUE),
MPFROM2SHORT(MIA_CHECKED,
(spyopt.bHooks & SPYH_INPUT) ? MIA_CHECKED : 0));
WinSendMsg(WinWindowFromID(hwndSpyFrame, FID_MENU),
MM_SETITEMATTR, MPFROM2SHORT(CMD_SENDMSGHOOK, TRUE),
MPFROM2SHORT(MIA_CHECKED,
(spyopt.bHooks & SPYH_SENDMSG) ? MIA_CHECKED : 0));
}
/* Fall through to DID_CANCEL */
case DID_CANCEL:
/* Now dismiss the dialog */
hwndMessageLB = NULL; /* Not here anymore to process */
fTrackingListBox = FALSE;
WinDismissDlg(hwnd, SHORT1FROMMP(mp1));
break;
/*
* These case simply update the listbox with which messages are
* enabled
*/
case DID_MALL:
UpdMsgsLBSels (0, TRUE);
break;
case DID_MNONE:
UpdMsgsLBSels (0, FALSE);
break;
case DID_MCON:
UpdMsgsLBSels (MSGI_KEY, TRUE);
break;
case DID_MCOFF:
UpdMsgsLBSels (MSGI_KEY, FALSE);
break;
case DID_MMON:
UpdMsgsLBSels (MSGI_MOUSE, TRUE);
break;
case DID_MMOFF:
UpdMsgsLBSels (MSGI_MOUSE, FALSE);
break;
case DID_MFON:
UpdMsgsLBSels (MSGI_FREQ, TRUE);
break;
case DID_MFOFF:
UpdMsgsLBSels (MSGI_FREQ, FALSE);
break;
}
break;
default:
/*
* Default is to see if the listbox has changed its focus
* item number. If it has, then we want to display the information
* about the window that the listbox cursor is over. There is no
* legal way to do this, except to temporarily put the listbox into
* single selection mode and query the selection.
*/
if (fTrackingListBox && (hwndMessageLB != NULL)) {
WinSetWindowBits(hwndMessageLB, QWL_STYLE, 0L, LS_MULTIPLESEL);
iItemFocus = (USHORT)WinSendMsg(hwndMessageLB, LM_QUERYSELECTION,
(MPARAM)LIT_FIRST, 0L);
WinSetWindowBits(hwndMessageLB, QWL_STYLE, LS_MULTIPLESEL,
LS_MULTIPLESEL);
if (iItemFocus != iCurItemFocus) {
iCurItemFocus = iItemFocus;
UpdateMsgBoxCurMsgText(hwnd);
}
}
return(WinDefDlgProc(hwnd, msg, mp1, mp2));
break;
}
return 0L;
}
/***************************** Private Function ****************************\
* void UpdateMsgBoxCurMsgText()
*
* Effects:
* Updates the text that is displayed in the message text line
*
* History:
* 27-September-1988 KurtE
\***************************************************************************/
void UpdateMsgBoxCurMsgText(hwndDlg)
HWND hwndDlg;
{
SHORT sMsgI;
char szTemp[80];
if (iCurItemFocus >= 0) {
/* Get the messge index */
sMsgI = (SHORT)WinSendMsg(hwndMessageLB, LM_QUERYITEMHANDLE,
(MPARAM)iCurItemFocus, 0L);
sprintf(szTemp, "0x%04x - %s", rgmsgi[sMsgI].msg,
rgmsgi[sMsgI].szMsg);
WinSetDlgItemText(hwndDlg, DID_MSGEDIT, (PSZ)szTemp);
} else {
WinSetDlgItemText(hwndDlg, DID_MSGEDIT, (PSZ)"");
}
}
/***************************** Private Function ****************************\
* void SelectMessageFromText(hwndDlg)
*
* Effects:
* Updates the text that is displayed in the message text line
*
* History:
* 27-September-1988 KurtE
\***************************************************************************/
void SelectMessageFromText(hwndDlg)
HWND hwndDlg;
{
char szTemp[80];
USHORT msg;
MSGI *pmsgi;
int i;
/* First get the edit text from the string */
WinQueryDlgItemText(hwndDlg, DID_MSGEDIT, sizeof(szTemp),
(PSZ)szTemp);
if ((msg = UConvertStringToNum(szTemp)) != 0xffff) {
/* We have a number, now try to find message in message table */
pmsgi = PmsgiFromMsg(msg);
} else {
/* Assume String, Try to locate string in our table */
pmsgi = rgmsgi; /* Start at beginning of table */
/*
* This does simple string compares, it does not map case, nor
* does it trim the string.
*/
for (i=0; i < cmsgi; i++) {
if (strcmpi(pmsgi->szMsg, szTemp) == 0)
break;
pmsgi++;
};
if (i >= cmsgi)
pmsgi = NULL;
}
/*
* Have a pointer to MSGI of message, or NULL if not in list.
*/
if(pmsgi != NULL) {
/* First make sure it is visible */
WinSendMsg(hwndMessageLB, LM_SETTOPINDEX,
MPFROMSHORT(pmsgi->iListBox), (MPARAM)0L);
/* Always set it on */
WinSendMsg(hwndMessageLB, LM_SELECTITEM,
MPFROMSHORT(pmsgi->iListBox), MPFROMSHORT(TRUE));
} else {
WinAlarm(HWND_DESKTOP, WA_WARNING);
WinSetDlgItemText(hwndDlg, DID_MSGEDIT, (PSZ)"");
}
}
/**************************** Public Function ******************************\
* void UpdMsgsLBSels (USHORT uMask, fOnOrOff);
*
* Effects: Will update the selected items in the message listbox, that is
* displayed in the options dialog
*
* Return value: none
\***************************************************************************/
void UpdMsgsLBSels (uMask, fOnOrOff)
USHORT uMask;
BOOL fOnOrOff;
{
SHORT i;
MSGI *pmsgi;
/*
* Loop through all of the items in our list, if the mask is 0 or
* the bit is on in the item, then update the select state in listbox
* defined in our message table
*/
fTrackingListBox = FALSE;
pmsgi = rgmsgi; /* Point to start of list */
for (i = 0; i < cmsgi; i++) {
if ((uMask == 0) || (pmsgi->wOptions & uMask)) {
WinSendMsg(hwndMessageLB, LM_SELECTITEM,
(MPARAM)pmsgi->iListBox, (MPARAM)fOnOrOff);
}
pmsgi++;
}
fTrackingListBox = TRUE;
}
/**************************** Public Function ******************************\
* void UpdMsgsLBSels (HWND hwndDialog, USHORT uMask, fOnOrOff);
*
* Effects: Will update the selected items in the message listbox, that is
* displayed in the options dialog
*
* Return value: none
\***************************************************************************/
void UpdMsgTblFromLB (hwndDialog)
HWND hwndDialog;
{
USHORT i;
register MSGI *pmsgi;
USHORT itemSel;
/*
* Loop through all of the items in the list and update the selection
* status depending of if the item is selected in the list box or
* not.
*/
/* First simply turn off all of the bits */
pmsgi = rgmsgi;
for (i = 0; i < cmsgi; i++) {
pmsgi->wOptions &= ~MSGI_ENABLED;
pmsgi++;
}
/* Then turn on all of the selected items */
itemSel = (USHORT)LIT_FIRST;
while ((itemSel = (USHORT)WinSendMsg(hwndMessageLB, LM_QUERYSELECTION,
(MPARAM)itemSel, 0L)) != (USHORT)LIT_NONE) {
/* The item handle contains index in our array */
i = (USHORT)WinSendMsg(hwndMessageLB, LM_QUERYITEMHANDLE,
(MPARAM)itemSel, 0L);
rgmsgi[i].wOptions |= MSGI_ENABLED;
}
/* Get the Other message option from checkmark */
spyopt.fDispOtherMsgs = ((BOOL)WinSendDlgItemMsg(hwndDialog, DID_OTHERMSGS,
BM_QUERYCHECK, 0L, 0L));
/* Now call function to update the hooks message list */
UpdateHooksMsgTable();
}
/**************************** Public Function ******************************\
* void UpdateHooksMsgTable(void)
*
* Effects: Set the message bitmask to the hook, for interested messages.
* displayed in the options dialog
*
* Return value: none
\***************************************************************************/
void UpdateHooksMsgTable()
{
MSGI *pmsgi;
UCHAR rgb[MAXMSGFILTERBYTES];
int i;
UCHAR *prgb;
unsigned char mask;
/*
* First zero the bitmask
*/
memset(rgb,'\0', MAXMSGFILTERBYTES);
mask = 1;
prgb = rgb;
/*
* Quick and dirty loop to set the bits
*/
pmsgi = rgmsgi;
for (i = 0; i <= MAXMSGFILTER; i++) {
/* If enabled, set bit in bit table */
if (pmsgi->msg == i) {
if (pmsgi->wOptions & MSGI_ENABLED)
*prgb = pmsgi->bMPTypes | MP_ENABLED;
pmsgi++;
} else {
/* Hole in range, set it true */
*prgb |= mask;
}
prgb++;
}
/* Now call the hook function with the new mask */
SpySetMessageList((char FAR *)rgb, spyopt.fDispOtherMsgs);
}
/**************************** Public Function ******************************\
* EnableOrDisableMsg(BOOL fEnable)
*
* Effects: Fastway to enable or disable a particular message code. The one
* that is currently selected in the output listbox.
*
* Return value: none
\***************************************************************************/
void EnableOrDisableMsg(fEnable)
BOOL fEnable;
{
USHORT itemSel;
char szTemp[100];
char *psz;
MSGI *pmsgi;
SHORT i;
itemSel = (USHORT)WinSendMsg(hwndSpyList, LM_QUERYSELECTION,
(MPARAM)LIT_FIRST, 0L);
if (itemSel == (USHORT)LIT_NONE)
return; /* None to process */
/* Get the message text */
WinSendMsg(hwndSpyList, LM_QUERYITEMTEXT,
MPFROM2SHORT(itemSel, sizeof(szTemp)), (MPARAM)(PSZ)szTemp);
/* Now lets extract the messgae string from the line */
psz = &szTemp[3];
while (*psz != ' ')
psz++; /* locate first blank */
*psz = '\0'; /* Zero terminate string */
/*
* Loop through all of the items in our list, until we find a
* string that matches our string.
*/
pmsgi = rgmsgi; /* Point to start of list */
for (i = 0; i < cmsgi; i++) {
if (strcmpi(&szTemp[2], pmsgi->szMsg) == 0) {
/*
* Found our message, update the bit of the message, and
* call the function to let the hook know the new results
*/
if (fEnable)
pmsgi->wOptions |= MSGI_ENABLED;
else
pmsgi->wOptions &= ~MSGI_ENABLED;
UpdateHooksMsgTable(); /* Set Spys Msg table */
return;
}
pmsgi++;
}
}
/**************************** Public Function ******************************\
* MRESULT SendMsgDlgProc(...)
*
* Effects: This is the dialog procedure for the Send Message facility of spy
*
* Return value: none
\***************************************************************************/
extern MRESULT EXPENTRY SendMsgDlgProc(hwnd, msg, mp1, mp2)
HWND hwnd;
USHORT msg;
MPARAM mp1;
MPARAM mp2;
{
switch (msg) {
case WM_INITDLG:
break;
case WM_COMMAND:
SendMsgProcCmd(hwnd, LOUSHORT(mp1));
break;
default:
return(WinDefDlgProc(hwnd, msg, mp1, mp2));
break;
}
return 0L;
}
void SendMsgProcCmd(hwnd, id)
HWND hwnd;
USHORT id;
{
HWND hwndPoint;
BOOL fPostMsg;
USHORT msg;
MPARAM mp1;
MPARAM mp2;
MRESULT mresult;
char szLine1[80];
char szLine2[80];
char szTemp[12];
fPostMsg = TRUE;
switch (id) {
case DID_SELHWND:
// Call function to allow the user to point at a window.
hwndPoint = HwndSelWinWithMouse(hwnd, NULL, FALSE);
sprintf(szTemp, "%p", hwndPoint);
WinSetDlgItemText(hwnd, DID_HWND, (PSZ)szTemp);
break;
case DID_SEND:
fPostMsg = FALSE;
case DID_POST:
/* Send or post, setup to send the message */
/* First setup the Hwnd */
hwndPoint = (HWND)GetItemVal(hwnd, DID_HWND, FALSE, szLine1, szLine2);
sprintf(szTemp, "%p", hwndPoint);
WinSetDlgItemText(hwnd, DID_HWND, (PSZ)szTemp);
/* Now the MSG */
msg = (USHORT)GetItemVal(hwnd, DID_COMMAND, TRUE, szLine1, szLine2);
SetItemHexNum(hwnd, DID_COMMAND, (ULONG)msg);
/* Now the mp1 */
mp1 = (MPARAM)GetItemVal(hwnd, DID_MPARAM1, TRUE, szLine1, szLine2);
SetItemHexNum(hwnd, DID_MPARAM1, (ULONG)mp1);
/* Now the mp2 */
mp2 = (MPARAM)GetItemVal(hwnd, DID_MPARAM2, TRUE, szLine1, szLine2);
SetItemHexNum(hwnd, DID_MPARAM2, (ULONG)mp2);
/* Get initial values of two string variables */
WinQueryDlgItemText(hwnd, DID_STRING1, sizeof(szLine1), (PSZ)szLine1);
WinQueryDlgItemText(hwnd, DID_STRING2, sizeof(szLine2), (PSZ)szLine2);
/* Now Send or post the message */
if (fPostMsg)
mresult = (MRESULT)WinPostMsg(hwndPoint, msg, mp1, mp2);
else
mresult = WinSendMsg(hwndPoint, msg, mp1, mp2);
SetItemHexNum(hwnd, DID_RESULT, (ULONG)mresult);
/* Set the Ending values for the strings */
WinSetDlgItemText(hwnd, DID_STRING1, (PSZ)szLine1);
WinSetDlgItemText(hwnd, DID_STRING2, (PSZ)szLine2);
break;
case DID_CANCEL:
WinDismissDlg(hwnd, 1234);
WinDestroyWindow(hwnd);
WinSendMsg(WinWindowFromID(hwndSpyFrame, FID_MENU),
MM_SETITEMATTR, MPFROM2SHORT(CMD_SENDMSG, TRUE),
MPFROM2SHORT(MIA_DISABLED, 0));
break;
}
}
void SetItemHexNum(hwnd, idItem, lVal)
HWND hwnd;
USHORT idItem;
ULONG lVal;
{
char szTemp[20];
sprintf (szTemp, "0x%lx", lVal);
WinSetDlgItemText(hwnd, idItem, (PSZ)szTemp);
}
ULONG GetItemVal(hwnd, idItem, fLookup, psz1, psz2)
HWND hwnd;
USHORT idItem;
BOOL fLookup;
PSZ psz1;
PSZ psz2;
{
ULONG lVal;
char szTemp[80];
register char *psz;
MSGI *pmsgi;
SHORT i;
USHORT usSel;
USHORT usOffset;
WinQueryDlgItemText(hwnd, idItem, sizeof(szTemp), (PSZ)szTemp);
/* Quick and dirty convert string to uppercase */
for (psz = szTemp; *psz; psz++) {
if ((*psz >= 'a') && (*psz <= 'z'))
*psz = *psz - 'a' + 'A';
}
if (fLookup) {
// Try to find the string in our table.
pmsgi = rgmsgi; /* Start at beginning of table */
/*
* This does simple string compares, it does not map case, nor
* does it trim the string.
*/
for (i=0; i < cmsgi; i++) {
if (strcmpi(pmsgi->szMsg, szTemp) == 0)
break;
pmsgi++;
}
if (i < cmsgi)
return ((ULONG)pmsgi->msg);
}
/* Simple Test for &1 and &2 */
if (szTemp[0] == '&') {
if (szTemp[1] == '2')
return ((LONG)psz2);
else
return ((LONG)psz1);
}
// Now test for pointers to convert
if (strchr(szTemp, ':') != NULL) {
// This NEEDS to be rewritten!!!!!
usOffset = 0;
for (psz = szTemp; *psz; psz++) {
if ((*psz >= '0') && (*psz <= '9'))
usOffset = (usOffset << 4) + (USHORT)(*psz - '0');
else if ((*psz >= 'A') && (*psz <= 'F'))
usOffset = (usOffset << 4) + (USHORT)(*psz - 'A' + 10 );
else if (*psz == ':') {
usSel = usOffset;
usOffset = 0;
}
else
break;
}
// Finally return the value
return (MAKEULONG(usOffset, usSel));
}
/* Quick and Dirty conversion functions */
lVal = 0;
if (szTemp[0] == '0' && szTemp[1] == 'X') {
/* Hex values */
for (psz = &szTemp[2]; *psz; psz++) {
if ((*psz >= '0') && (*psz <= '9'))
lVal = (lVal << 4) + (ULONG)(*psz - '0');
else if ((*psz >= 'A') && (*psz <= 'F'))
lVal = (lVal << 4) + (ULONG)(*psz - 'A' + 10 );
else
return (lVal);
}
} else {
/* Base 10 */
for (psz = szTemp; *psz; psz++) {
if ((*psz >= '0') && (*psz <= '9'))
lVal = lVal * 10 + (ULONG)(*psz - '0');
else
return (lVal);
}
}
return (lVal);
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.