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,"W S_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
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,"W
}
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
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,"W S_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,"W
}
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,"W S_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...
>>if(!(style & WS_OVERLAPPED))
>>{
>> string=AddString(string,"W
>>}
>>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...
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,"W S_OVERLAPP ED| ",1);
}
This works fine because WS_POPUP is not zero.
if((style & WS_POPUP))
{
string=AddString(string,"W S_POPUP| ",1);
}
This doesn't work
if((style & BS_PUSHBUTTON))
{
string=AddString(string,"B S_PUSHBUTT ON| ",1);
}
This works fine because BS_DEFPUSHBUTTON is not zero.
if((style & BS_DEFPUSHBUTTON))
{
string=AddString(string,"B S_DEFPUSHB UTTON| ",1);
}
/Andla
>>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,"W
}
This works fine because WS_POPUP is not zero.
if((style & WS_POPUP))
{
string=AddString(string,"W
}
This doesn't work
if((style & BS_PUSHBUTTON))
{
string=AddString(string,"B
}
This works fine because BS_DEFPUSHBUTTON is not zero.
if((style & BS_DEFPUSHBUTTON))
{
string=AddString(string,"B
}
/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...
>>#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...
ASKER
I don't understand this...
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,"B S_TEXT| ",1);
break;
case BS_ICON:
string=AddString(string,"B S_ICON| ",1);
break;
case BS_BITMAP:
string=AddString(string,"B S_BITMAP| ",1);
break;
}
#define BS_TYPE_MASK3 0x00000F00L
// Sleep(0);
switch(style & BS_TYPE_MASK3)
{
case BS_LEFT:
string=AddString(string,"B S_LEFT| ",1);
break;
case BS_RIGHT:
string=AddString(string,"B S_RIGHT| ",1);
break;
case BS_CENTER:
string=AddString(string,"B S_CENTER| ",1);
break;
case BS_TOP:
string=AddString(string,"B S_TOP| ",1);
break;
case BS_BOTTOM:
string=AddString(string,"B S_BOTTOM| ",1);
break;
case BS_VCENTER:
string=AddString(string,"B S_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
I show you how i did this.
#define BS_TYPE_MASK2 0x00000080L
switch(style & BS_TYPE_MASK2)
{
case BS_TEXT:
string=AddString(string,"B
break;
case BS_ICON:
string=AddString(string,"B
break;
case BS_BITMAP:
string=AddString(string,"B
break;
}
#define BS_TYPE_MASK3 0x00000F00L
// Sleep(0);
switch(style & BS_TYPE_MASK3)
{
case BS_LEFT:
string=AddString(string,"B
break;
case BS_RIGHT:
string=AddString(string,"B
break;
case BS_CENTER:
string=AddString(string,"B
break;
case BS_TOP:
string=AddString(string,"B
break;
case BS_BOTTOM:
string=AddString(string,"B
break;
case BS_VCENTER:
string=AddString(string,"B
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...
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...
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
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
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;
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry i have forgotten about this.
Splitting points.
Yours sincerely
Andla
Splitting points.
Yours sincerely
Andla
DWORD dwStyle = GetWindowLong ( hWnd, GWL_STYLE);