Always on top

New to FreeBASIC? Post your questions here.
Post Reply
student1347
Posts: 49
Joined: Dec 16, 2011 3:48

Always on top

Post by student1347 »

Is there a way in freebasic to use left click when mouse pointer is outside of console window or program's screen and not allow the console or program's screen to be minimized and be Always on top and see the coordinates on the window when mouse moves and by clicking save mouse coordinates(x.y) in a file?
Thank you in advance.
Last edited by student1347 on Jun 05, 2017 15:34, edited 1 time in total.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Re: Always on top

Post by vdecampo »

Yes
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Re: Always on top

Post by vdecampo »

vdecampo wrote:Yes
Here is a start for your wish list. This will get the screen coordinates of the mouse whether inside or outside of the program window

Code: Select all

#Include "windows.bi"

Dim As POINT pt

Do
	
	If GetCursorPos(@pt) Then
		Print pt.x, pt.y
	End If
	
	Sleep 100	
Loop Until InKey=Chr(27)
-Vince
student1347
Posts: 49
Joined: Dec 16, 2011 3:48

Re: Always on top

Post by student1347 »

Thank you.... But when I left click the screen minimizes! (Not Always on top)
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Always on top

Post by fxm »

Code: Select all

#Include "windows.bi"

Dim As POINT pt
Dim As HWND handle

handle = GetConsoleWindow()
  
Do
   
   If GetCursorPos(@pt) Then
      Print pt.x, pt.y
   End If

   If GetForegroundWindow() <> handle then
      SetForegroundWindow(handle)
      SetFocus(handle)
   End If

   Sleep 100   
Loop Until InKey=Chr(27)
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Always on top

Post by fxm »

Version with a thread to force the foreground and the focus if necessary:

Code: Select all

#Include "windows.bi"

Dim As POINT pt

Dim As HWND handle

Dim As Any Ptr ht
Declare Sub Thread (Byval p As Any Ptr)
Dim Shared As Integer halt = 0

handle = GetConsoleWindow()
ht = Threadcreate(@Thread, handle)
  
Do
   
   If GetCursorPos(@pt) Then
      Print pt.x, pt.y
   End If

   Sleep 100
Loop Until InKey=Chr(27)

halt = 1
ThreadWait(ht)


Sub Thread (Byval p As Any Ptr)
   Do
      If GetForegroundWindow() <> p then
         SetForegroundWindow(p)
         SetFocus(p)
      End If
      Sleep 1
   Loop Until halt = 1
End Sub
[edit]
SLEEP was not inside the loop.
Last edited by fxm on Jun 06, 2017 12:46, edited 1 time in total.
student1347
Posts: 49
Joined: Dec 16, 2011 3:48

Re: Always on top

Post by student1347 »

As always thank you fxm.
student1347
Posts: 49
Joined: Dec 16, 2011 3:48

Re: Always on top

Post by student1347 »

Sorry.... and how can I retrieve mouse left click outside of the console window? GetMouse only retrieve mouse left click inside of the console window.(last part of my question)
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Re: Always on top

Post by vdecampo »

Code: Select all

#Include "windows.bi"

Dim As POINT pt

Do
   
   If GetCursorPos(@pt) Then
      Print pt.x, pt.y
   End If
   
   If GetAsyncKeyState(VK_LBUTTON) Then Print "Left Button Pressed"
   
   Sleep 100   
   
Loop Until InKey=Chr(27)
You can get a list of all the virtual key codes Here

-Vince
student1347
Posts: 49
Joined: Dec 16, 2011 3:48

Re: Always on top

Post by student1347 »

Thanks a lot....vdecampo
Post Reply