WINDOWHASFOCUS: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:_WINDOWHASFOCUS}} The _WINDOWHASFOCUS function returns true (-1) if the current program's window has focus. Windows-only. {{PageSyntax}} : {{Parameter|hasFocus%%}} = _WINDOWHASFOCUS {{PageDescription}} * The function returns true (-1) if the current program is the topmost window on the user's desktop and has focus. If the current program is running behind another window, the function returns false (0). * Keywords_currently_not_supported_by_QB...")
 
No edit summary
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:_WINDOWHASFOCUS}}
{{DISPLAYTITLE:_WINDOWHASFOCUS}}
The [[_WINDOWHASFOCUS]] function returns true (-1) if the current program's window has focus. Windows-only.
The [[_WINDOWHASFOCUS]] function returns true (-1) if the current program's window has focus. Not supported for macOS.




Line 9: Line 9:
{{PageDescription}}
{{PageDescription}}
* The function returns true (-1) if the current program is the topmost window on the user's desktop and has focus. If the current program is running behind another window, the function returns false (0).
* The function returns true (-1) if the current program is the topmost window on the user's desktop and has focus. If the current program is running behind another window, the function returns false (0).
* [[Keywords_currently_not_supported_by_QB64#Keywords_Not_Supported_in_Linux_or_MAC_OSX_versions|Not available in macOS]].
* '''[[Keywords currently not supported by QB64#Keywords_not_supported_in_Linux_or_macOS_versions|Keyword not supported in macOS versions]]'''




==Availability==
{{PageAvailability}}
* '''Build 20170924/68'''.
<!-- QB64 = a version or none, QBPE = a version or all, Platforms = yes or no -->
<gallery widths="48px" heights="48px" mode="nolines">
File:Qb64.png|'''v1.2'''
File:Qbpe.png|'''all'''
File:Apix.png
File:Win.png|'''yes'''
File:Lnx.png|'''yes'''
File:Osx.png|'''no'''
</gallery>
<!-- additional availability notes go below here -->




{{PageExamples}}
{{PageExamples}}
''Example:'' Detecting if the current program has focus. Windows and Linux-only.
''Example:'' Detecting if the current program has focus. Windows and Linux-only.
{{CodeStart}} '' ''
{{CodeStart}}
DO
{{Cl|DO}}
     {{Cl|IF}} {{Cl|_WINDOWHASFOCUS}} THEN
     {{Cl|IF}} {{Cl|_WINDOWHASFOCUS}} THEN
         {{Cl|COLOR}} 15, 6
         {{Cl|COLOR}} 15, 6
Line 26: Line 35:
     {{Cl|ELSE}}
     {{Cl|ELSE}}
         {{Cl|COLOR}} 0, 7
         {{Cl|COLOR}} 0, 7
         CLS
         {{Cl|CLS}}
         PRINT "(ain't nobody looking...)"
         {{Cl|PRINT}} "(ain't nobody looking...)"
     {{Cl|END IF}}
     {{Cl|END IF}}
     {{Cl|_DISPLAY}}
     {{Cl|_DISPLAY}}
Line 37: Line 46:


{{PageSeeAlso}}
{{PageSeeAlso}}
* [https://qb64phoenix.com/forum/showthread.php?tid=1084 Featured in our "Keyword of the Day" series]
* [[_WINDOWHANDLE]]
* [[_SCREENEXISTS]]
* [[_SCREENEXISTS]]




{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 19:35, 24 May 2024

The _WINDOWHASFOCUS function returns true (-1) if the current program's window has focus. Not supported for macOS.


Syntax

hasFocus%% = _WINDOWHASFOCUS


Description

  • The function returns true (-1) if the current program is the topmost window on the user's desktop and has focus. If the current program is running behind another window, the function returns false (0).
  • Keyword not supported in macOS versions


Availability


Examples

Example: Detecting if the current program has focus. Windows and Linux-only.

DO
    IF _WINDOWHASFOCUS THEN
        COLOR 15, 6
        CLS
        PRINT "*** Hi there! ***"
    ELSE
        COLOR 0, 7
        CLS
        PRINT "(ain't nobody looking...)"
    END IF
    _DISPLAY
    _LIMIT 30
LOOP
Explanation: The program will display "*** Hi There! ***" while the window is the topmost and is being manipulated by the user. If another window, the taskbar or the desktop are clicked, the program window loses focus and the message "(ain't nobody looking...)" is displayed.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link