Results 1 to 11 of 11

Thread: Converting Dialog Units into Pixels

Threaded View

  1. #1

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    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:
    1. Public Class DialogUnits
    2.  
    3.     Private Declare Function GetDialogBaseUnits Lib "user32" () As Integer
    4.  
    5.     Private _Width As Integer
    6.     Private _Height As Integer
    7.  
    8.     Public Sub New()
    9.         Call CalculateDialogUnits()
    10.     End Sub
    11.  
    12.     Public ReadOnly Property Width() As Integer
    13.         Get
    14.             Return _Width
    15.         End Get
    16.     End Property
    17.  
    18.     Public ReadOnly Property Height() As Integer
    19.         Get
    20.             Return _Height
    21.         End Get
    22.     End Property
    23.  
    24.     Public Function GetHeightInPixels(ByVal dialogUnits As Integer) As Integer
    25.         Return (_Height * dialogUnits) / 8
    26.     End Function
    27.  
    28.     Public Function GetWidthInPixels(ByVal dialogUnits As Integer) As Integer
    29.         Return (_Width * dialogUnits) / 4
    30.     End Function
    31.  
    32.     Public ReadOnly Property Size() As SizeF
    33.         Get
    34.             Return New SizeF(_Width, _Height)
    35.         End Get
    36.     End Property
    37.  
    38.     Private Sub CalculateDialogUnits()
    39.         Dim DialogUnits As Long = GetDialogBaseUnits
    40.  
    41.         _Width = LongManipulation.GetLoWord(DialogUnits)
    42.         _Height = LongManipulation.GetHiWord(DialogUnits)
    43.     End Sub
    44.  
    45. End Class
    And the LongManipulation class:
    VB Code:
    1. Public Class LongManipulation
    2.  
    3.     Public Shared Function GetLoWord(ByVal sourceLong As Long) As Integer
    4.         Return (sourceLong / &H10000) And &HFFFF&
    5.     End Function
    6.  
    7.     Public Shared Function GetHiWord(ByVal sourceLong As Long) As Integer
    8.         Return sourceLong And &HFFFF&
    9.     End Function
    10.  
    11.     Public Shared Function IntegersToLong(ByVal loWord As Integer, ByVal hiWord As Integer) As Long
    12.         Return (hiWord * &H10000) + (loWord And &HFFFF&)
    13.     End Function
    14.  
    15. 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
  •  



Click Here to Expand Forum to Full Width