Page 1 of 1

Open window at mouse position

Posted: Sat Mar 21, 2020 1:57 am
by BarryG
I need to open a tool-style, sizable window at the current mouse position BUT with the window's client top-left area where the mouse is (just like in the screenshot). I've done the code below, but I don't like how I have to add the hack of *2)+2 to the X position calculation. Is there a better non-hack way? I played around with ClientToScreen_() and so on, with no luck. Thanks.

Image

Code: Select all

GetCursorPos_(mouse.POINT)
flags=#PB_Window_Invisible|#PB_Window_Tool|#PB_Window_SizeGadget ; Must be these only.
hWnd=OpenWindow(0,0,0,100,50,"test",flags)
GetClientRect_(hWnd,inner.RECT)
GetWindowRect_(hWnd,outer.RECT)
x=((outer\left-inner\left)-(inner\left-outer\left))+(GetSystemMetrics_(#SM_CXSIZEFRAME)*2)+2
y=((outer\bottom-outer\top)-(inner\bottom-inner\top))-GetSystemMetrics_(#SM_CYSIZEFRAME)
SetWindowPos_(hWnd,#HWND_TOP,mouse\x-x,mouse\y-y,0,0,#SWP_NOSIZE|#SWP_SHOWWINDOW)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

Re: Open window at mouse position

Posted: Sat Mar 21, 2020 3:24 am
by RASHAD
Hi BarryG
Using native commands

Code: Select all

flags=#PB_Window_Invisible|#PB_Window_Tool|#PB_Window_SizeGadget ; Must be these only.
OpenWindow(0,0,0,100,50,"test",flags)
x = DesktopMouseX()-1 ;-1 To show the arrow icon
y = DesktopMouseY()-WindowY(0,#PB_Window_InnerCoordinate)+1
ResizeWindow(0,x,y,100,50)
HideWindow(0,0)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

Re: Open window at mouse position

Posted: Sat Mar 21, 2020 4:21 am
by BarryG
Man, I seriously overthink things sometimes! Thanks buddy.