I have a window that I want to be resizeable in height only.

Just starting out? Need help? Post your questions and find answers here.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

I have a window that I want to be resizeable in height only.

Post 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! :D
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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! :D
I may look like a mule, but I'm not a complete ass.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post 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.
:lol:
Last edited by dagcrack on Tue May 02, 2006 3:41 pm, edited 3 times in total.
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

:D
I may look like a mule, but I'm not a complete ass.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

:D
@}--`--,-- A rose by any other name ..
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

srod wrote:Theress probably a better way though! :D
Yeah, I that's what i'm looking for! :P (everything must be perfect in my eyes)
But thank you anyway, I might have to stick with this! :D
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

So there is no way of switching the resizing on and off? :cry:
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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
I may look like a mule, but I'm not a complete ass.
Post Reply