Page 1 of 1

Put a Window in a Corner

Posted: Fri Sep 21, 2001 11:45 pm
by BackupUser
Restored from previous forum. Originally posted by 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 
Have a nice day...
Franco

Posted: Sat Sep 22, 2001 4:47 am
by BackupUser
Restored from previous forum. Originally posted by Mr.Skunk.

another gret type, thanks.

Just add, that we must have enabled the 'inline assembly' to make it work.


Mr Skunk

Mr Skunk's PureBasic Web Page
http://www.skunknet.fr.st

Posted: Tue Sep 25, 2001 7:36 pm
by BackupUser
Restored from previous forum. Originally posted by Franco.

Finally a procedure to use it with your code:

Code: Select all

; (c) 2001 - Franco's Template - absolutely freeware
; Move a window to a defined position - from 0 to 8 (9 positions)
; Usage: WindowPos(#)
; 0 = top-left, 1 = top-mid, 2 = top-right
; 3 = center-left, 4 = center-mid, 5 = center-right
; 6 = bottom-left, 7 = bottom-mid, 8 = bottom-right

Procedure WindowPos(Window, Pos)
  Structure WindowPosAppBar
    NotUsed1.l
    NotUsed2.l
    NotUsed3.l
    Position.l
    LeftX.l
    LeftY.l
    RightX.l
    RightY.l
  EndStructure

  WindowPosInfo.WindowPosAppBar
  
  SHAppBarMessage_(5,WindowPosInfo)
  
  If Pos = 0 Or Pos = 1 Or Pos = 2 : If WindowPosInfo\Position = 1 : yPos = WindowPosInfo\RightY : Else : yPos = 0 : EndIf : EndIf ;top
  If Pos = 3 Or Pos = 4 Or Pos = 5 : yPos = (GetSystemMetrics_(#SM_CYSCREEN)/2)-(WindowHeight(Window)/2) : EndIf ;center
  If Pos = 6 Or Pos = 7 Or Pos = 8 : If WindowPosInfo\Position = 3 : yPos = WindowPosInfo\LeftY-WindowHeight(Window) : Else : yPos = GetSystemMetrics_(#SM_CYSCREEN)-WindowHeight(Window) : EndIf : EndIf ;bottom
  If Pos = 0 Or Pos = 3 Or Pos = 6 : If WindowPosInfo\Position = 0 : xPos = WindowPosInfo\RightX : Else : xPos = 0 : EndIf : EndIf ;left
  If Pos = 1 Or Pos = 4 Or Pos = 7 : xPos = (GetSystemMetrics_(#SM_CXSCREEN)/2)-(WindowWidth(Window)/2) :  EndIf ;mid
  If Pos = 2 Or Pos = 5 Or Pos = 8 : If WindowPosInfo\Position = 2 : xPos = WindowPosInfo\LeftX-WindowWidth(Window) : Else : xPos = GetSystemMetrics_(#SM_CXSCREEN)-WindowWidth(Window) : EndIf : EndIf ;right

  ResizeWindow(0, xPos, yPos, #PB_Ignore, #PB_Ignore)

EndProcedure

Have a nice day...
Franco