Dialog size behaviour: VO dialog appears narrower (only width!) in X#
-
- Posts: 71
- Joined: Thu Jul 15, 2021 10:46 am
- Location: Germany
Dialog size behaviour: VO dialog appears narrower (only width!) in X#
Thanks Leonid. I have copied your full content into cctl6.man (which is referred in Manifest.rc), but the behaviour is still the same.
Dialog size behaviour: VO dialog appears narrower (only width!) in X#
Stefan,
I am sorry, but we need a complete example to explain this.
Robert
I am sorry, but we need a complete example to explain this.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
Dialog size behaviour: VO dialog appears narrower (only width!) in X#
Stefan,
If I understood you correctly, then you set the size of the dialog box manually (not the resource). Apparently, using the SetWindowPos or MoveWindow functions.
If this is the case, then to correctly display the full size of the dialog box, you need to calculate the size of the client area you need, and then apply the AdjustWindowRectEx function.
Here's an example:
If I understood you correctly, then you set the size of the dialog box manually (not the resource). Apparently, using the SetWindowPos or MoveWindow functions.
If this is the case, then to correctly display the full size of the dialog box, you need to calculate the size of the client area you need, and then apply the AdjustWindowRectEx function.
Here's an example:
LOCAL rc IS _WINRECT
LOCAL dwExStyle := DWORD(_CAST, GetWindowLong(SELF:Handle(), GWL_EXSTYLE)) AS DWORD
SetRect(@rc, 0, 0, nW, nH)
AdjustWindowRectEx(@rc, SELF:GetStyle(), FALSE, dwExStyle)
SetWindowPos(SELF:Handle(), HWND_TOP, 0, 0, rc.right - rc.left, rc.bottom - rc.top, _OR(SWP_NOMOVE, SWP_NOZORDER))
Best regards,
Leonid
Leonid
-
- Posts: 71
- Joined: Thu Jul 15, 2021 10:46 am
- Location: Germany
Dialog size behaviour: VO dialog appears narrower (only width!) in X#
That's very interesting. Actually I only used the Size assign to alter the dialog size. If I put your example code in a method like this
XSharp:
VO:
However, this looks like an approach. But shouldn't the Size assign do all of this?
and call it before the show(),METHOD _recalcSize()
LOCAL rc IS _WINRECT
LOCAL dwExStyle := DWORD(_CAST, GetWindowLong(SELF:Handle(), GWL_EXSTYLE)) AS DWORD
SetRect(@rc, 0, 0, SELF:size:width, SELF:size:height)
AdjustWindowRectEx(@rc, SELF:GetStyle(), FALSE, dwExStyle)
SetWindowPos(SELF:Handle(), HWND_TOP, 0, 0, rc.right - rc.left, rc.bottom - rc.top, _OR(SWP_NOMOVE, SWP_NOZORDER))
RETURN NIL
the width is better (not yet identical) but the height too big:SELF:_recalcSize()
SUPER:Show(SHOWCENTERED)
XSharp:
VO:
However, this looks like an approach. But shouldn't the Size assign do all of this?
-
- Posts: 71
- Joined: Thu Jul 15, 2021 10:46 am
- Location: Germany
Dialog size behaviour: VO dialog appears narrower (only width!) in X#
...and if I change the parameters to
METHOD _recalcSize()
LOCAL rc IS _WINRECT
LOCAL dwExStyle := DWORD(_CAST, GetWindowLong(SELF:Handle(), GWL_EXSTYLE)) AS DWORD
SetRect(@rc, 0, 0, SELF:canvasarea:size:width, SELF:canvasarea:size:height)
AdjustWindowRectEx(@rc, SELF:GetStyle(), FALSE, dwExStyle)
SetWindowPos(SELF:Handle(), HWND_TOP, 0, 0, rc.right - rc.left, rc.bottom - rc.top, _OR(SWP_NOMOVE, SWP_NOZORDER))
RETURN NIL
the result is as with the beginning of the thread (so this seems to be what "self:size :=" is doing):
METHOD _recalcSize()
LOCAL rc IS _WINRECT
LOCAL dwExStyle := DWORD(_CAST, GetWindowLong(SELF:Handle(), GWL_EXSTYLE)) AS DWORD
SetRect(@rc, 0, 0, SELF:canvasarea:size:width, SELF:canvasarea:size:height)
AdjustWindowRectEx(@rc, SELF:GetStyle(), FALSE, dwExStyle)
SetWindowPos(SELF:Handle(), HWND_TOP, 0, 0, rc.right - rc.left, rc.bottom - rc.top, _OR(SWP_NOMOVE, SWP_NOZORDER))
RETURN NIL
the result is as with the beginning of the thread (so this seems to be what "self:size :=" is doing):
-
- Posts: 71
- Joined: Thu Jul 15, 2021 10:46 am
- Location: Germany
Dialog size behaviour: VO dialog appears narrower (only width!) in X#
So doing this
leads to an acceptable result.
Question is: Why do I need to do this at all?
ASSIGN size( oSize )
LOCAL rc IS _WINRECT
LOCAL dwExStyle := DWORD(_CAST, GetWindowLong(SELF:Handle(), GWL_EXSTYLE)) AS DWORD
SUPER:size := oSize
SetRect(@rc, 0, 0, SELF:size:width, SELF:canvasarea:size:height)
AdjustWindowRectEx(@rc, SELF:GetStyle(), FALSE, dwExStyle)
SetWindowPos(SELF:Handle(), HWND_TOP, 0, 0, rc.right - rc.left, rc.bottom - rc.top, _OR(SWP_NOMOVE, SWP_NOZORDER))
RETURN
leads to an acceptable result.
Question is: Why do I need to do this at all?
Dialog size behaviour: VO dialog appears narrower (only width!) in X#
Stefan,
If you are manually controlling the size of the window, then what are you using the Size property for? This property under the hood simply gets the current size of the window using the GetWindowRect function. This will be some default size that is given to the window after creation. If you have not set it in advance to some value you need, then all subsequent results based on it will not give you the desired result.
For example, the default window size (after creation) is 20 pixels wide. And you pass this value to the AdjustWindowRectEx function, thereby telling that this is the width you need. But obviously 20px (just an example) is not the right width.
Again, if you decide to control the size of the window yourself, then you need to control all aspects of it. In your example, you need to determine the value of the widest control you have placed in the window. Then add the required amount of padding to the left and right to this value (for example, 8 pixels each). Likewise for height. And then these values need to be passed to the AdjustWindowRectEx function.
If you are manually controlling the size of the window, then what are you using the Size property for? This property under the hood simply gets the current size of the window using the GetWindowRect function. This will be some default size that is given to the window after creation. If you have not set it in advance to some value you need, then all subsequent results based on it will not give you the desired result.
For example, the default window size (after creation) is 20 pixels wide. And you pass this value to the AdjustWindowRectEx function, thereby telling that this is the width you need. But obviously 20px (just an example) is not the right width.
Again, if you decide to control the size of the window yourself, then you need to control all aspects of it. In your example, you need to determine the value of the widest control you have placed in the window. Then add the required amount of padding to the left and right to this value (for example, 8 pixels each). Likewise for height. And then these values need to be passed to the AdjustWindowRectEx function.
Best regards,
Leonid
Leonid
-
- Posts: 71
- Joined: Thu Jul 15, 2021 10:46 am
- Location: Germany
Dialog size behaviour: VO dialog appears narrower (only width!) in X#
Leonid,
we do all of this (in VO) for all the dynamic controls. But in VO it is enough to set the calculated size (taking system menu etc. into account) via the "Size" ASSIGN. In X# there seems to be a difference which I haven't understood fully yet...
we do all of this (in VO) for all the dynamic controls. But in VO it is enough to set the calculated size (taking system menu etc. into account) via the "Size" ASSIGN. In X# there seems to be a difference which I haven't understood fully yet...
Dialog size behaviour: VO dialog appears narrower (only width!) in X#
Stefan,
If you have a scale of elements greater than 100% enabled on your computer (Windows settings), then instead of constants like 118x146, you need to pass their scaled values to the Size setter. In principle, this should be done in VO as well.
Example:
If you have a scale of elements greater than 100% enabled on your computer (Windows settings), then instead of constants like 118x146, you need to pass their scaled values to the Size setter. In principle, this should be done in VO as well.
Example:
These calculations can (should) be defined in some general function so that it can be used in all the right places.LOCAL hDC := GetDC(HWND_DESKTOP) AS PTR
LOCAL nLogX, nLogY AS REAL8
nLogX := GetDeviceCaps(hDC, LOGPIXELSX) / 96.0
nLogY := GetDeviceCaps(hDC, LOGPIXELSY) / 96.0
ReleaseDC(HWND_DESKTOP, hDC)
LOCAL oMyWndSize AS VO.Dimension
oMyWndSize := VO.Dimension{(INT)(118 * nLogX), (INT)(146 * nLogY)}
Best regards,
Leonid
Leonid
-
- Posts: 71
- Joined: Thu Jul 15, 2021 10:46 am
- Location: Germany
Dialog size behaviour: VO dialog appears narrower (only width!) in X#
I see, and of course I agree with the concept. However, I would expect that a window with fixed constants as dimension, passed by the Size assign, would appear identical regardless if shown by VO or X# code on the same machine with the same resolution (which is, BTW, 100%, thus resulting in 96dpi) - no?
In addition, the results of GetDeviceCaps don't work with all screen scalings under windows (had to do a lot of these calculations recently to achieve automated hardcopies of dialog regions), but that's another story...
In addition, the results of GetDeviceCaps don't work with all screen scalings under windows (had to do a lot of these calculations recently to achieve automated hardcopies of dialog regions), but that's another story...