Put a Window in a Corner
Posted: Fri Sep 21, 2001 11:45 pm
Restored from previous forum. Originally posted by Franco.
Code updated for 5.20+
Have a nice day...
Franco
Code updated for 5.20+
Code: Select all
; (c) 2001 Franco's template - absolutely freeware
; Put a window in a corner.
; Positions depends on the Windows-AppBar.
; Compiler option 'Enable inline ASM support must be ON
EnableASM
Procedure.l Screen_Width()
ProcedureReturn GetSystemMetrics_(#SM_CXSCREEN)
EndProcedure
Procedure.l Screen_Height()
ProcedureReturn GetSystemMetrics_ (#SM_CYSCREEN)
EndProcedure
Structure AppBar
NotUsed1.l
NotUsed2.l
NotUsed3.l
Position.l
LeftX.l
LeftY.l
RightX.l
RightY.l
EndStructure
Global Info.AppBar
Procedure$ AppBarHide(Info)
; Is AutoHide of AppBar active ?
; Result: 0 = no , 1 = yes
AppBarHide=SHAppBarMessage_(4,Info)-2 ; don't know axactly why I have to substract 2
If AppBarHide = 0 : ProcedureReturn "no" : EndIf
If AppBarHide = 1 : ProcedureReturn "yes" : EndIf
EndProcedure
Procedure$ AppBarPos(Info)
; Position of the Windows-AppBar
; Value of position information: 0 = left, 1 = top, 2 = right, 3 = bottom
SHAppBarMessage_(5,Info)
If Info = 0 : ProcedureReturn "left" : EndIf
If Info = 1 : ProcedureReturn "top" : EndIf
If Info = 2 : ProcedureReturn "right" : EndIf
If Info = 3 : ProcedureReturn "bottom" : EndIf
EndProcedure
#MAX_GADGET = 4
Dim GadFunc.l(#MAX_GADGET)
GadFunc(1) = ?gadget1 ; This stores the adress of label gadget0 in GadFunc(1)
GadFunc(2) = ?gadget2 ; This stores the adress of label gadget0 in GadFunc(2)
GadFunc(3) = ?gadget3 ; This stores the adress of label gadget0 in GadFunc(3)
GadFunc(4) = ?gadget4 ; This stores the adress of label gadget0 in GadFunc(4)
#WindowWidth = 320
#WindowHeight = 240
If OpenWindow(0, Screen_Width(), Screen_Height(), #WindowWidth, #WindowHeight, "(c) Franco's CornerWindow", #PB_Window_SystemMenu)
ButtonGadget(1,1,1,80,25,"Top Left")
ButtonGadget(2,235,1,80,25,"Top Right")
ButtonGadget(3,1,191,80,25,"Bottom Left")
ButtonGadget(4,235,191,80,25,"Bottom Right")
xPos = (Screen_Width() / 2) - (#WindowWidth / 2)
yPos = (Screen_Height() / 2) - (#WindowHeight / 2)
ResizeWindow(0, xPos, yPos, #PB_Ignore, #PB_Ignore)
Text$="AutoHide of AppBar active: "+AppBarHide(Info)
TextGadget(5,75,75,200,15,Text$)
Text$="Position of AppBar: "+AppBarPos(Info)
TextGadget(6,75,90,200,15,Text$)
EndIf
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_Gadget
GadgetID.l = EventGadget()
DestAdress.l = GadFunc(GadgetID)
CALL DestAdress
EndIf
Until EventID = #PB_Event_CloseWindow
End
gadget1:
; some code for gadget 1
Text$="AutoHide of AppBar active: "+AppBarHide(Info)
SetGadgetText(5,Text$)
Text$="Position of AppBar: "+AppBarPos(Info)
SetGadgetText(6,Text$)
xPos = 0 : yPos = 0
If Info\Position = 0 : xPos = Info\RightX : EndIf ;left
If Info\Position = 1 : yPos = Info\RightY : EndIf ;top
ResizeWindow(0, xPos, yPos, #PB_Ignore, #PB_Ignore)
Return
gadget2:
; some code for gadget 2
Text$="AutoHide of AppBar active: "+AppBarHide(Info)
SetGadgetText(5,Text$)
Text$="Position of AppBar: "+AppBarPos(Info)
SetGadgetText(6,Text$)
xPos = Screen_Width()-#WindowWidth : yPos = 0
If Info\Position = 1 : yPos = Info\RightY : EndIf ;top
If Info\Position = 2 : xPos = Info\LeftX-#WindowWidth : EndIf ;right
ResizeWindow(0, xPos, yPos, #PB_Ignore, #PB_Ignore)
Return
gadget3:
; some code for gadget 3
Text$="AutoHide of AppBar active: "+AppBarHide(Info)
SetGadgetText(5,Text$)
Text$="Position of AppBar: "+AppBarPos(Info)
SetGadgetText(6,Text$)
xPos = 0 : yPos = Screen_Height()-#WindowHeight
If Info\Position = 0 : xPos = Info\RightX : EndIf ;left
If Info\Position = 3 : yPos = Info\LeftY-#WindowHeight : EndIf ;bottom
ResizeWindow(0, xPos, yPos, #PB_Ignore, #PB_Ignore)
Return
gadget4:
; some code for gadget 4
Text$="AutoHide of AppBar active: "+AppBarHide(Info)
SetGadgetText(5,Text$)
Text$="Position of AppBar: "+AppBarPos(Info)
SetGadgetText(6,Text$)
xPos = Screen_Width()-#WindowWidth : yPos = Screen_Height()-#WindowHeight
If Info\Position = 2 : xPos = Info\LeftX-#WindowWidth : EndIf ;right
If Info\Position = 3 : yPos = Info\LeftY-#WindowHeight : EndIf ;bottom
ResizeWindow(0, xPos, yPos, #PB_Ignore, #PB_Ignore)
Return
End
Franco