Introduction
Flag Lookup is a simple utility to decode flags into individual values that were combined
to make them. It also demonstrates drag-drop of values between the VC++ debugger and your application.
It can find out the values for flags used for Window Styles, Extended Window Styles,
Class styles and SetWindowPos flags.
Description
We make flags for some windows functions by combining individual bits( like
WS_CHILD | WS_BORDER
. etc). The problem is while debugging, given a combined value it is
difficult to find out the individual values that were OR-ed to make it.
This utility reads the value and displays each bit in a list box.
You can copy-paste a value to it or drag and drop it from the debugger window. Currently
it is implemented for Window Styles, Extended Window styles, Class styles and
SetWindowPos flags. You can add new sets to it without great effort.
How It Works
The Strings for display are defined in arrays like this:
const char* bExtendedStyles[128]=
{
"WS_EX_RIGHTSCROLLBAR",
"WS_EX_DLGMODALFRAME",
"",
"WS_EX_NOPARENTNOTIFY",
"WS_EX_TOPMOST",
"WS_EX_ACCEPTFILES",
"WS_EX_TRANSPARENT",
.
.
.
}
The sequence of the array has to be the same as the sequence of bits.. ( i.e binary 0001 , 0010 , 0100 , 1000 etc..).
I make the array by copying the #defines
in windows header files ( winuser.h in this case). There will be a separate
array for each type ( Window Styles, Extended Window Styles etc). I just pass the corresponding array to the function
that displays the strings.
Now the logic for looking up the values is simple, I iterate thru each bit in the input value and if it is set ( =1),
I get the corresponding value from the array and add it to the listbox.
For implementing drag and drop there is a class CFLDropTarget
which is derived from COleDropTarget
.
OnDrop
function is overridden. In this function the following is used to get the value, when it is dragged in
from a debugger 'Variables' window.
BOOL CFLDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObject,
DROPEFFECT dropEffect, CPoint point)
{
HGLOBAL hData = pDataObject->GetGlobalData(CF_TEXT);
char *pData = (char*)GlobalLock(hData);
CString strData = pData;
int nIndex = strData.ReverseFind('\t');
strData = strData.Mid(nIndex+1);
strData.TrimLeft();
strData.TrimRight();
. . .
. . .
The Dlg class has an object of CFLDropTarget
as a member. The Register
method is called on the member in
OnCreate
on the dialog class.