News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Convert units from resource files to pixels?

Started by xanatose, May 24, 2013, 03:51:57 PM

Previous topic - Next topic

xanatose

On Resource files (.rc)
What units does dialogs, and controls use for the x,y,with,height? How do I convert them to pixel units?

jj2007


dedndave

lol
set them to 0 and let WM_SIZE take care of it   :biggrin:

MichaelW

This example shows how it works, and a detail that the documentation does not make clear.

I needed 2 dialogs, and since I didn't take the time to use modeless dialogs, to see the output for the second dialog you must close the first dialog.

#include "\masm32\include\resource.h"
#define IDD_DLG0 1000
#define IDD_DLG1 1001
IDD_DLG0 DIALOGEX 0,0,100,100
CAPTION "System font"
STYLE WS_OVERLAPPED | WS_SYSMENU | DS_CENTER
BEGIN
END
IDD_DLG1 DIALOGEX 0,0,100,100
CAPTION "User font"
FONT 12,"Wingdings",400,0,0
STYLE WS_OVERLAPPED | WS_SYSMENU | DS_CENTER
BEGIN
END


;==============================================================================
; Build as a console app.
;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================
IDD_DLG0 equ 1000
IDD_DLG1 equ 1001
;==============================================================================
    .data
      hInstance dd 0
      rc        RECT <>
    .code
;==============================================================================

DialogProc proc hwndDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    SWITCH uMsg

        CASE WM_INITDIALOG

            ;--------------------------------
            ; IDD_DLG1 DIALOGEX 0,0,100,100
            ;--------------------------------

            printf("GetWindowRect:\n")
            invoke GetWindowRect, hwndDlg, ADDR rc
            printf("%d\t%d\t%d\t%d\n", rc.left,rc.top,rc.right,rc.bottom)
            mov eax, rc.right
            sub eax, rc.left
            printf("%d\t", eax)
            mov eax, rc.bottom
            sub eax, rc.top
            printf("%d\n\n", eax)

            printf("GetClientRect:\n")
            invoke GetClientRect, hwndDlg, ADDR rc
            printf("%d\t%d\t%d\t%d\n", rc.left,rc.top,rc.right,rc.bottom)
            mov eax, rc.right
            sub eax, rc.left
            printf("%d\t", eax)
            mov eax, rc.bottom
            sub eax, rc.top
            printf("%d\n\n", eax)

            printf("GetDialogBaseUnits:\n")
            invoke GetDialogBaseUnits
            push eax
            movzx eax, ax
            invoke MulDiv, 100, eax, 4
            printf("%d\t", eax)
            pop eax
            shr eax, 16
            invoke MulDiv, 100, eax, 8
            printf("%d\n\n", eax)

            printf("MapDialogRect:\n")
            invoke SetRect, ADDR rc, 0, 0, 100, 100
            invoke MapDialogRect, hwndDlg, ADDR rc
            printf("%d\t%d\t%d\t%d\n", rc.left,rc.top,rc.right,rc.bottom)
            mov eax, rc.right
            sub eax, rc.left
            printf("%d\t", eax)
            mov eax, rc.bottom
            sub eax, rc.top
            printf("%d\n\n\n\n", eax)

        CASE WM_COMMAND

            SWITCH wParam

                CASE IDCANCEL

                    invoke EndDialog, hwndDlg, 0

            ENDSW

        CASE WM_CLOSE

            invoke EndDialog, hwndDlg, 0

    ENDSW

    xor   eax, eax
    ret

DialogProc endp

;==============================================================================
start:
;==============================================================================

    invoke GetModuleHandle, NULL
    mov   hInstance, eax
    invoke DialogBoxParam, hInstance, IDD_DLG0, NULL, ADDR DialogProc, 0
    invoke DialogBoxParam, hInstance, IDD_DLG1, NULL, ADDR DialogProc, 0

    exit
;==============================================================================
end start


GetWindowRect:
512     368     768     656
256     288

