Open window at mouse position
Posted: Sat Mar 21, 2020 1:57 am
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.


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