xsharp.eu • Dialog size behaviour: VO dialog appears narrower (only width!) in X# - Page 2
Page 2 of 4

Dialog size behaviour: VO dialog appears narrower (only width!) in X#

Posted: Tue Jul 18, 2023 12:57 pm
by stefan.ungemach
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#

Posted: Tue Jul 18, 2023 1:06 pm
by robert
Stefan,
I am sorry, but we need a complete example to explain this.

Robert

Dialog size behaviour: VO dialog appears narrower (only width!) in X#

Posted: Tue Jul 18, 2023 1:26 pm
by leon-ts
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:
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))

Dialog size behaviour: VO dialog appears narrower (only width!) in X#

Posted: Tue Jul 18, 2023 1:44 pm
by stefan.ungemach
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
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
and call it before the show(),
            SELF:_recalcSize()
            SUPER:Show(SHOWCENTERED)
the width is better (not yet identical) but the height too big:

XSharp:

 
dialogXsharp2.png
dialogXsharp2.png (1.7 KiB) Viewed 763 times
VO:

 
dialogVO.png
dialogVO.png (2.07 KiB) Viewed 763 times
However, this looks like an approach. But shouldn't the Size assign do all of this?

Dialog size behaviour: VO dialog appears narrower (only width!) in X#

Posted: Tue Jul 18, 2023 1:54 pm
by stefan.ungemach
...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):

 
dialogXsharp.png
dialogXsharp.png (2.73 KiB) Viewed 763 times

Dialog size behaviour: VO dialog appears narrower (only width!) in X#

Posted: Tue Jul 18, 2023 2:09 pm
by stefan.ungemach
So doing this
        
    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.

 
dialogXsharp3.png
dialogXsharp3.png (2.32 KiB) Viewed 763 times
​​​​​​​
Question is: Why do I need to do this at all?

Dialog size behaviour: VO dialog appears narrower (only width!) in X#

Posted: Tue Jul 18, 2023 2:49 pm
by leon-ts
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.

Dialog size behaviour: VO dialog appears narrower (only width!) in X#

Posted: Tue Jul 18, 2023 2:59 pm
by stefan.ungemach
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...

Dialog size behaviour: VO dialog appears narrower (only width!) in X#

Posted: Tue Jul 18, 2023 3:22 pm
by leon-ts
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:
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)}
These calculations can (should) be defined in some general function so that it can be used in all the right places.

Dialog size behaviour: VO dialog appears narrower (only width!) in X#

Posted: Tue Jul 18, 2023 4:02 pm
by stefan.ungemach
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...