Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
#Include "Win32API.inc"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Rollup + Edge Avoidance",300,300,250,200, %WS_OverlappedWindow To hDlg
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Static oldH As Long '<--- oldH is the pre-rollup height of the dialog
Local w,h As Long
Select Case Cb.Msg
Case %WM_InitDialog
Dialog Get Client hDlg To w,oldH
Case %WM_NCLButtonDblClk
Dialog Get Client hDlg To w,h
Dialog Set Client hDlg, w, IIf(h<10,oldH,0)
oldH = IIf(h<10,oldH,h)
AvoidDesktopEdges
Function = 1
End Select
End Function
Sub AvoidDesktopEdges
Static oldX, oldY, Avoided As Long '<--- Avoided tells me if the current position was due to edge avoidance
Local x,y,deskW,deskH,wSize,hSize As Long
Dialog Get Size hDlg To wSize,hSize
Dialog Get Loc hDlg To x,y
'Desktop Get Client To deskW, deskH '<--- handles single monitor
deskW = GetSystemMetrics( %SM_CXVIRTUALSCREEN ) '<--- handles dual monitors of same size
deskH = GetSystemMetrics( %SM_CYVIRTUALSCREEN ) '<--- handles dual monitors of same size
If hSize < (Metrics(Caption)+10) Then
If Avoided Then Dialog Set Loc hDlg, oldX, oldY
Avoided = 0
Else
'avoid desktop edge
If (x+wSize>deskW) Or (y+hSize>deskH) Then
oldX = x : oldY = y
If x + wSize > deskW Then x = deskW - wSize - 20
If y + hSize > deskH Then y = deskH - hSize - 20
Dialog Set Loc hDlg, x,y '<--- move away from the edge
Avoided = 1 '<--- says I moved away from the edge
Else
Avoided = 0 '<--- says I did not have to move away from the edge
End If
End If
End Sub
'gbs_01205
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm