|
-
Apr 14th, 2005, 01:43 AM
#1
Thread Starter
Frenzied Member
Converting Dialog Units into Pixels
I've been trying to convert the measurements for Wizards from the Wizard97 specification into pixels for god knows how long now and I can't ever seem to get it to look right at all.
If you see this page on Welcome and Completion Page Layouts, all the measurements are in Dialog Units for some special reason I can't recall at this point in time.
Anyway, after spending a while looking for the stuff todo it, I found the GetDialogBaseUnits() function, made a little wrapper for it and when I try to align the controls on my form to the measurements provided by the specification, they are nowhere near them.
Here's my attempt at wrapping the API up:
VB Code:
Public Class DialogUnits
Private Declare Function GetDialogBaseUnits Lib "user32" () As Integer
Private _Width As Integer
Private _Height As Integer
Public Sub New()
Call CalculateDialogUnits()
End Sub
Public ReadOnly Property Width() As Integer
Get
Return _Width
End Get
End Property
Public ReadOnly Property Height() As Integer
Get
Return _Height
End Get
End Property
Public Function GetHeightInPixels(ByVal dialogUnits As Integer) As Integer
Return (_Height * dialogUnits) / 8
End Function
Public Function GetWidthInPixels(ByVal dialogUnits As Integer) As Integer
Return (_Width * dialogUnits) / 4
End Function
Public ReadOnly Property Size() As SizeF
Get
Return New SizeF(_Width, _Height)
End Get
End Property
Private Sub CalculateDialogUnits()
Dim DialogUnits As Long = GetDialogBaseUnits
_Width = LongManipulation.GetLoWord(DialogUnits)
_Height = LongManipulation.GetHiWord(DialogUnits)
End Sub
End Class
And the LongManipulation class:
VB Code:
Public Class LongManipulation
Public Shared Function GetLoWord(ByVal sourceLong As Long) As Integer
Return (sourceLong / &H10000) And &HFFFF&
End Function
Public Shared Function GetHiWord(ByVal sourceLong As Long) As Integer
Return sourceLong And &HFFFF&
End Function
Public Shared Function IntegersToLong(ByVal loWord As Integer, ByVal hiWord As Integer) As Long
Return (hiWord * &H10000) + (loWord And &HFFFF&)
End Function
End Class
Can someone please show me where I'm going wrong because I got no idea what I'm doing wrong. It seems to be logically correct, but something's a miss.
Last edited by Ideas Man; Apr 14th, 2005 at 01:46 AM.
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
Apr 14th, 2005, 02:54 AM
#2
Re: Converting Dialog Units into Pixels
I don't live here any more.
-
Apr 14th, 2005, 02:59 AM
#3
Re: Converting Dialog Units into Pixels
VB Code:
Public Class LongManipulation
Public Shared Function GetLoWord(ByVal sourceLong As Long) As Integer
Return CType(sourceLong And &HFFFF&, Integer)
End Function
Public Shared Function GetHiWord(ByVal sourceLong As Long) As Integer
Return CType((sourceLong >> 16) And &HFFFF&, Integer)
End Function
Public Shared Function IntegersToLong(ByVal loWord As Integer, ByVal hiWord As Integer) As Long
Return (hiWord << 16) Or loWord
End Function
End Class
Last edited by wossname; Apr 14th, 2005 at 03:07 AM.
I don't live here any more.
-
Apr 14th, 2005, 03:03 AM
#4
Thread Starter
Frenzied Member
Re: Converting Dialog Units into Pixels
... that doesn't exactly help me . I'm not worried about the IntegersToLong function, that was just something that was tagged on when I found that code, and the KB article didn't help all too much sorry.
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
Apr 14th, 2005, 03:08 AM
#5
Re: Converting Dialog Units into Pixels
I revised my code again, try it now.
I don't live here any more.
-
Apr 14th, 2005, 03:21 AM
#6
Thread Starter
Frenzied Member
Re: Converting Dialog Units into Pixels
No, doesn't seem to.
Have a go, put a label on the form and use my functions to try and place it as they have it on the form.
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
Apr 14th, 2005, 03:20 AM
#7
Re: Converting Dialog Units into Pixels
 Originally Posted by Ideas Man
I'm not worried about the IntegersToLong function
Perhaps you should be.
You just don't do binary operations with division and multiplication operators. Especially when extracting words.
Use bitshift operators (<<, >>) instead.
If you use divide instead of >> then you will get incorrect results because the low byte is included in the operation, >> 16 ignores the low byte.
That whole LongManipulation class looked a bit suspect if you ask me.
I don't live here any more.
-
Apr 14th, 2005, 03:26 AM
#8
Thread Starter
Frenzied Member
Re: Converting Dialog Units into Pixels
 Originally Posted by wossname
Perhaps you should be.
You just don't do binary operations with division and multiplication operators. Especially when extracting words.
Use bitshift operators (<<, >>) instead.
If you use divide instead of >> then you will get incorrect results because the low byte is included in the operation, >> 16 ignores the low byte.
That whole LongManipulation class looked a bit suspect if you ask me.
Well, I didn't supply the code for it, so I don't know how it works, it just "seemed" to work.
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
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
|