Set Requester Position ...
Posted: Mon Jun 23, 2003 10:31 am
...to init default position of requesters
or add optional parameter x,y
or add optional parameter x,y
http://www.purebasic.com
https://www.purebasic.fr/english/
The Problem is, that the API don't give the posibility (or only with much, much code)eddy wrote:...to init default position of requesters
or add optional parameter x,y
I used this to center a Requester (But you need the Window Name of it):PB wrote:All you need is some creative coding.
Code: Select all
; If you know the Window name of a Requester you can place it...
; (c) 2003 - Franco's Template - absolutely free
Procedure CenterFutureWindowThread(WindowTitle$)
Repeat
WindowID = FindWindow_(0,WindowTitle$)
Pos.RECT : GetWindowRect_(WindowID,Pos)
SetWindowPos_(WindowID,#HWND_TOPMOST,(GetSystemMetrics_(#SM_CXSCREEN)/2)-((Pos\right-Pos\left)/2),(GetSystemMetrics_(#SM_CYSCREEN)/2)-((Pos\bottom-Pos\top)/2),Pos\right-Pos\left,Pos\bottom-Pos\top, 0)
;MoveWindow_(WindowID,(GetSystemMetrics_(#SM_CXSCREEN)/2)-((Pos\right-Pos\left)/2),(GetSystemMetrics_(#SM_CYSCREEN)/2)-((Pos\bottom-Pos\top)/2),Pos\right-Pos\left,Pos\bottom-Pos\top, #TRUE)
ShowWindow_(WindowID,#SW_SHOW)
Until WindowID
EndProcedure
ThreadID=CreateThread(@CenterFutureWindowThread(),"Browse for Folder")
OpenProject$ = PathRequester("Select Directory:", Path$)
KillThread(ThreadID)
Code: Select all
Procedure CenterFutureWindowThread(WindowTitle)
WindowTitle$=PeekS(WindowTitle)
Repeat
WindowID = FindWindow_(0,WindowTitle$)
Pos.RECT : GetWindowRect_(WindowID,Pos)
SetWindowPos_(WindowID,#HWND_TOPMOST,50,50,300,400,0)
ShowWindow_(WindowID,#SW_SHOW)
Until WindowID
EndProcedure
ThreadID=CreateThread(@CenterFutureWindowThread(),@"Browse for Folder")
OpenProject$ = PathRequester("Select Directory:", Path$)
Debug OpenProject$
Franco was the alias I used to use in the old forum.
For MacOS you may use the following code to display a modal requester (NSAlert) at a specified position (successfully tested on MacOS 11.7 'Big Sur' with PB 6.00):fsw wrote: Mon Oct 24, 2022 1:37 am Now I'm on a Mac and could have used such code for macOS in the past.
Code: Select all
EnableExplicit
Define MenuBarHeight.CGFloat
Define Point.NSPoint
Define Requester.I
Define RequesterWindow.I
Define RequesterWindowFrame.NSRect
; ----- Create requester using NSAlert
Requester = CocoaMessage(0, CocoaMessage(0, 0, "NSAlert new"), "autorelease")
CocoaMessage(0, Requester, "setMessageText:$", @"Requester demo")
CocoaMessage(0, Requester, "setInformativeText:$",
@"This requester is displayed at position x=100 and y=100")
CocoaMessage(0, Requester, "addButtonWithTitle:$", @"OK")
Point\x = 100
; ----- Get height of menu bar
CocoaMessage(@MenuBarHeight.CGFloat, CocoaMessage(0, CocoaMessage(0, 0,
"NSApplication sharedApplication"), "mainMenu"), "menuBarHeight")
; ----- Calculate inverse y coordinate of requester
ExamineDesktops()
RequesterWindow = CocoaMessage(0, Requester, "window")
CocoaMessage(@RequesterWindowFrame, RequesterWindow, "frame")
Point\y = DesktopHeight(0) - MenuBarHeight - RequesterWindowFrame\size\height - 100
; ----- Display requester
CocoaMessage(0, RequesterWindow, "setFrameOrigin:@", @Point)
CocoaMessage(0, RequesterWindow, "makeKeyAndOrderFront:", 0)
CocoaMessage(0, Requester, "runModal")