May 10, 2024, 01:25:57 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Dlg to Pixel conversions

Started by LarryMc, November 17, 2010, 10:31:37 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

The following is based upon a sub I found in the old forum CD.

I'm wanting to take the l,t,w,h values given in a resource dialog (dialog units) and covert the values to pixels.

This gives me the wrong results (bigger than expected)
Anyone tell me what's wrong?
SUB Dlg2Pix(PixX:INT BYREF,PixY:INT BYREF,DlgUnitX:INT ,DlgUnitY:INT)
  int bu=GetDialogBaseUnits()
  PixX = (DlgUnitX * (bu & 0xFFFF))/4
  PixY =(DlgUnitY *((bu >> 16) & 0xFFFF))/8   
  RETURN   
ENDSUB


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

ZeroDog

GetDialogBaseUnits returns the dialog base units for dialog boxes that use the default system font.

Use MapDialogRect instead.

LarryMc

Quote from: ZeroDog on November 17, 2010, 12:18:30 PM
Use MapDialogRect instead.
Is it safe to assume that the proper way to use MapDialogRect is to create the dialog, then in initdialog set the font followed by
MapDialogRect and a setsize?

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

ZeroDog

I believe that is how it is intended to be used.  Further info from MSDN:

MapDialogRect Function
Converts the specified dialog box units to screen units (pixels). The function replaces the coordinates in the specified RECT structure with the converted coordinates, which allows the structure to be used to create a dialog box or position a control within a dialog box.

Syntax
Quote
BOOL WINAPI MapDialogRect(
  __in     HWND hDlg,
  __inout  LPRECT lpRect
);

Parameters
hDlg [in]
HWND
A handle to a dialog box. This function accepts only handles returned by one of the dialog box creation functions; handles for other windows are not valid.

lpRect [in, out]
LPRECT
A pointer to a RECT structure that contains the dialog box coordinates to be converted.

Return Value
BOOL

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
The MapDialogRect function assumes that the initial coordinates in the RECT structure represent dialog box units. To convert these coordinates from dialog box units to pixels, the function retrieves the current horizontal and vertical base units for the dialog box, then applies the following formulas:

left   = MulDiv(left,   baseunitX, 4 );
right  = MulDiv(right,  baseunitX, 4 );
top    = MulDiv(top,    baseunitY, 8 );
bottom = MulDiv(bottom, baseunitY, 8 );
If the dialog box template has the DS_SETFONT or DS_SHELLFONT style, the base units are the average width and height, in pixels, of the characters in the font specified by the template.

LarryMc

I didn't get it to work (return the proper pixel size) so I bailed on that.

I'm going to leave the dialog in the resource file (means I don't have to convert anything) and load it directly into my app.  That way the windows apis take care of everything for me without me having to do anything.
Seems I was making it more complex than it needed to be.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library