|
-
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)
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
|