Here's a little helpful tip which you can use if you need to
display the hex string of a byte in a tooltip. This can be
handy to display some debugging info, if nothing else during
testing. I used it to display the Direct Input key code in
hex assigned dynamically to a control.
In a typical MOUSE_TOOLTIP_TEXT_STRING() you can use %1!d! to
display a decimal (base 10) integer, but it does not implement
the 'x' format (like printf), ie you can't do %1!x! and have
it display the byte in hex. (At least I haven't been able to
do so)
First, define a global static c-string like this:
static char hexString[] = "00"; // NULL terminated
Be sure to use the "" (not ''), so that it is NULL terminated.
Define the following static function:
static char* byteArrayToHexString(byte in)
{
byte ch = 0x00;
int i = 0;
char pseudo[] = {"0123456789ABCDEF"};
ch = (byte) (in & 0xF0); // Strip off high nibble
ch = (byte) (ch >> 4); // Shift the bits down
ch = (byte) (ch & 0x0F); // In case high order bit was set
hexString[0] = pseudo[ (int)ch ]; // Convert nibble to hex
ch = (byte) (in & 0x0F); // Strip off low nibble
hexString[1] = pseudo[ (int)ch ]; // Convert nibble to hex
hexString[2] = NULL;
return hexString;
}
Now, create a TOOLTIP callback function:
static PCSTRINGZ CALLBACK GetHexString(FLOAT64 number, ID id,
PCSTRINGZ string, MODULE_VAR *source_var, PGAUGEHDR gauge)
{
byteArrayToHexString( byteToConvert );
return hexString;
}
The function uses a global variable (vs. new allocated
memory) to avoid having to unroll the macros to insert
appropriate delete [] pointer statements to avoid memory
leaks.
Now define an appropriate tooltip arg:
MOUSE_TOOLTIP_ARGS (Dynamic_Args)
MOUSE_TOOLTIP_ARG(MODULE_VAR_NONE, 1, NULL, NULL, NULL, NULL, NULL, GetAssignedKey)
MOUSE_TOOLTIP_ARGS_END
And the mouse tooltip string in your mouse section:
MOUSE_BEGIN(gauge_rect, HELP_NONE, 0, 0)
MOUSE_TOOLTIP_TEXT_STRING ("Hex: 0x%1!s!", Dynamic_Args)
MOUSE_CHILD_FUNCT(0, 0, 33, 33, CURSOR_GRAB,
MOUSE_LEFTSINGLE | MOUSE_LEFTRELEASE | MOUSE_DOWN_REPEAT |
MOUSE_LEAVE, Gauge_mcb)
MOUSE_END
You may find other uses for function.
Enjoy!
Patrick