Page 1 of 1

Set Requester Position ...

Posted: Mon Jun 23, 2003 10:31 am
by eddy
...to init default position of requesters

or add optional parameter x,y

Re: SetRequesterPosition

Posted: Mon Jun 23, 2003 11:42 am
by GPI
eddy wrote:...to init default position of requesters

or add optional parameter x,y
The Problem is, that the API don't give the posibility (or only with much, much code)

Re: SetRequesterPosition

Posted: Mon Jun 23, 2003 3:06 pm
by PB
> ...to init default position of requesters

All the requesters are based on API calls, as GPI said. For Fred to make
them open in an X-Y position, he'd have to create custom requesters.

There are ways to force the position of some of them, for example:

viewtopic.php?t=6278

All you need is some creative coding. :wink:

Re: SetRequesterPosition

Posted: Tue Jun 24, 2003 11:40 pm
by fsw
PB wrote:All you need is some creative coding. :wink:
I used this to center a Requester (But you need the Window Name of it):

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)


Posted: Wed Jun 25, 2003 10:48 am
by eddy
fantastic :)

I prefer the first solution because it works even if your OS is in french,english or german
I'll try to improve it.

Re: Set Requester Position ...

Posted: Wed Oct 19, 2022 10:09 am
by BarryG
Franco and fsw's code updated for 2022:

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$

Re: Set Requester Position ...

Posted: Mon Oct 24, 2022 1:37 am
by fsw
That's really old Windows code, glad it still works.
Now I'm on a Mac and could have used such code for macOS in the past.
:cry:
BarryG wrote: Wed Oct 19, 2022 10:09 am Franco and fsw's code updated for 2022:
Franco was the alias I used to use in the old forum.
Before this forum there was another one but something happened to it.
Fred was able to rescue the content but not the users names...

Re: Set Requester Position ...

Posted: Mon Oct 24, 2022 9:52 am
by Shardik
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.
:cry:
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):

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")

Re: Set Requester Position ...

Posted: Wed Oct 26, 2022 6:48 am
by fsw
This works nice.
Thank you Shardik.

Re: Set Requester Position ...

Posted: Wed Oct 26, 2022 6:12 pm
by davido
@Shardik,
Excellent.
Thank you.