Open window at mouse position

Windows specific forum
BarryG
Addict
Addict
Posts: 3320
Joined: Thu Apr 18, 2019 8:17 am

Open window at mouse position

Post 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
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4662
Joined: Sun Apr 12, 2009 6:27 am

Re: Open window at mouse position

Post 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
Egypt my love
BarryG
Addict
Addict
Posts: 3320
Joined: Thu Apr 18, 2019 8:17 am

Re: Open window at mouse position

Post by BarryG »

Man, I seriously overthink things sometimes! Thanks buddy.
Post Reply