Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Screen Capture
Message
 
 
To
07/11/2000 15:57:17
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Miscellaneous
Thread ID:
00438986
Message ID:
00439018
Views:
29
>Is it possible to go sniffing around in VFP's message queue?

Sure, use the _ActivateHandler() function in FoxTools. There's an example in the help file. Some poorly formatted sample code:
// Code begins here

#include "pro_ext.h"
int HandlerID;
int EventNo;
unsigned short event_container[1024];
int EventHandler(WHandle theWindow, EventRec *eventrec)

{
if(EventNo<1024)
{

if(eventrec->what != nullEvent)
{

event_container[EventNo] = eventrec->what;
EventNo++;
}
}

switch(eventrec->what)

{

case nullEvent:
_PutStr("nullEvent\r\n");
break; 

case mouseDownEvent:
_PutStr("mouseDownEvent\r\n");
break;

case keyDownEvent:
_PutStr("keyDownEvent\r\n");
break;

case activateEvent:
_PutStr("activateEvent\r\n");
break;

case deactivateEvent:
_PutStr("deactivateEvent\r\n");
break;

case menuHitEvent:
_PutStr("menuHitEvent\r\n");
break;

case closeEvent:
_PutStr("closeEvent\r\n");
break;

case hideEvent:
_PutStr("hideEvent\r\n");
break;

case showEvent:
_PutStr("showEvent\r\n");
break;

case hotkeyEvent:
_PutStr("hotkeyEvent\r\n");
break;

case sizeEvent:
_PutStr("sizeEvent\r\n");
break;

case updateEvent:
_PutStr("updateEvent\r\n");
break;

case moveEvent:
_PutStr("moveEvent\r\n");
break;

case mouseUpEvent:
_PutStr("mouseUpEvent\r\n");
break;

case mMouseDownEvent:
_PutStr("mMouseDownEvent\r\n");
break;

case mMouseUpEvent:
_PutStr("mMouseUpEvent\r\n");
break;

case rMouseDownEvent:
_PutStr("rMouseDownEvent\r\n");
break;

case rMouseUpEvent:
_PutStr("rMouseUpEvent\r\n");
break;

case mouseMoveEvent:
_PutStr("mouseMoveEvent\r\n");
break;

case mouseWheelEvent:
_PutStr("mouseWheelEvent\r\n");
break;

case menuInitEvent:
_PutStr("menuInitEvent\r\n");
break;

case menuUpdateEvent:
_PutStr("menuUpdateEvent\r\n");
break;

case toolbarEvent:
_PutStr("toolbarEvent\r\n");
break;

case alarmEvent:
_PutStr("alarmEvent\r\n");
break;

} 

return NO; // Tell VFP that it still needs to handle this event.

}

void startlog(void)

{
register int index;
HandlerID = _ActivateHandler(EventHandler);
EventNo = 0;
for(index=0; index<1024; index++)
    event_container[index] = -1; // initialize the array between successive runs
}

void stoplog(void)
{
_DeActivateHandler(HandlerID);
}

void retrieve_stored_event(ParamBlk FAR *parm)
{
int the_eventno;
the_eventno = parm->p[0].val.ev_long;
if(the_eventno<1024)
    _RetInt(event_container[the_eventno],10);
}

void finishing(void)
{
_DeActivateHandler(HandlerID);
}

FoxInfo myFoxInfo[] =
{
{"STARTLOG", (FPFI) startlog, 0, ""},
{"STOPLOG", (FPFI) stoplog, 0, ""},
{"GETEVENT", (FPFI) retrieve_stored_event, 1, "N"},
{"FINISHING", (FPFI) finishing, CALLONUNLOAD, ""}
};

FoxTable _FoxTable =
{
(FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};
// Code ends here
If you're truly a glutton, you can even write a message loop using VFP, but only if the messages are placed in the queue using PostMessage. The VFP runtime eats anything sent with SendMessage(). Doing this in VFP will impact performance, though. Truly horrid sample code:
*-- Code begins here
#include winuser.h

Declare Integer GetMessage In Win32Api String @lpMsg, Integer, Integer, Integer
Declare Integer TranslateMessage In Win32Api String @lpMsg
Declare Long DispatchMessage In Win32Api String @lpMsg

Set libr to home()+"foxtools"
HWnd = MainHwnd()

*-- Create the message structure
lpMsg = LongToStr(hWnd) + Space(22)
bNotDone = .f.

*-- Translating your basic C message loop to FoxPro
Do While !bNotDone
	GetMessage(@lpMsg, hWnd, 0, 0)
	lnMessage = StrToLong(Substr(lpMsg, 5,4))
	If lnMessage = WM_QUIT && Parse the message out
		bNotDone = .t.
	Endif

*-- Do something with non-WM_QUIT messages

*-- Process Windows events. Not sure if this is needed, still experimenting
	DoEvents

*-- Print out message value, just to show that it works.
	?lnMessage
	TranslateMessage(@lpMsg)
	DispatchMessage(@lpMsg)
Enddo

*-- The following function converts a long integer to an ASCII
*-- character representation of the passed value in low-high format.
******************
Function LongToStr
******************
* Passed : 32-bit non-negative numeric value (lnLongval)
* Returns : ascii character representation of passed value in low-high
* format (lcRetstr)
* Example :
* m.long = "999999"
* m.longstr = long2str(m.long)

Parameters lnLongval
Private i, lcRetstr
lcRetstr = ""

For i = 24 TO 0 STEP -8
	lcRetstr = CHR(INT(lnLongval/(2^i))) + lcRetstr
	lnLongval = MOD(lnLongval, (2^i))
Next

Return lcRetstr



*-- The following function converts a string in low-high format to a
*-- long integer.
******************
Function StrToLong
******************
* Passed: 4-byte character string (lcLongstr) in low-high ASCII format
* Returns: long integer value
* Example:
* m.longstr = "1111"
* m.longval = str2long(m.longstr)

Parameters lcLongstr
Private i, lnRetval

lnRetval = 0
For i = 0 TO 24 STEP 8
	lnRetval = lnRetval + (ASC(lcLongstr) * (2^i))
	lcLongstr = RIGHT(lcLongstr, LEN(lcLongstr) - 1)
Next

Return lnRetval
*-- Code ends here
Mike Stewart
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform