|
-
Aug 30th, 2009, 10:08 AM
#1
Is my bitwise operation correct?
i want to identify windows which fully or partially trasnparent. so i check those windows against WS_EX_LAYERED bit. i want to make sure below bitwise operation is correct.
Code:
Public Function isTrans(qhwnd As Long) As Boolean
Dim tmp As Long
tmp = GetWindowLong(qhwnd, GWL_EXSTYLE)
If tmp And WS_EX_TRANSPARENT Then
isTrans = True ' yes it is
Else
isTrans = False ' no its not
End If
End Function
is this correct? can i identify windows such as shown below using this code?
Last edited by Fazi; Aug 30th, 2009 at 10:36 AM.
-
Aug 30th, 2009, 10:35 AM
#2
Re: Is my bitwise operation correct?
You shouldn't have any problems with what you posted. That check does not indicate if the window is partially transparent or not, it simply means the style is applied and the window could be transparent and could also be 100% opaque. Shaped windows will use that style even though they have no intention of being partially/fully transparent.
However, when using AND, AND NOT, I find it better to use grouping parentheses to avoid potential of VB miscalculating; especially, if you have more than one calculation in the formula:
If (tmp And (WS_EX_TRANSPARENT Or WS_EX_WINDOWEDGE))
Recommend when testing for a specific style, always do explicit comparisons
If ((tmp And WS_EX_TRANSPARENT) = WS_EX_TRANSPARENT)
By using explicit comparisions, you avoid the problem when a style is not a power of two. Button properties are an example of such a thing: BS_OWNERDRAW = 11
-
Aug 30th, 2009, 10:47 AM
#3
-
Aug 30th, 2009, 10:53 AM
#4
Re: Is my bitwise operation correct?
There are 2 ways to get that effect:
1. Using layered windows
2. Using window regions. Which is what that is probably using.
Can you tell us why you need to know if a window is shaped or not? You cannot determine that by simply looking at style bits. If window regions are used, you can determine it by comparing the window region against a rectangular window region of the window's size and see if they are equal: EqualRgn API. But that will return false positives since every XP themed window, I believe, is using window regions to round the top left/right window corners. Therefore, knowing if a window is shaped due to themes or not, may not be 100% possible. Knowing if a window is partially transparent or not by checking the style bits is not possible.
-
Aug 30th, 2009, 11:06 AM
#5
Re: Is my bitwise operation correct?
Last edited by Fazi; Aug 30th, 2009 at 11:11 AM.
-
Aug 30th, 2009, 11:13 AM
#6
Re: Is my bitwise operation correct?
There are some really odd shaped windows about. You may have trouble placing the woodpecker on all possible shapes. The right edge is an arc in your example, it could be a point if the window looked something like: <___>
Just some thoughts...
You can get the window region, if one is used and you can paint the region to a DC. With layered windows you can bitblt the widow to a dc and use a mask to determine its shape if not rectangular. Once you can determine the shape, I think you'd have to use a lot of trig to locate/calculate a line to place your woodpecker on. That line may be rotated at any angle, which means the woodpecker may have to be rotated too.
-
Aug 30th, 2009, 11:21 AM
#7
Re: Is my bitwise operation correct?
 Originally Posted by LaVolpe
There are some really odd shaped windows about. You may have trouble placing the woodpecker on all possible shapes. The right edge is an arc in your example, it could be a point if the window looked something like: <___>
Just some thoughts...
You can get the window region, if one is used and you can paint the region to a DC. With layered windows you can bitblt the widow to a dc and use a mask to determine its shape if not rectangular. Once you can determine the shape, I think you'd have to use a lot of trig to locate/calculate a line to place your woodpecker on. That line may be rotated at any angle, which means the woodpecker may have to be rotated too.
for now i really dont want to place the wood on shaped window shown like above at all. so i will tyr your bitblt suggession to determine a windows right edge is rect or arc. that i think worth a try
-
Aug 30th, 2009, 11:28 AM
#8
Re: Is my bitwise operation correct?
another problem also there even with the fully rectangular shaped windows.
for excample window7 start menu. unlike in xp, it has a diffrent rect that has a big offset from the actual right edge.
-
Aug 30th, 2009, 11:55 AM
#9
Re: Is my bitwise operation correct?
I don't have access to Win7. I suspect that the start menu is using layered windows and the extended rect is fully transparent. When a menu is selected the window is refreshed and the rect is filled in.
Even if your woodpecker could align itself on the smaller rect, when user selects a menu, your woodpecker wouldn't know to jump to the far right. Complicates your logic quite a bit.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|