It is currently Mon Apr 06, 2020 10:13 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Open window at mouse position
PostPosted: Sat Mar 21, 2020 1:57 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 668
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Open window at mouse position
PostPosted: Sat Mar 21, 2020 3:24 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3552
Hi BarryG
Using native commands
Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Open window at mouse position
PostPosted: Sat Mar 21, 2020 4:21 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 668
Man, I seriously overthink things sometimes! Thanks buddy.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye