get style of a control

Posted on 2006-04-14
Last Modified: 2013-11-20

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_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();
            if (dw & it->second) {
                 strStyle += it->first + " | ";
    return strStyle;

int main()
    CEdit edit;
    edit.create(WS_BORDER | WS_CHILD | ES_MULTILINE...);

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,

Question by:minnirok
    LVL 14

    Accepted Solution

    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.
    LVL 7

    Author Comment

    Ahhh curses..

    I'll give it a try
    LVL 7

    Author Comment

    Ok looks like it's working with specific maps.


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

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

    if (static.GetStyle() & SS_BLACKFRAME) {

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

    LVL 14

    Expert Comment

    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-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
    If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
    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.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now