Get Style of static control

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?

Who is Participating?
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.

This is my test:


    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.

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
Knut HunstadCommented:
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 :-)
Deepu AbrahamR & D Engineering ManagerCommented:
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,
AndyAinscowFreelance programmer / ConsultantCommented:
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 ) )
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.