Blue
I wrote the following code on AutoIt3, or rather there were two of them, one created a window in the visible area, the other centered it in the program and at the same time made it in the visible area, but apparently I did one code and not the second. When the dialog is centered, a problem arises if the window is partially moved off the screen, then the child window may appear off the screen and the user will not have access to it. You don’t see what is written there, it is possible to remove the disk from the OS, and the question is “Yes or No”, you press Enter expecting the worst consequences. You can't pull out the parent window because the child denies access to it until the child is closed, checkmate.
Try dragging the window off the screen and clicking the button
Code: Select all
EnableExplicit
Structure Rect2
x.l
y.l
w.l
h.l
EndStructure
;- Enumeration
Enumeration
#Win0
#Win_About
EndEnumeration
#w0_btn = 0
Global About$, ProgName$
Declare Win_About(ProgName$, Width = 270, Height = 170, WinID = -1)
ProgName$ = "ProgName"
About$ = "About"
;- GUI
OpenWindow(#Win0, 0, 0, 420, 300, "Win", #PB_Window_SizeGadget | #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget)
ButtonGadget(#w0_btn, 10, 10, 110, 30, About$)
;- Loop
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case #w0_btn
Win_About(ProgName$, 300, 220, #Win0)
EndSelect
Case #PB_Event_CloseWindow
CloseWindow(#Win0)
End
EndSelect
ForEver
Procedure ChildCoor(*gp.Rect2, nWnd, w, h, c=0, d=0)
Protected DX, DY
*gp\w = WindowWidth(nWnd)
*gp\h = WindowHeight(nWnd)
*gp\x = WindowX(nWnd)
*gp\y = WindowY(nWnd)
ExamineDesktops()
DX=DesktopWidth(0)
DY=DesktopHeight(0)
If c = 0
*gp\x=*gp\x+(*gp\w-w)/2
*gp\y=*gp\y+(*gp\h-h)/2
EndIf
If *gp\x+w+d>DX
*gp\x=DX-w-10-d
EndIf
If *gp\y+h+60+d>DY
*gp\y=DY-h-70-d
EndIf
If *gp\x<=d
*gp\x=d
EndIf
If *gp\y<=d
*gp\y=d
EndIf
*gp\w=w
*gp\h=h
EndProcedure
Procedure Win_About(ProgName$, Width = 270, Height = 170, WinID = -1)
Protected hWnd
Protected gp.Rect2
If WinID > -1
hWnd = WindowID(WinID)
DisableWindow(WinID, #True)
Else
hWnd = 0
EndIf
ChildCoor(@gp, #Win0, Width, Height, 0, 30)
If OpenWindow(#Win_About, gp\x, gp\y, gp\w, gp\h, About$, #PB_Window_SystemMenu | #PB_Window_TitleBar, WindowID(#Win0))
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
If hWnd
DisableWindow(WinID, #False)
EndIf
CloseWindow(#Win_About)
ProcedureReturn 0
EndIf
EndProcedure