Get Style of static control

Posted on 2006-04-14
Last Modified: 2013-11-20
I'm creating a static control with only 2 styles to it:

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

When I try checking if it's got a static specific style on it that I did NOT specify, it returns true!?

    if (static.GetStyle() & SS_BLACKFRAME) {

Any idea why it says that style is active, yet I didn't specify it?

Question by:minnirok
    LVL 48

    Accepted Solution

    This is my test:

            WS_CHILD | WS_VISIBLE,

        if ( m_static.GetStyle() & SS_BLACKFRAME )

    MessageBox is not shown. Can you show your exact code? Small mistake like && instead of & can give this effect.
    LVL 8

    Expert Comment

    The only mistake I see in your code, is that you use "static" as a variable name. Since "static" is a keyword, this is not allowed. From the documentation:

    "Keywords are predefined reserved identifiers that have special meanings. They cannot be used as identifiers in your program."

    What happens if you break that rule? I think the only correct answer is: Undefined behaviour! Change the name of your variable and see what happens :-)
    LVL 11

    Expert Comment

    I think now it must be in a constructur and when the scope of the constructor goes it deletes the CStatic object.Put your "CStatic static;"  statement in your header file as your class member variable.

    Best Regards,
    LVL 43

    Expert Comment

    As the lines
     CStatic static;
        static.Create(WS_CHILD | WS_VISIBLE);
    are pseudo code (they should not compile, static is reserved keyword, Create takes more paramters) it would be better if you posted your actual code.

    I guess Alex has hit the nail on the head and you use the AND (&&) instead of the bitwise AND (&).

    Another possibility is you have a customised class (eg. CMyStatic) and in the PreCreateWindow of the CMyStatic you set some extra styles there.

    A further possibility is you create a CStatic (eg. m_static) but you test another control for the SS_BLACKFRAME  (eg. if ( m_staticAnotherControl.GetStyle() & SS_BLACKFRAME ) )

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Suggested Solutions

    Title # Comments Views Activity
    Detect CR LF to each line 12 116
    maxBlock challenge 30 88
    dog bark java program 15 69
    no14 challenge 14 46
    In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
    Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
    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.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    779 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

    21 Experts available now in Live!

    Get 1:1 Help Now