• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 344
  • Last Modified:

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) {
        AfxMessageBox("why....");
    }

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

Thanks
0
minnirok
Asked:
minnirok
1 Solution
 
AlexFMCommented:
This is my test:

    m_static.Create(
        _T("123"),
        WS_CHILD | WS_VISIBLE,
        CRect(0,0,100,100),
        this,
        100);

    if ( m_static.GetStyle() & SS_BLACKFRAME )
    {
        AfxMessageBox(_T("Yes"));
    }

MessageBox is not shown. Can you show your exact code? Small mistake like && instead of & can give this effect.
0
 
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 :-)
0
 
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,
Deepu
0
 
AndyAinscowCommented:
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 ) )
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now