Working with Microsoft Flags
Working with Microsoft Flags
Working with Microsoft Flags
Working with Microsoft Flags
Working with Microsoft Flags
Working with Microsoft Flags Working with Microsoft Flags Working with Microsoft Flags Working with Microsoft Flags Working with Microsoft Flags Working with Microsoft Flags Working with Microsoft Flags Working with Microsoft Flags
Working with Microsoft Flags Working with Microsoft Flags
Working with Microsoft Flags
Go Back  Xtreme Visual Basic Talk > > > Working with Microsoft Flags


Reply
 
Thread Tools Display Modes
  #1  
Old 09-18-2015, 08:40 AM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default Working with API Flags


I am trying to get this C++ line of code to work in VB6

Code:
if ((pt & typeBezier) == typeBezier)
I have the following, but it doesn't work
Code:
Option Explicit

Private Const PathPointTypeStart = 0             ' type = move
Private Const PathPointTypeLine = 1              ' type = line
Private Const PathPointTypeBezier = 3            ' type = Beizer
Private Const PathPointTypePathMarker = &H20     ' flag = marker
Private Const PathPointTypeCloseSubpath = &H80   ' flag = close

Private Sub Command1_Click()

    Dim pt As Byte
    
    
    ' 0            should yield Start  (0)
    ' 1, 129, 161  should yield Line   (1)
    ' 3, 131, 163  should yield Bezier (3)
    
    
    pt = 163


    If (pt And PathPointTypeStart) = PathPointTypeStart Then
        MsgBox "Start"
    ElseIf (pt And PathPointTypeLine) = PathPointTypeLine Then
        MsgBox "Line"
    ElseIf (pt And PathPointTypeBezier) = PathPointTypeBezier Then
        MsgBox "Bezier"
    End If

End Sub
Am I not understanding properly how these flags are meant to work?

Last edited by mms; 09-18-2015 at 10:16 AM.
Reply With Quote
  #2  
Old 09-18-2015, 11:08 PM
Cerian Knight's Avatar
Cerian KnightWorking with Microsoft Flags Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,193
Default

Without really understanding the intent of the code, all I can say is that when you have underlapping and overlapping flags (forgive the make-shift terminology), you have to carefully consider the order of evaluation:
Code:
    If pt = PathPointTypeStart Then 'underlap must be explicitly parsed, further masking seemingly not required due to no-conflict with high-nibble constants
        MsgBox "Start"
    ElseIf (pt And PathPointTypeBezier) = PathPointTypeBezier Then 'multi-bit overlap must be parsed before single-bit
        MsgBox "Bezier"
    ElseIf (pt And PathPointTypeLine) = PathPointTypeLine Then 'single-bit overlap must be parsed after multi-bit
        MsgBox "Line"
    End If
It is best if you express all values in hex when doing this so you can better visualize the bit position values.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').

Last edited by Cerian Knight; 09-18-2015 at 11:22 PM.
Reply With Quote
  #3  
Old 09-19-2015, 07:11 AM
dilettante's Avatar
dilettanteWorking with Microsoft Flags dilettante is offline
Underclocked lifestyle

Forum Leader
* Guru *
 
Join Date: Feb 2005
Location: Michigan, USA
Posts: 4,524
Default

PathPointType is an enum anyway, not a bunch of unrelated constants.

If you look in the SDK (GdiPlusEnums.h) you'll see that the lower 3 bits are used for values and only the next 5 bits above those are flags.

PathPointTypePathTypeMask is to be used to extract the "type" subfield for comparison against the value members PathPointTypeStart, PathPointTypeLine, and PathPointTypeBezier/PathPointTypeBezier3.
Reply With Quote
  #4  
Old 09-19-2015, 10:08 AM
passel's Avatar
passelWorking with Microsoft Flags passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

if ((pt & typeBezier) == typeBezier)

If that is the C++ code, it would seem technically inappropriate.
Since the lower bits are an enumeration, it should have been a comparison to a masked off value, as dilettante said.
The way the C++ code could work, is by doing that check before the line check, as Cerian Knight pointed out.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #5  
Old 09-19-2015, 08:51 PM
Cerian Knight's Avatar
Cerian KnightWorking with Microsoft Flags Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,193
Default

Quote:
Originally Posted by dilettante View Post
If you look in the SDK (GdiPlusEnums.h) you'll see that the lower 3 bits are used for values...
So something like this might be more accurate:
Code:
Select Case pt And 7 'mask to leave lower 3 bits
    Case PathPointTypeStart
        MsgBox "Start"
    Case PathPointTypeLine
        MsgBox "Line"
    Case PathPointTypeBezier
        MsgBox "Bezier"
End Select
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #6  
Old 09-21-2015, 07:08 AM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,859
Default

This was the total C++ block, so I guess that is what you guys were talking about (ie ORDER of compare)
Code:
        if (pt == typeStart)
        {
            //
        }
        else
        {
            if ((pt & typeBezier) == typeBezier)
            {
                 //
            }
            else if ((pt & typeLine) == typeLine)
            {
                //
            }
        }
Cerian Knight
I like it!! Thank you.

Now I understand the mask
Code:
Private Const PathPointTypePathTypeMask = &H7            ' mask all bits except 3 low-order bits

Select Case pt And PathPointTypePathTypeMask
    Case PathPointTypeStart
        MsgBox "Start"
    Case PathPointTypeLine
        MsgBox "Line"
    Case PathPointTypeBezier
        MsgBox "Bezier"
End Select
Reply With Quote
Reply

Tags
private, const, line, type, pathpointtypestart, msgbox, yield, pathpointtypebezier, pathpointtypeline, bezier, start, flag, elseif, flags, typebezier, byte, meant, command1_click, dim, understanding, microsoft, properly, pathpointtypeclosesubpath, option, explicit


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Working with Microsoft Flags
Working with Microsoft Flags
Working with Microsoft Flags Working with Microsoft Flags
Working with Microsoft Flags
Working with Microsoft Flags
Working with Microsoft Flags Working with Microsoft Flags Working with Microsoft Flags Working with Microsoft Flags Working with Microsoft Flags Working with Microsoft Flags Working with Microsoft Flags
Working with Microsoft Flags
Working with Microsoft Flags
 
Working with Microsoft Flags
Working with Microsoft Flags
 
-->