?
Solved

get style of a control

Posted on 2006-04-14
4
Medium Priority
?
298 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:minnirok
  • 2
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
RichieHindle earned 2000 total points
ID: 16455017
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.
0
 
LVL 7

Author Comment

by:minnirok
ID: 16455051
Ahhh curses..

I'll give it a try
0
 
LVL 7

Author Comment

by:minnirok
ID: 16455253
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
0
 
LVL 14

Expert Comment

by:RichieHindle
ID: 16455812
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-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question