As promised in the other thread: Many thanks to José for this gem that can save a lot of trouble.
The attached picture shows the window as designed with two text boxes, a frame and a list. In the main.bas program, don't forget:
#include "afx\clayout.inc"
And this is the form.inc code:
' frmMain form code file
''
''
''These constants are enumerated in afx/clayout.inc
' AFX_ANCHOR_NONE = 0
' AFX_ANCHOR_WIDTH
' AFX_ANCHOR_RIGHT
' AFX_ANCHOR_CENTER_HORZ
' AFX_ANCHOR_HEIGHT
' AFX_ANCHOR_HEIGHT_WIDTH
' AFX_ANCHOR_HEIGHT_RIGHT
' AFX_ANCHOR_BOTTOM
' AFX_ANCHOR_BOTTOM_WIDTH
' AFX_ANCHOR_BOTTOM_RIGHT
' AFX_ANCHOR_CENTER_HORZ_BOTTOM
' AFX_ANCHOR_CENTER_VERT
' AFX_ANCHOR_CENTER_VERT_RIGHT
' AFX_ANCHOR_CENTER
dim shared as clayout ptr playout 'A shared pointer so it can be seen in all functions
dim shared as boolean form_ready=false 'Prevents a hard-to-debug crash
Function frmMain_Load( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
dim as long ngrip=frmmain.getnextctrlid()
playout = new clayout(frmmain.hwindow) 'assigns a layout manager to this window
'This is optional. Adds the little gripper spot to the bottom right corner.
frmmain.pwindow->addcontrol("SizeGrip", frmmain.hWindow, ngrip)
'Decide how each control is to be sized
playout->anchorcontrol(frmmain.text1.hwindow, afx_anchor_width)
playout->anchorcontrol(frmmain.text2.hwindow, afx_anchor_height_width)
playout->anchorcontrol(frmmain.frame1.hwindow, afx_anchor_height_right)
playout->anchorcontrol(frmmain.list1.hwindow, afx_anchor_height_right)
playout->anchorcontrol(ngrip, afx_anchor_bottom_right)
Function = 0
End Function
''
''
Function frmMain_Resize( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
if form_ready then 'This prevents the crash.
playout->adjustcontrols 'This does the resizing
end if
Function = 0
End Function
''
''
Function frmMain_FormClosed( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
delete playout 'Wouldn't want a memory leak
Function = 0
End Function
''
''
Function frmMain_AllEvents( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
'This part taken from José's example layout manager programs.
'Who knew there was such a thing?
'I could have just put a test in the RESIZE event.
if e.Message = wm_getminmaxinfo then
dim ptmmi as MINMAXINFO ptr = cast(minmaxinfo ptr, e.lParam )
ptmmi->ptmintracksize.x = 300
ptmmi->ptmintracksize.y = 180
end if
Function = 0
End Function
''
''
Function frmMain_FormReady( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
'Sometimes a Resize event happens before Form_Load is done.
'That causes a nasty crash.
form_ready=true
Function = 0
End Function
I think the comments explain what's going on. The minimum size of 300x180 is a nice touch taken from the examples. Check out the layout manager examples in the templates for more complex behavior. It's possible to put layouts inside layouts.
Thank you for the example mate, it is much appreciated.
I do get errors right of the bat.
The include of the clayout.inc is fine.
The assignment of the pointer throws an error:
dim shared as clayout ptr playout
Throws the error : ERROR 14: Expected identifier, found 'clayout'
I do see where this is going though.
But I think i am going to wait until Paul adds it to his designer.
That automation made it a breeze.
Thanks for the example.
Peter
Hmm. Works for me. I do get that error, among many others, if I leave out the #include.
Thanks, Philbar! Worked first time, no errors.
Yes it works just fine if the moron that pasted the info removes a rem comma....
I can be a real idiot.
Dear Heavens. :-[
Great stuff. It works perfectly when I change the form size, use the maximize button and so forth.
But when i start the form using formwindowstate.maximized then it completely messes up the controls.
In Powerbasic the Maximized form worked under the form_resize function.
It does not seem to be the case in Freebasic.
-Regards, Peter
I've never tried it on a form that starts out maximized. Maybe if you start out regular and maximize it in Form_Load after the layout manager has initialized?
Hi
That works fine if i do that, I was just wondering why the Maximize startup of the form does not fire the form-resize event.
Unless the Maximize startup runs before some of the other events.
Regards, Peter
QuoteBut when i start the form using formwindowstate.maximized then it completely messes up the controls.
FormWindowState.Normal is the only state that appears to work without messing up the control sizes and positions.
After some experimenting, I got the result I expected when I started out normal and put "frmmain.windowstate = maximized" at the end of the frmmain_FormReady event.
Yes, that works perfectly.
Thanks a million.