GetClientRect:
0       0       250     250
250     250

GetDialogBaseUnits:
250     250

MapDialogRect:
0       0       250     250
250     250



GetWindowRect:
424     355     855     668
431     313

GetClientRect:
0       0       425     275
425     275

GetDialogBaseUnits:
250     250

MapDialogRect:
0       0       425     275
425     275

Well Microsoft, here's another nice mess you've gotten us into.

TouEnMasm

Fa is a musical note to play with CL

TouEnMasm


Am I right doing this ?.
I have dialog box coordinate,i want to get pixel coordinate .
I create an invisible dialog box.
I put the dialog coordinate in a rect.
I use the "MapDialogRect" function  on this rect and I get pixel coordinate ?.

Fa is a musical note to play with CL

MichaelW

#6
This test did not work out as I expected, and I can't see the problem.

;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================
    .data
      hInstance dd 0
    .code
;==============================================================================

DialogProc proc uses ebx hwndDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    LOCAL rc:RECT
    LOCAL ps:PAINTSTRUCT

    SWITCH uMsg

        CASE WM_PAINT

            invoke BeginPaint, hwndDlg, ADDR ps

            mov rc.left, 0
            mov rc.top, 0
            invoke MapDialogRect, hwndDlg, ADDR rc
            invoke MoveToEx, ps.hdc, rc.left, rc.top, NULL

            mov rc.left, 49
            mov rc.top, 49
            invoke MapDialogRect, hwndDlg, ADDR rc
            invoke LineTo, ps.hdc, rc.left, rc.top

            mov rc.left, 99
            mov rc.top, 0
            invoke MapDialogRect, hwndDlg, ADDR rc
            invoke MoveToEx, ps.hdc, rc.left, rc.top, NULL

            mov rc.left, 49
            mov rc.top, 49
            invoke MapDialogRect, hwndDlg, ADDR rc
            invoke LineTo, ps.hdc, rc.left, rc.top

            invoke EndPaint, hwndDlg, ADDR ps

        CASE WM_COMMAND

            SWITCH wParam

                CASE IDCANCEL

                    invoke EndDialog, hwndDlg, 0

            ENDSW

        CASE WM_CLOSE

            invoke EndDialog, hwndDlg, 0

    ENDSW

    xor   eax, eax
    ret

DialogProc endp

;==============================================================================
start:
;==============================================================================

    invoke GetModuleHandle, NULL
    mov   hInstance, eax

    Dialog "Test", \
           "MS Sans Serif",10, \
           WS_OVERLAPPED or WS_SYSMENU or DS_CENTER, \
           0,0,0,100,100,1024

    CallModalDialog hInstance,0,DialogProc,NULL

    exit
;==============================================================================
end start


Well Microsoft, here's another nice mess you've gotten us into.

TouEnMasm

I get also bad results with MapDialogRect.
I don't get correct results in pixels.
Other soluce,a coefficient.
xdialog * 1,5 = pixels X
ydialog * 1,73 = pixels Y

it's on a screen of 800 by 600
Fa is a musical note to play with CL

TouEnMasm


here is a sample showing a dialog box and is translate in sdi.
xdialog * 1,5 = pixels X
ydialog * 1,8 = pixels Y

Fa is a musical note to play with CL

TouEnMasm


The MapDialogRect give correct results if the dialog (invisible) used to made the translate had the same font as the dialog being translated.
A dialog box change his coordinate with the font.


Fa is a musical note to play with CL

dedndave

so, maybe if you use GetDialogBaseUnits or MapDialogRect, with GetTextExtentPoint32

TouEnMasm


I get perfect results for all the controls inside the window.
There is just the window itself wich size is given as follow after used of the MapDialogRect function.
x position ,OK
y position OK
width = max.x + min.x
heigt = max.y + 2*min.y

   FRECT   STRUCT
      min POINT <>
      max POINT <>
   FRECT ENDS
Fa is a musical note to play with CL