Always on top

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

Always on top

Postby student1347 » Jun 05, 2017 15:16

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: 2980
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Re: Always on top

Postby vdecampo » Jun 05, 2017 15:19

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

Re: Always on top

Postby vdecampo » Jun 05, 2017 15:44

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: 47
Joined: Dec 16, 2011 3:48

Re: Always on top

Postby student1347 » Jun 05, 2017 16:06

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

Re: Always on top

Postby fxm » Jun 05, 2017 16:29

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
Posts: 7492
Joined: Apr 22, 2009 12:46
Location: Paris suburb, FRANCE

Re: Always on top

Postby fxm » Jun 05, 2017 16:45

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: 47
Joined: Dec 16, 2011 3:48

Re: Always on top

Postby student1347 » Jun 05, 2017 16:53

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

Re: Always on top

Postby student1347 » Jun 06, 2017 18:08

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: 2980
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Re: Always on top

Postby vdecampo » Jun 06, 2017 18:49

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: 47
Joined: Dec 16, 2011 3:48

Re: Always on top

Postby student1347 » Jun 06, 2017 19:11

Thanks a lot....vdecampo

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 2 guests