Announcement

Collapse
No announcement yet.

VB Cordinates to Dialog Units

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Gregery D Engle
    replied
    Thanks Scott

    ------------------
    -Greg

    Leave a comment:


  • Scott Hauser
    replied
    Greg,
    I posted a little vb to ddt conversion utility a while back. It includes
    source and samples. There are some problems with this utility (explained in the readme)
    feel free to use it and tweak it in any way you choose. I still use it for quick and dirty
    dialog building.

    http://www.powerbasic.com/files/pub/pbwin/vb/

    ------------------

    Leave a comment:


  • Gregery D Engle
    replied
    Edwin,

    I'm actually trying to make my own Visual Basic frm to DDT
    conversion tool. Just for a learning experience I guess.


    ------------------
    -Greg

    Leave a comment:


  • Edwin Knoppert
    replied
    The FreeDDT tool on my site does this conversion too.
    Take a look in the generated code..


    ------------------
    [email protected]

    Leave a comment:


  • Semen Matusovski
    replied
    Greg --
    Let's strictly divide following questions
    1) How to convert twips to pixels
    2) How to convert pixels to dialog units
    3) How Dialog New and Dialog Set Size work.

    About first. Let's make in VB6 empty form and run following.

    Code:
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    
    Private Const LOGPIXELSX = 88        '  Logical pixels/inch in X
    Private Const LOGPIXELSY = 90        '  Logical pixels/inch in Y
    
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Declare Function CreateIC Lib "gdi32" Alias "CreateICA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal NotUsedHere As Long) As Long
    Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
    Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    
    Private Sub Form_Load()
      Me.Height = 3600
      Me.Width = 4800
    End Sub
    
    
    Private Sub Form_Activate()
       Dim rc As RECT
       Dim hdc As Long
       
       hdc = CreateIC("DISPLAY", ByVal 0&, ByVal 0&, ByVal 0&)
       
       GetWindowRect Me.hwnd, rc
       MsgBox 1440 * (rc.Right - rc.Left) / GetDeviceCaps(hdc, LOGPIXELSX), , Me.Width
       MsgBox 1440 * (rc.Bottom - rc.Top) / GetDeviceCaps(hdc, LOGPIXELSY), , Me.Height
       
       DeleteDC hdc
    End Sub
    In my understanding this means:
    a) formula is correct
    b) Width/Height in VB (at least for form) are sizes of window area (not of a client area).

    About second questions.
    I have no idea, how PB converts pixels to units.
    Probably is used MapDialogRect with reverse re-calculation.
    Here it's possible to expect losing accuracy.

    Dialog New ...
    As Lance mentioned somehow, if there is %WS_CAPTION in DIALOG NEW, DDT accepts that sizes relate to client area.
    Otherwise - to window.

    Dialog Set Size...
    From your sample, it looks that Dialog Set Size thinks about window coordinates, unlike %WS_CAPTION.
    And this explains different results of Test1/Test2.




    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Gregery D Engle
    replied
    Eric & Semen,

    Code:
    #COMPILE EXE
    #REGISTER NONE
    #INCLUDE "Win32Api.Inc"
    GLOBAL gExit AS LONG
    
    SUB TwipsToUnits (hDlg AS LONG, BYVAL x AS LONG, BYVAL y AS LONG, xx AS LONG, yy AS LONG)
          DIM hDC AS LONG
          hDC = CreateIC ("DISPLAY", BYVAL 0&, BYVAL 0&, BYVAL 0&)
          DIALOG PIXELS hDlg, x * GetDeviceCaps(hDC, %LOGPIXELSX) / 1440, _
                              y * GetDeviceCaps(hDC, %LOGPIXELSY) / 1440 TO UNITS xx, yy
          DeleteDc hDC
    END SUB
    
    CALLBACK FUNCTION Form1_DLGPROC
        SELECT CASE CBMSG
             CASE %WM_DESTROY
                  gExit = 1
        END SELECT
    END FUNCTION
    
    CALLBACK FUNCTION Form2_DLGPROC
        SELECT CASE CBMSG
             CASE %WM_DESTROY
                  gExit = 1
        END SELECT
    END FUNCTION
    
    SUB Test1()
        LOCAL hDlg AS LONG, xx AS LONG, yy AS LONG
          DIALOG NEW 0, "", , , 0, 0, %WS_CAPTION OR %WS_THICKFRAME OR _
             %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX TO hDlg
          TwipsToUnits hDlg, 2925, 5460, xx, yy
          DIALOG SET SIZE hDlg, xx, yy
          'SetWindowText hDlg, "Test1 - Units: " + STR$(xx) + STR$(yy)
          DIALOG SHOW MODELESS hDlg CALL Form1_DLGPROC
        DIALOG GET SIZE hDlg TO x&, y&
        SetWindowText hDlg, "Test1 - Units: " + STR$(x&) + STR$(y&)   
    
    END SUB
    
    SUB test2()
       LOCAL hDlg AS LONG, xx AS LONG, yy AS LONG
          DIALOG NEW 0, "", , , 0, 0, %WS_CAPTION OR %WS_THICKFRAME OR _
             %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX TO hDlg
          TwipsToUnits hDlg, 2925, 5460, xx, yy
         DIALOG END hDlg
          DIALOG NEW 0, "", , , xx, yy, %WS_CAPTION OR %WS_THICKFRAME OR _
             %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX TO hDlg
        'SetWindowText hDlg, "Test2 - Units: " + STR$(xx) + STR$(yy)
        DIALOG SHOW MODELESS hDlg CALL Form2_DLGPROC
        DIALOG GET SIZE hDlg TO x&, y&
        SetWindowText hDlg, "Test2 - Units: " + STR$(x&) + STR$(y&)   
    END SUB
    
    FUNCTION PBMAIN() AS LONG
    test1
    test2
    DO WHILE NOT gExit = 1
       DIALOG DOEVENTS
    LOOP
    END FUNCTION
    look at both dialogs, test2 is bigger then test1, the only difference
    is that I call DIALOG SET SIZE hDlg, xx, yy in test1.

    Is this what you are talking about Eric?


    ------------------
    -Greg

    [This message has been edited by Gregery D Engle (edited December 11, 2000).]

    Leave a comment:


  • Eric Pearson
    replied
    I haven't looked closely at this, but I agree with Joe... Those number look to me like one set is based on 0,0 at the top-left corner of the dialog, and the other is based on the top-left corner of the client area of the dialog.

    -- Eric

    ------------------
    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]</A>

    Leave a comment:


  • Semen Matusovski
    replied
    Greg --
    Take empty form in VB and run
    Code:
    Private Sub Form_Load()
       Me.ScaleWidth = 4800
       Me.ScaleHeight = 3600
    End Sub
    In PB
    Code:
       #Compile Exe
       #Register None
       #Include "Win32Api.Inc"
    
       Sub TwipsToUnits (hDlg As Long, ByVal x As Long, ByVal y As Long, xx As Long, yy As Long)
          Dim hDC As Long
          hDC = CreateIC ("DISPLAY", ByVal 0&, ByVal 0&, ByVal 0&)
          Dialog Pixels hDlg, x * GetDeviceCaps(hDC, %LOGPIXELSX) / 1440, _
                              y * GetDeviceCaps(hDC, %LOGPIXELSY) / 1440 To Units xx, yy
          DeleteDc hDC
       End Sub
    
       Function PbMain
          Local hDlg As Long, xx As Long, yy As Long
          Dialog New 0, "", , , 0, 0, %WS_CAPTION Or %WS_THICKFRAME Or _
             %WS_SYSMENU Or %WS_MINIMIZEBOX Or %WS_MAXIMIZEBOX To hDlg
          TwipsToUnits hDlg, 4800, 3600, xx, yy
          Dialog Set Size hDlg, xx, yy
          SetWindowText hDlg, "Units: " + Str$(xx) + Str$(yy)
          Dialog Show Modal hDlg
       End Function
    and visually compare two forms.
    On my PC I see a small (very small) difference (VB is a little BIGGER).

    99% sure that this is a result of VB & DDT conversions.
    As I understand, in natural API there are no functions "Set the size of client area" and "Convert pixels to units". It's necessary to use combinations of some functions and here could be different rounding.

    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Gregery D Engle
    replied
    I'm confused on why the Visual Studio import works perfectly.

    There has to be a formula that is as accurate, any suggestions?

    ------------------
    -Greg

    Leave a comment:


  • Joseph W Murphy
    replied
    208 to 213 looks like a rounding problem
    131 to 148 could be caption height ?

    just guessing

    Joe Murphy

    ------------------

    Leave a comment:


  • Gregery D Engle
    replied
    Semen,

    I don't see how that works. Running your code with these twip
    values: 4800, 3600 I get: 213, 148

    If I import that frm into a resource dialog in Visual Studio
    6.0 I get this:

    Code:
    IDD_DIALOG1 DIALOG DISCARDABLE  0, 0, 208, 131
    STYLE WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_SYSMENU
    CAPTION "Form1"
    FONT 8, "MS Sans Serif"
    BEGIN
    END
    I have lined up the Visual Studio import and my original VB form
    and everything lines up so the number 208,131 is correct.

    Why can't I get it with your code? Am I doing something wrong?

    Thanks


    ------------------
    -Greg

    Leave a comment:


  • Semen Matusovski
    replied
    Greg --
    As I understand, 1 twip = 1/20 of a point, or 1/1440 of an inch.
    From another side, for a screen hDC
    1 inch = GetDeviceCaps(hDC, %LOGPIXELSX) pixels (horz) or
    1 inch = GetDeviceCaps(hDC, %LOGPIXELSY) pixels (vert).

    This means that to translate (x, y) in twips to (xx, yy) in units:
    Code:
       Sub TwipsToUnits (hDlg As Long, ByVal x As Long, ByVal y As Long, xx As Long, yy As Long)
          Dim hDC As Long
          hDC = CreateIC ("DISPLAY", ByVal 0&, ByVal 0&, ByVal 0&)
          Dialog Pixels hDlg, x * GetDeviceCaps(hDC, %LOGPIXELSX) / 1440, _
                              y * GetDeviceCaps(hDC, %LOGPIXELSY) / 1440 To Units xx, yy
          DeleteDc hDC
       End Sub
    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Gregery D Engle
    started a topic VB Cordinates to Dialog Units

    VB Cordinates to Dialog Units

    How would I translate VB Form Cordinates (I believe twips) to
    Dialog Units, eg:

    FORM1

    Height = 3195
    Left = 60
    Top = 345
    Width = 4680

    ---
    TEXTBOX

    Height = 495
    LEFT = 120
    Top = 1200
    Width = 1455

    How do I translate the above numbers to dialog units?

    Thanks

    ------------------
    -Greg
Working...
X