Jump to content
  • Advertisement
Sign in to follow this  
GetWindowRect

[RESOLVED] Check for Window Styles

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I tried searching the forums first, but it is temprorily disabled, so sorry if this is a re-post to the same question. Is there a way to check if a window contains a certain style with GetWindowLong? I searched VBForums.com and someone posted this code
if(GetWindowLong(lst,GWL_STYLE) & LBS_SORT)


but it always returns true, whether it is in or not, it does not look right to me at all, but it was worth a shot. I would like to run a function a different way if a style is present as opposed to if it is not. Any help is appreciated. Thanks. [Edited by - GetWindowRect on July 26, 2005 5:20:52 PM]

Share this post


Link to post
Share on other sites
Advertisement
The "GetWindowLong" function will return the 32-bit value that is requested. It will only return 0, or false, if an error has occured.

I would assume, I have not utilized the function before, that you would take the returned value and compare it, say in a switch statement, to the available styles that you can have such as WS_BORDER, WS_CAPTION, WS_ICONIC, and so on.

Edit: Why is there an evaluation of LBS_SORT?

Share this post


Link to post
Share on other sites
LBS_SORT is what I would like to check for, and as you say by using a switch statement how would that work? I am sure case LBS_SORT: would never be correct since it is always a mix of a bunch of styles? Would I have to do a check with all the style possibilities I use?

Share this post


Link to post
Share on other sites
Then I guess it should work from looking at this.

I got confused by the & for Bitwise And.

0x00FF = 0000000011111111
0xFF00 = 1111111100000000
For the bitwise operation, the two operands have no "1" bits in the same positions.
Therefore, bit by bit yields zero bits.
Look at the binary representation of each operand and observe that there is no overlap of "1" bits.

I am not familiar with this. Sorry.

I guess since its return value is 32 bits, it will have each bit representing a particular window style state. You are testing, from what I have read, if any of those bits match. A match in any bits or more will result in true.

Share this post


Link to post
Share on other sites
Yes, that code should work.

Not sure why it wouldn't unless there's a typo or something somewhere else in the code. Make sure you're not doing something like:


if(GetWindowLong(lst,GWL_STYLE) & LBS_SORT);
{
}



and that you're using the correct window handle etc.

Share this post


Link to post
Share on other sites
The exact code I am using is

if(GetWindowLong(lst,GWL_STYLE) & LBS_SORT)
SetWindowText(GetParent(lst), "Sorted");
else
SetWindowText(GetParent(lst), "NOT Sorted");

return;



It seems to actually work now, I am not sure what I changed since this time and the last time I tried. Either way it works now, it most likely was a simple syntax error that I screwed up. Thank you both for all your help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!