Click here to Skip to main content
15,885,899 members
Articles / Desktop Programming / MFC
Article

A Tool to look up Common Windows Flags

Rate me:
Please Sign up or sign in to vote.
3.67/5 (2 votes)
20 Feb 20022 min read 50K   1.4K   19  
A simple tool to decode windows flags , like window styles, extended styles. Supports drag and drop.

Sample Image - flaglookup.jpg

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", //0x00000000L
    "WS_EX_DLGMODALFRAME",  //0x00000001L
    "",
    "WS_EX_NOPARENTNOTIFY", //0x00000004L
    "WS_EX_TOPMOST",        //0x00000008L
    "WS_EX_ACCEPTFILES",    //0x00000010L
    "WS_EX_TRANSPARENT",    //0x00000020L
    .
    .
    .
}

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect
United Kingdom United Kingdom
Has been programming for 7 years, mostly in Visual C++, C# .NET and occasionally in Java

Comments and Discussions

 
-- There are no messages in this forum --