Code: Select all
; Windows Handling Example v 0.01 (XP-ready)
; How to adjust Gadgets and Elements inside the window after resizing it.
; This example takes care of different bordersizes and window-fontsizes
; Quick hacked by Juergen Vierheilig
; Comments *bad* translated to english
;
; ***********************************
; SOME PRE DEFINING
; ***********************************
InitGadget(12)
; ***********************************
; VARIABLES AND CONSTANTS
; ***********************************
#Frame3D = 8
#Min_Screen_X = 800
#Min_Screen_Y = 600
rectangle.RECT
; *********************
; STRUCTS
; *********************
Structure Window
Address.l
NumericID.l
GadgetArea.l
Flags.l
Title.s
x.w
y.w
Width.w
Height.w
TreePosition.w
TreeState.b
EndStructure
; ***********************************
; PROCEDURES
; ***********************************
Procedure SizeCallback(WindowID, Message, wParam, lParam)
; Diese Prozedur setzt die minimale und maximale Groesse eines zuvor geoeffneten Fensters fest
;
; This Procedure sets min and max dimensions for a previous opened window
;
If Message = #WM_GETMINMAXINFO
*SizeTracking.MINMAXINFO = lParam
*SizeTracking\ptMinTrackSize\x = 100
*SizeTracking\ptMinTrackSize\y = 100
*SizeTracking\ptMaxTrackSize\x = 640
*SizeTracking\ptMaxTrackSize\y = 480
EndIf
EndProcedure
Procedure ColorizeWindow(Color)
; Diese Prozedur färbt ein Windows unter WindowsXP in die korrekten Hintergrundfarben ein
; Aufruf *nach* Öffnen des Windows
;
; This Procedure sets correct background-color on Windows XP systems.
;
Brush.LOGBRUSH\lbColor = GetSysColor_(Color)
SetClassLong_(WindowID(),#GCL_HBRBACKGROUND,CreateBrushIndirect_(Brush))
RedrawWindow_(WindowID(),0,0,7)
EndProcedure
; ***************
; MAIN PART
; ***************
; Wir moechten ein Fenster mit den Dimensionen 640 x 480 mittig auf dem Bildschirm oeffnen
; Also muessen wir die Screendimensionen auslesen und den x/y Startpunkt errechnen
;
; We want to open a centered window with 640 x 480 pixels
; So we need to know the actual desktop dimensions:
;
screenx.w = GetSystemMetrics_(#SM_CXSCREEN)
screeny.w = GetSystemMetrics_(#SM_CYSCREEN)
;
; Wir haben jetzt also die aktuellen Dimensionen des Desktops
; Jetzt pruefen wir erstmal, ob die Dimensionen gross genug sind:
; Wir setzen eine Mindestgroesse von 800 x 600 voraus, andernfalls
; terminieren wir mit einer Fehlermeldung
;
; Now we know the desktop dimensions. We can check now for minimal required resolution,
; since our window should fit into the screen. Let us force a minimum resolution of
; 800 x 400, otherwise we will terminate with error-message, informing the user,
; that a higher resolution is needed.
;
If ((screenx.w #FALSE
rx=rectangle.RECT\right-rectangle.RECT\left
ry=rectangle.RECT\bottom-rectangle.RECT\top
EndIf
Borderleft=640-rx
Bordertop=480-ry
; Create a 3d-frame. This frame will resize with the window-size
If CreateGadgetList(WindowID())
Frame3DGadget(#Frame3D, 1, 1, WindowWidth() - Borderleft, WindowHeight()-Bordertop, "Fensterdemo", 0)
EndIf
; Now let the user play with our window
; End the program, when user hits the close-button
;
Repeat
EventID.l = WaitWindowEvent()
; Sichern der aktuellen Fenstergroesse
;
; Store the actual window size
;
AktuelleBreite.w = WindowWidth()
AktuelleHoehe.w = WindowHeight()
; Wurde die Groesse des Fensters veraendert?
;
; Has the window size changed?
;
If (AktuelleHoehe.w AlteHoehe.w) Or (AktuelleBreite.w AlteBreite.w)
; Backup der aktuellen Groesse fuer spaeteren Vergleich
;
; Backup the actual size for recall later
;
AlteBreite.w = AktuelleBreite
AlteHoehe.w = AktuelleHoehe
ResizeGadget(#Frame3D, 1, 1, WindowWidth() - Borderleft, WindowHeight()-Bordertop)
EndIf
; Otherwise end
Until EventID = #PB_EventCloseWindow