Link to home
Start Free TrialLog in
Avatar of andla
andla

asked on

Finding out if a style is applied to a window.

Hi!

Please help me solve this.

I want a method of finding out wich styles a window has.
The current way i do this is checking the bits like this.

if(style & WS_TABSTOP)
{
     string=AddString(string,"WS_TABSTOP| ",1);
}

But when i want to check WS_OVERLAPPED i can't because it is defined as zero and fails in the if statement.

How can i create a routine that works with all types ?

Regards
Andla
Avatar of jkr
jkr
Flag of Germany image

"GetWindowLong()" gan be used like this, e.g.

DWORD dwStyle = GetWindowLong ( hWnd, GWL_STYLE);
Avatar of andla
andla

ASKER

Yes i know but this gets all the bits. I want to check a sertain bit.

I thought that i maybe could use

if(!(style & WS_OVERLAPPED))
{
    string=AddString(string,"WS_TABSTOP| ",1);
}
but this would be true even if a window doesn't have this style.

/Andla
>>I thought that i maybe could use
>>if(!(style & WS_OVERLAPPED))
>>{
>>   string=AddString(string,"WS_TABSTOP| ",1);
>>}
>>but this would be true even if a window doesn't have
>>this style.

No, this should solve your problem - let's see:

"style & WS_OVERLAPPED" will be TRUE if the bit is set and "FALSE" if not. So applying "!" to the expresseion will result in a call to "AddString()" is "WS_OVERLAPPED" is NOT set...
Avatar of andla

ASKER

>>"style & WS_OVERLAPPED" will be TRUE if the bit is set
>>and "FALSE" if not. So applying "!" to the expresseion
>>will result in a call to "AddString()"
>>is "WS_OVERLAPPED" is NOT set...

Yes i know.

Check out how WS_OVERLAPPED is defined.
#define WS_OVERLAPPED       0x00000000L
#define WS_POPUP            0x80000000L
#define WS_CHILD            0x40000000L
#define WS_MINIMIZE         0x20000000L
#define WS_VISIBLE          0x10000000L
...

And for button styles:
#define BS_PUSHBUTTON       0x00000000L
#define BS_DEFPUSHBUTTON    0x00000001L
#define BS_CHECKBOX         0x00000002L
#define BS_AUTOCHECKBOX     0x00000003L
#define BS_RADIOBUTTON      0x00000004L
....

The WS_OVERLAPPED and BS_PUSHBUTTON doesnt work on this code.

This doesn't work
if((style & WS_OVERLAPPED))
{
     string=AddString(string,"WS_OVERLAPPED| ",1);
}

This works fine because WS_POPUP is not zero.
if((style & WS_POPUP))
{
     string=AddString(string,"WS_POPUP| ",1);
}

This doesn't work
if((style & BS_PUSHBUTTON))
{
     string=AddString(string,"BS_PUSHBUTTON| ",1);
}

This works fine because BS_DEFPUSHBUTTON is not zero.
if((style & BS_DEFPUSHBUTTON))
{
     string=AddString(string,"BS_DEFPUSHBUTTON| ",1);
}

/Andla

>>Check out how WS_OVERLAPPED is defined.
>>#define WS_OVERLAPPED       0x00000000L


Ooops, I better had .o)

Why don't you just

if(style != WS_OVERLAPPED))

then? If it IS WS_OVERLAPPED (iow: 0), no other bit can be set anyway...
Avatar of andla

ASKER

I don't understand this...
Avatar of andla

ASKER

I figured this out i think. By setting a mask that restrict other bits that doesnt belong to the style group.
I show you how i did this.
          #define BS_TYPE_MASK2  0x00000080L
          switch(style & BS_TYPE_MASK2)
          {
               case BS_TEXT:
                    string=AddString(string,"BS_TEXT| ",1);
               break;
               case BS_ICON:
                    string=AddString(string,"BS_ICON| ",1);
               break;
               case BS_BITMAP:
                    string=AddString(string,"BS_BITMAP| ",1);
               break;
          }

          #define BS_TYPE_MASK3  0x00000F00L
     //     Sleep(0);
          switch(style & BS_TYPE_MASK3)
          {
               case BS_LEFT:
                    string=AddString(string,"BS_LEFT| ",1);
               break;
               case BS_RIGHT:
                    string=AddString(string,"BS_RIGHT| ",1);
               break;
               case BS_CENTER:
                    string=AddString(string,"BS_CENTER| ",1);
               break;
               case BS_TOP:
                    string=AddString(string,"BS_TOP| ",1);
               break;
               case BS_BOTTOM:
                    string=AddString(string,"BS_BOTTOM| ",1);
               break;
               case BS_VCENTER:
                    string=AddString(string,"BS_VCENTER| ",1);
               break;
          }


