I'm porting an old app to .NET, in there all the forms sizes are set in Dialog Units.
int w = --- from dialog definition
int h = --- from dialog definition
I tried to use such an approach
int dx = (double)(LOWORD(GetDialogBaseUnits())) / 4;
int dy = (double)(HIWORD(GetDialogBaseUnits())) / 8;
w *= dx;
h *= dy;
_form->ClientSize = Size::Size(w, h);
but .NET form becomes way larger than expected.
Then I tried to use
RECT rc = { _form->Location.Y, _form->Location.X, _form->Location.Y + w, _form->Location.X + h };
BOOL b = ::MapDialogRect((HWND)_form->Handle.ToInt32(), &rc);
char err[1024];
GetLastErrorText(GetLastError(), err, 1024);
inside the OnLoad
event, but I'm getting an error saying the window is not a valid dialog, and the rc
variable remains un-changed.
How to correctly transform DU inside a WinForms application?
Thx