Solved

Finding out if a style is applied to a window.

Posted on 2002-05-20
15
242 Views
Last Modified: 2013-12-03
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
0
Comment
Question by:andla
  • 8
  • 4
  • 2
15 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
"GetWindowLong()" gan be used like this, e.g.

DWORD dwStyle = GetWindowLong ( hWnd, GWL_STYLE);
0
 
LVL 1

Author Comment

by:andla
Comment Utility
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
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>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...
0
 
LVL 1

Author Comment

by:andla
Comment Utility
>>"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

0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>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...
0
 
LVL 1

Author Comment

by:andla
Comment Utility
I don't understand this...
0
 
LVL 1

Author Comment

by:andla
Comment Utility
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


0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 12

Expert Comment

by:pjknibbs
Comment Utility
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...
0
 
LVL 1

Author Comment

by:andla
Comment Utility
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
0
 
LVL 1

Author Comment

by:andla
Comment Utility
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;
     }
0
 
LVL 12

Assisted Solution

by:pjknibbs
pjknibbs earned 25 total points
Comment Utility
The reason I chose the selection there is because WS_POPUP and WS_CHILD are related styles, whereas WS_MINIMIZE and WS_VISIBLE aren't. If you just used 0x80000000L, then you'd only remove the WS_POPUP style bit, so if WS_CHILD happened to be set you could end up setting both WS_POPUP and WS_CHILD, which I don't think is a valid combination of style bits.
0
 
LVL 1

Author Comment

by:andla
Comment Utility
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
0
 
LVL 86

Accepted Solution

by:
jkr earned 25 total points
Comment Utility
feedback?
0
 
LVL 1

Author Comment

by:andla
Comment Utility
Sorry i have forgotten about this.

Splitting points.

Yours sincerely
Andla
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) 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…

763 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

12 Experts available now in Live!

Get 1:1 Help Now