Author Topic: Helper Routines for sizing controls in a window  (Read 3070 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
Helper Routines for sizing controls in a window
« on: August 22, 2018, 06:44:15 AM »
Hello,

this is a small project which worried me for a while. I am still not sure if it works ok now. There are two procedures which should help to autosize the controls in a window. I got the idea of placement factors from a code written in Euphoria, but the implementation in Oxygenbasic is different (and a bit more simplified).

The demos should work in 32-bit and 64-bit mode. The procedures cannot achieve everything but if applied carefully they can do a lot. If I coded everything correctly, they could save a lot of additional calculations.

Demo6Dlg.o2bas uses the modified Dialogs.inc which was presented here:
https://www.oxygenbasic.org/forum/index.php?topic=1525.msg18825#msg18825

Roland
Edit:
I reworked the project and provide the code here:

https://www.oxygenbasic.org/forum/index.php?topic=1863.msg20129#msg20129
« Last Edit: February 28, 2019, 08:10:50 AM by Arnold »

Aurel

  • Guest
Re: Helper Routines for sizing controls in a window
« Reply #1 on: August 22, 2018, 01:43:55 PM »
Hi Arnold
You dont need to call getWindowrect than just look into awinh.inc
function i use in Aurel Edit it is called GetSize.
Or maybe you need different sizing?
I am not sure that i understand your example  ::)

Arnold

  • Guest
Re: Helper Routines for sizing controls in a window
« Reply #2 on: August 22, 2018, 10:58:32 PM »
Hi Zlatko,

learning by doing: How would you build the functionality e.g. of demo2.o2bas using awinh.inc?  It would be interesting to compare different approaches.

In the meantime I noticed that I will need a function which will interrupt moving and resizing controls at a certain point of sizing the main window. Until now I only used the setMinSize macro to stop decreasing the size of the window. But my focus was running the demos in 32-bit and 64-bit mode.

Roland

Arnold

  • Guest
Re: Helper Routines for sizing controls in a window
« Reply #3 on: August 23, 2018, 03:13:44 AM »
It turns out that preventing resizing is not so difficult. I added an additional function:
sub unpinControl(sys hCtl, sys hParent, int width, height) 'pixels

« Last Edit: February 28, 2019, 08:12:08 AM by Arnold »

Aurel

  • Guest
Re: Helper Routines for sizing controls in a window
« Reply #4 on: August 23, 2018, 04:53:47 AM »
Quote
learning by doing: How would you build the functionality e.g. of demo2.o2bas using awinh.inc?

Probably very similar like you because all is driven by WM_SIZE message.
I forget that i use two functions:

Code: [Select]
sub GetSize(int hnd,hndx as int,hndy as int,hndw as int,hndh as int)
GetClientRect(hnd,rc)
'hndx=0:hndy=0:hndw=0:hndh=0
hndx = rc.left
hndy = rc.top
hndw = rc.right
hndh = rc.bottom
end sub


'SetSize()

sub SetSize(int hnd,byref hndx as int,byref hndy as int,byref hndw as int,byref hndh as int)
INT sdata[4]
sdata[0]=hndx
sdata[1]=hndy
sdata[2]=hndw
sdata[3]=hndh
'SetWindowPos(hnd,0,sdata[0],sdata[1],sdata[2],sdata[3],0)
MoveWindow(hnd,sdata[0],sdata[1],sdata[2],sdata[3],1)
end sub

Mike Lobanovsky

  • Guest
Re: Helper Routines for sizing controls in a window
« Reply #5 on: August 25, 2018, 02:02:20 PM »
Hi Roland,

MoveWindow() works OK and definitely does what it is supposed to. But control movement will be more or less smooth and fast only if the number of controls to resize/reposition is relatively small.

If you have to resize/reposition a much larger number of dialog controls like e.g. a set of table cells in a single swoop, which isn't so uncommon in practice, then prefer to use a BeginDeferWindowPos()/DeferWindowPos()/EndDeferWindowPos() API sequence.

Their cumulative effect and syntax are very similar to a series of SetWindowPos() API calls but will occur in a single redraw of the parent dialog window in response to the EndDeferWindowPos() call. Thus there will be much less dialog window flicker and resizing/repositioning will be much much faster and unnoticeable to the eye.

Note well that the above APIs will work only if each and every child control window in the batch to be moved belongs directly to one and the same immediate parent -- in your case, to the main dialog window of your project. If at least one child window happens to have some other immediate parent (by mistake or in an attempt to cheat Windows), like e.g. a frame or tab page container control, then the entire sequence will fail and the child controls' positions and/or sizes will remain unchanged.

JRS

  • Guest
Re: Helper Routines for sizing controls in a window
« Reply #6 on: August 25, 2018, 06:25:34 PM »
I would think there is a wealth of WinAPI code that would apply to anyone creating Windows applications by reviewing the IUP source code.

Arnold

  • Guest
Re: Helper Routines for sizing controls in a window
« Reply #7 on: August 26, 2018, 12:59:16 AM »
Hi Mike,

thank you for your considerations. I know there are some weaknesses in the code; there is a missing correlation between dialog units and screen pixels, I do not know the effects if using statusbar, wrapping menue and toolbar, or rebarband (which is not yet done in Oxygenbasic). Also the behaviour with using tabcontrols must be checked. But as a starting point for small projects it already works quite nice.

I like the idea of using placement factors. There are some examples which apply different methods for anchoring, some of them use a lot of code and yet do not work correctly in some cases.

Thank you for pointing me to the DeferWindowPos... functions. I was aware of them but until now I did not give much attention to them. They seem to be superior to the MoveWindow feature and I will try to use them instead.

Roland

Aurel

  • Guest
Re: Helper Routines for sizing controls in a window
« Reply #8 on: August 26, 2018, 01:53:31 AM »
Quote
or rebarband (which is not yet done in Oxygenbasic).

Arnold
This is like everything else here...
nobody ask about that control ..soo it looks that nobody need such a control in
his programs, or simply there is no interest for that   ::)

jack

  • Guest
Re: Helper Routines for sizing controls in a window
« Reply #9 on: August 26, 2018, 03:22:10 AM »
Hi Arnold
I am following your explorations with interest, I hope to see more :)