Solved

Finding out if a style is applied to a window.

Posted on 2002-05-20
15
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
  • 2
15 Comments
 
LVL 86

Expert Comment

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

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

Author Comment

by:andla
ID: 7022137
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
ID: 7022147
>>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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 1

Author Comment

by:andla
ID: 7022180
>>"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
ID: 7022193
>>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
ID: 7022233
I don't understand this...
0
 
LVL 1

Author Comment

by:andla
ID: 7022556
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
 
LVL 12

Expert Comment

by:pjknibbs
ID: 7023679
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
ID: 7024692
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
ID: 7024718
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
ID: 7026132
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
ID: 7026435
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
ID: 10668329
feedback?
0
 
LVL 1

Author Comment

by:andla
ID: 10670493
Sorry i have forgotten about this.

Splitting points.

Yours sincerely
Andla
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared 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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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