I don't feel that you gave me an answer that helped me but i'm grateful that you tried. I would be happy if you could help me figure out how to remove bits in a style group. It is not just by putting
wndstyle =wndstyle&~style;

I will try to experiment with masks and se if it works.

Cheers
Andla


If you wanted to set, say, the WS_POPUP style independently of the rest of the style, you could use:

style = (style & ~(WS_POPUP | WS_CHILD)) | WS_POPUP

This would remove any existing style, then add the new one. I'm really not sure you should be changing THOSE particular style bits on the fly, mind you...
Avatar of andla

ASKER

Thanks for your tip.
Not sure if i got this right.
>>This would remove any existing style, then add the new
>>one

//winuser.h
#define WS_POPUP            0x80000000L
#define WS_CHILD            0x40000000L
#define WS_MINIMIZE         0x20000000L
#define WS_VISIBLE          0x10000000L

Should it not be that the highest mask level (0x80000000L) is used to restric other masks in the same level ?
I'm pretty unsure of this stuff so i'm trying to get a clear picture.

Now WS_POPUP is the highest number but to be sure i use 'F' witch is the highest in this group. Should i not use it like this:

style = (style & ~(WS_POPUP | 0xF0000000L)) | WS_POPUP


Regards
Andla
Avatar of andla

ASKER

I did a small source code that could maybe work if i know the right stuff wich you do :-)

     switch(style)
     {
          case BS_DEFPUSHBUTTON:
          case BS_PUSHBUTTON       0x00000000L
          case BS_DEFPUSHBUTTON    0x00000001L
          case BS_CHECKBOX         0x00000002L
          case BS_AUTOCHECKBOX     0x00000003L
          case BS_RADIOBUTTON      0x00000004L
          case BS_3STATE           0x00000005L
          case BS_AUTO3STATE       0x00000006L
          case BS_GROUPBOX         0x00000007L
          case BS_USERBUTTON       0x00000008L
          case BS_AUTORADIOBUTTON  0x00000009L
          case BS_OWNERDRAW        0x0000000BL

          #define MASK1        0x0000000FL//Highest mask
         
          //Do some magic
          //wndstyle =wndstyle&~style;
          break;
     }
SOLUTION
Avatar of pjknibbs
pjknibbs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andla

ASKER

I think i must do a reserch and create a small project. I feal that i almost know the secret about setting the bits and using mask with bit operators. Now i have to figure out some more what is relly happening underneath.

I got many ideas but i need the truth that i can base new ideas on. Please let me know i got this right:

I see groups as bit levels. The first group is on the
higest level and the second group a level below and so on
until it toutches the L character defined as a LONG type.
A group can also be two or more bit levels giving it more
variations. I'm not sure why they don't use the 0xF00.. in the first group ? Now if i am not misstaken i can use the
0xF000000000L in the first level to make a mask restricted
to only that level when manipulating and use the
0x0F00000000L to make restrictions on the second group and so on.

Please let me know what is wrong and what is right with this above.


//first group
#define WS_OVERLAPPED       0x00000000L
#define WS_POPUP            0x80000000L
#define WS_CHILD            0x40000000L
#define WS_MINIMIZE         0x20000000L
#define WS_VISIBLE          0x10000000L

//second
#define WS_DISABLED         0x08000000L
#define WS_CLIPSIBLINGS     0x04000000L
#define WS_CLIPCHILDREN     0x02000000L
#define WS_MAXIMIZE         0x01000000L

//third
#define WS_CAPTION          0x00C00000L    
#define WS_BORDER           0x00800000L
#define WS_DLGFRAME         0x00400000L
#define WS_VSCROLL          0x00200000L
#define WS_HSCROLL          0x00100000L

//fourth
#define WS_SYSMENU          0x00080000L
#define WS_THICKFRAME       0x00040000L
#define WS_GROUP            0x00020000L
#define WS_TABSTOP          0x00010000L

/Andla
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andla

ASKER

Sorry i have forgotten about this.

Splitting points.

Yours sincerely
Andla