get style of a control

Hi,

I'm trying to format an edit control's style type into a nicely formatted string. I am doing something like:


map<CString, DWORD> mStyles;
mStyles["WS_BORDER"] = WS_BORDER;
mStyles["WS_CHILD"] = WS_CHILD;
// etc....

// Make a nice string rep of the style, like "WS_CHILD | WS_BORDER" ... etc
CString MakeStyleString(DWORD dw)
{
     CString strStyle = "";
     for (map<CString, DWORD>::iterator  it = mStyles.begin();
                                                             it != mStyles.end();
                                                             it++)
     {
            if (dw & it->second) {
                 strStyle += it->first + " | ";
            }
     }
    return strStyle;
}

int main()
{
    CEdit edit;
    edit.create(WS_BORDER | WS_CHILD | ES_MULTILINE...);
    AfxMessageBox(MakeStyleString(edit.GetStyle());
}

Ok so the above is a little pseudo-codeish, i know there are a few typos etc. But the function works MOST of the time, except when I start specifying styles like ES_MULTILINE. In this case, my function is saying there are styles in there that I had never put into the edit, like SS_BLACKFRAME and stuff - how did that get into the style? What am I doing wrong?

This is pretty urgent, any help would be great,

Thanks
LVL 7
minnirokAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RichieHindleCommented:
Not all window styles have unique values - the values are only unique within the set of styles for a given window class.  So within the STATIC styles, SS_CENTER is guaranteed different from SS_RIGHT, and within the button styles, BS_DEFPUSHBUTTON is guaranteed different from BS_CHECKBOX.  But when you look at the actual values, you'll see that BS_DEFPUSHBUTTON == SS_CENTER == 1, and BS_CHECKBOX == SS_RIGHT == 2.

So your code needs to know not only the style of the window, but also its window class, and it needs to know which styles apply to which class.  Rather than a single mStyles map, you need one for each window class.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
minnirokAuthor Commented:
Ahhh curses..

I'll give it a try
minnirokAuthor Commented:
Ok looks like it's working with specific maps.

But,

still my CStatic controls keep returning true on the following checks:

CStatic static;
static.Create(WS_CHILD | WS_VISIBLE);

if (static.GetStyle() & SS_BLACKFRAME) {
    AfxMessageBox("why....");
}

Any ideas? Is there some default style being applied I'm not aware of?

Thanks
RichieHindleCommented:
SS_BLACKFRAME is the value of the lower 5 bits of the style, rather than being a single bit.  Its value is 7, so if you have a static control of style SS_CENTER, whose value is 1, then (static.GetStyle() & SS_BLACKFRAME) will be true.  You need to do this:

if ((static.GetStyle() & SS_TYPEMASK) == SS_BLACKFRAME) {
    // It's a black frame
}

It's always helpful to look up the actual values of these styles in winuser.h, because it becomes obvious which ones are single bits, which ones belong in ranges of values, and what the masks are for those ranges.  Both my answers to your questions have come straight out of winuser.h.  8-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.