Page 1 of 1
I have a window that I want to be resizeable in height only.
Posted: Mon May 01, 2006 6:26 pm
by Joakim Christiansen
I have a window that I want to be resizeable in height only.
But I also have to be able to switch the resizing off and on, because sometimes I don't want the user to be able to resize it.
And the thing is... I don't know how to do this!

Posted: Mon May 01, 2006 6:51 pm
by srod
Here's one way:
Code: Select all
Procedure WndProc(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
*pMinMax.MINMAXINFO
If Message = #WM_GETMINMAXINFO
*pMinMax = lParam
*pMinMax\ptMaxTrackSize\x = 640+2*GetSystemMetrics_(#SM_CXSIZEFRAME)
*pMinMax\ptMinTrackSize\x = 640+2*GetSystemMetrics_(#SM_CXSIZEFRAME)
Result = 0
EndIf
ProcedureReturn Result
EndProcedure
OpenWindow(0,0,0,640,500,"",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
SetWindowCallback(@WndProc())
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
There's probably a better way though!

Posted: Tue May 02, 2006 3:36 pm
by dagcrack
I just wanted to state that you are adding some overhead by having 2 api calls over there and the adding, multiplying, etc.
When you could do it just once:
Code: Select all
Global MaxScale.l
;
Procedure WndProc(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
*pMinMax.MINMAXINFO
If Message = #WM_GETMINMAXINFO
*pMinMax = lParam
*pMinMax\ptMaxTrackSize\X = MaxScale
*pMinMax\ptMinTrackSize\X = MaxScale
Result = 0
EndIf
ProcedureReturn Result
EndProcedure
;
WinWidth.w = 640;
WinHeight.w = 480;
OpenWindow(0,0,0,WinWidth,WinHeight,"",#pb_window_systemmenu|#PB_Window_SizeGadget)
MaxScale =WinWidth+2*GetSystemMetrics_(#SM_CXSIZEFRAME)
SetWindowCallback(@WndProc())
;
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
Because I'm pretty sure that everytime you'll scale your window you'll be wasting cpu cycles. Even though its not something that is done all the time nor cpu intensive (on most cases), it's good to take care of simple things like this.
Yeh it was just an example you might say, but its good habit to optimize your code.
Now let's talk about the memory overhead I just created.

Posted: Tue May 02, 2006 3:40 pm
by srod
Posted: Tue May 02, 2006 3:47 pm
by Dare2
Posted: Tue May 02, 2006 9:17 pm
by Joakim Christiansen
srod wrote:Theress probably a better way though!

Yeah, I that's what i'm looking for!

(everything must be perfect in my eyes)
But thank you anyway, I might have to stick with this!

Posted: Wed May 03, 2006 7:27 pm
by Joakim Christiansen
So there is no way of switching the resizing on and off?

Posted: Wed May 03, 2006 7:48 pm
by Flype
yes you can - i made a little proc for you.
Code: Select all
Procedure ToggleSizeWindow(window.l)
Protected hWnd.l = WindowID(window)
Protected style.l = GetWindowLong_(hWnd, #GWL_STYLE)
If (style&#WS_SIZEBOX)
SetWindowLong_(hWnd, #GWL_STYLE, style&~#WS_SIZEBOX)
Else
SetWindowLong_(hWnd, #GWL_STYLE, style|#WS_SIZEBOX)
EndIf
SetWindowPos_(hWnd, 0, 0, 0, 0, 0, #SWP_NOMOVE|#SWP_NOSIZE|#SWP_NOZORDER|#SWP_FRAMECHANGED)
EndProcedure
Posted: Wed May 03, 2006 7:55 pm
by srod
This one prohibits just horizontal sizing when you check the checkbox gadget.
Code: Select all
Global MaxScale.l
;
Procedure WndProc(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
*pMinMax.MINMAXINFO
If Message = #WM_GETMINMAXINFO And GetGadgetState(1)
*pMinMax = lParam
*pMinMax\ptMaxTrackSize\X = MaxScale
*pMinMax\ptMinTrackSize\X = MaxScale
Result = 0
ElseIf message = #WM_SIZE
MaxScale=WindowWidth(0)+2*GetSystemMetrics_(#SM_CXSIZEFRAME)
EndIf
ProcedureReturn Result
EndProcedure
;
WinWidth.w = 640;
WinHeight.w = 480;
OpenWindow(0,0,0,WinWidth,WinHeight,"",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
CreateGadgetList(WindowID(0))
CheckBoxGadget(1,10,10,20,20,"")
TextGadget(2,40,10,200,20,"Check to prohibit horizontal sizing.")
MaxScale =WinWidth+2*GetSystemMetrics_(#SM_CXSIZEFRAME)
SetWindowCallback(@WndProc())
;
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow