if dialog box size in resource script file is set to 300X250 how can you set 2 integers x, y to be x=150, y = 125. can you please show me a simple example code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
but everything i tried to be able to place controls on dialog box were wrong locations, so i used mapdialogrect. and when i took the rect sides as reference, somehow all the rect sides were 0. and when i used getdialogbaseunits, i was still not able to put controls at right locations. all the searchs i did on the net didn't fix my problem. so i had to post this thread.
when i use these calculations, somehow either i am too off, and don't see the control, or it's never at the right location. my dialog font is set at 8.
now i'm asking how can i be able to put controls created by CreateWindow function at right locations.
thanks a million time.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
but as far as initializing, i am calling MapDialogRect to fill all the values of Rect structure. and for some reason, i am not able to place this created hwnd on a right location on the popup dialogbox.
originally, i am just asking for a way to be able to place stuff that i create inside winmainproc onto the popup dialogbox at the right location. but when i do it, it's either off the visibility or way to wrong location. the 2 functions i found is GetDialogBaseUnits and MapDialogRect, but both of them produces wrong results. (on my end).
example:
in my resource script file Dialog_abcd is at x=400 and y=300.
in my DlgProc
--------------------------------
RECT rect;
HWND MyHwnd;
case WM_INITDIALOG:
MapDialogRect(hwndDlg, &Rect);
if dialog box size in resource script file is set to 300X250 how can you set 2 integers x, y to be x=150, y = 125. can you please show me a simple example code.
mybe my post is not clear.
but everything i tried to be able to place controls on dialog box were wrong locations, so i used mapdialogrect. and when i took the rect sides as reference, somehow all the rect sides were 0. and when i used getdialogbaseunits, i was still not able to put controls at right locations. all the searchs i did on the net didn't fix my problem. so i had to post this thread.
from msdn
pixelX = (templateunitX * baseunitX) / 4
pixelY = (templateunitY * baseunitY) / 8
or
templateunitX = (pixelX * 4) / baseunitX
templateunitY = (pixelY * 8) / baseunitY
when i use these calculations, somehow either i am too off, and don't see the control, or it's never at the right location. my dialog font is set at 8.
now i'm asking how can i be able to put controls created by CreateWindow function at right locations.
thanks a million time.
please,
I used MapDialogRect successfully, maybe you're not calling it with the correct parameters or at the right time;
also check for error codes
Adrian
on DialogOneProc
case WM_INITDIALOG:
MapDialogRect(hwndDlg, &Rect);
MyCreatedhwnd = CreateWindows(Name, Name, Style, Rect.right/10, Rect.bottom/10, Rect.right/2, Rect.bottom/2, HWND, HMENU, HINSTANCE, NULL);
all sides of Rect is 0.....
Did you initialize your Rect?
According to
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/DialogBoxes/DialogBoxReference/DialogBoxFunctions/MapDialogRect.asp
the second parameter of MapDialogRect is a
"Pointer to a RECT structure that contains the dialog box coordinates to be converted."
Liviu
you mean initialized or "declared"?
on my dialog procedure, Rect is declared as:
RECT Rect;
but as far as initializing, i am calling MapDialogRect to fill all the values of Rect structure. and for some reason, i am not able to place this created hwnd on a right location on the popup dialogbox.
originally, i am just asking for a way to be able to place stuff that i create inside winmainproc onto the popup dialogbox at the right location. but when i do it, it's either off the visibility or way to wrong location. the 2 functions i found is GetDialogBaseUnits and MapDialogRect, but both of them produces wrong results. (on my end).
example:
in my resource script file Dialog_abcd is at x=400 and y=300.
in my DlgProc
--------------------------------
RECT rect;
HWND MyHwnd;
case WM_INITDIALOG:
MapDialogRect(hwndDlg, &Rect);
MyHwnd = CreateWindow(
Name,
Name,
Style,
???XXX_start,
???YYY_start,
???xxx_end,
???yyy_end,
HWND,
HMENU,
HINSTANCE,
NULL
);
Wanting MyHwnd x size tobe 100, y size tobe 50, starting x tobe 200, and starting y tobe 150:
but the following code dont' work:
MyHwnd = CreateWindow(
Name,
Name,
Style,
rect.right/2, <<<<<<<<<<<<<<<<<<<<<<<<
rect.bottom/2,<<<<<<<<<<<<<<<<<<<<<<
rect.right/4,<<<<<<<<<<<<<<<<<<<<<<<<
right.bottom/6,<<<<<<<<<<<<<<<<<<<<<<
HWND,
HMENU,
HINSTANCE,
NULL
);
what do i have to do to make MyHwnd to be the above size and be placed at the above mentioned location???????
thank you very much
"i am calling MapDialogRect to fill all the values of Rect structure"
You MUST fill the Rect structure with some values before you call MapDialogRect, otherwise the function will not "know" what to convert :)
If you want to create a window of 100x50 dialog units,
positioned at (200, 150) dialog units, you have to initialize your Rect like that:
Rect.left=200;
Rect.top=150;
Rect.right=Rect.left+100;
Rect.bottom=Rect.top+50;
and than call
MapDialogRect( hwndDlg, &Rect).
After the call, the Rect structure will contain the coordinates in "pixels", and you can use them in a CreateWindowEx function.
Note that all the coordinates are "client" coordinates, i.e. they are relative to the upper-left corner of a window's client area.
Liviu