Set Requester Position ...

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Set Requester Position ...

Post by eddy »

...to init default position of requesters

or add optional parameter x,y
Last edited by eddy on Wed Jun 25, 2003 10:51 am, edited 1 time in total.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: SetRequesterPosition

Post 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)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: SetRequesterPosition

Post 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:
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: SetRequesterPosition

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


I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post 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.
BarryG
Addict
Addict
Posts: 4123
Joined: Thu Apr 18, 2019 8:17 am

Re: Set Requester Position ...

Post 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$
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Set Requester Position ...

Post 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...

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Set Requester Position ...

Post 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")
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Set Requester Position ...

Post by fsw »

This works nice.
Thank you Shardik.

I am to provide the public with beneficial shocks.
Alfred Hitshock
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Set Requester Position ...

Post by davido »

@Shardik,
Excellent.
Thank you.
DE AA EB
Post Reply