Check if active

General FreeBASIC programming questions.
Jawade
Posts: 224
Joined: Apr 25, 2008 19:13

Check if active

Postby Jawade » Apr 17, 2019 11:19

Is there a way to check if the program is the active window? And also too for graphics mode?
marcov
Posts: 2750
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: Check if active

Postby marcov » Apr 17, 2019 11:39

grindstone
Posts: 640
Joined: May 05, 2015 5:35
Location: Germany

Re: Check if active

Postby grindstone » Apr 17, 2019 12:39

Something like this?

Code: Select all

#Include "windows.bi"
#Include "win\psapi.bi"

Dim As HANDLE processhandle, hwnd
Dim As ULong PID
Dim As ZString*MAX_PATH filename

hwnd = GetActiveWindow()

If hwnd Then
   GetWindowThreadProcessId(hwnd, @PID)
   processHandle = OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, FALSE, PID)
   GetModuleFileNameEx(processHandle, NULL, filename, MAX_PATH)
   CloseHandle(processHandle)   
  If filename = Command(0) Then
     Print "active"
  Else
     Print "no"
  EndIf
Else
   Print "no active window"
EndIf

Sleep
Jawade
Posts: 224
Joined: Apr 25, 2008 19:13

Re: Check if active

Postby Jawade » Apr 18, 2019 9:17

Many thanks
jj2007
Posts: 1159
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Check if active

Postby jj2007 » Apr 18, 2019 16:57

On Windows, check the difference between GetActiveWindow, GetForegroundWindow and GetFocus.

Return to “General”

Who is online

Users browsing this forum: No registered users and 3 guests