Check if active

General FreeBASIC programming questions.
Post Reply
Jawade
Posts: 228
Joined: Apr 25, 2008 19:13

Check if active

Post by Jawade »

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

Re: Check if active

Post by marcov »

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

Re: Check if active

Post by grindstone »

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: 228
Joined: Apr 25, 2008 19:13

Re: Check if active

Post by Jawade »

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

Re: Check if active

Post by jj2007 »

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