BACKGROUNDCOLOR: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
m (Protected "BACKGROUNDCOLOR" ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only autoconfirmed users] (indefinite)))
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:_BACKGROUNDCOLOR}}
{{DISPLAYTITLE:_BACKGROUNDCOLOR}}
The [[_BACKGROUNDCOLOR]] function returns the current background color.
The '''_BACKGROUNDCOLOR''' function returns the current background color for an image handle or page.




{{PageSyntax}}
{{PageSyntax}}
:{{Parameter|BGcolor&}} = [[_BACKGROUNDCOLOR]]
:{{Parameter|col~&}} = [[_BACKGROUNDCOLOR]] [({{Parameter|imageHandle&}})]


{{PageParameters}}
* If {{Parameter|imageHandle&}} is omitted, it is assumed to be the current write page or image designated by [[_DEST]].
* If {{Parameter|imageHandle&}} is an invalid handle, an [[ERROR Codes|Invalid handle]] error occurs. Check handle values first. Zero designates the current screen.




{{PageDescription}}
{{PageDescription}}
* Use it to get the current background color to restore later in a program.
* Use it to get the current background color to restore it later in a program.
* Returns the closest attribute value of the background color.
* In legacy [[SCREEN]] modes and in [[_NEWIMAGE]] 256 colors mode the color attribute/palette index is returned.
* In [[_NEWIMAGE]] 32-bit mode the [[_RGBA32]] value ('''&H00{{Text|00|red}}{{Text|00|green}}{{Text|00|blue}}''' to '''&HFF{{Text|FF|red}}{{Text|FF|green}}{{Text|FF|blue}}''') is returend, make sure to store it in an [[_UNSIGNED]] [[LONG]] variable (as seen in the syntax above with the '''~&''' suffix), otherwise the blue component may be lost.




{{PageExamples}}
{{PageExamples}}
''Example 1:'' Storing a background color for later use.
;Example:Storing the background color for later use.
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|SCREEN}} 0
{{Cl|SCREEN}} {{Text|0|#F580B1}}
{{Cl|COLOR}} 1, 3
{{Cl|COLOR}} {{Text|1|#F580B1}}, {{Text|3|#F580B1}} {{Text|<nowiki>'set color 1 as foreground, color 3 as background</nowiki>|#919191}}
{{Cl|CLS}}
BG% = {{Cl|_BACKGROUNDCOLOR}}
{{Cl|PRINT}} BG%
{{CodeEnd}}
{{OutputStartBG3}}{{Text|3|#0000aa}}
{{OutputEnd}}
 
 
''Example 2:'' Understanding the function output
{{CodeStart}} '' ''
{{Cl|SCREEN}} 0
{{Cl|COLOR}} 1, 11
{{Cl|CLS}}
{{Cl|CLS}}
BG% = {{Cl|_BACKGROUNDCOLOR}}
col~& = {{Cl|_BACKGROUNDCOLOR}}
{{Cl|PRINT}} BG%                  'prints the attribute as 3 instead of 11
{{Cl|PRINT}} col~&
{{CodeEnd}}
{{CodeEnd}}
{{OutputStartBG3}}{{Text|3|#0000aa}}
{{OutputStartBG3}}
{{Text|3|#0000aa}}
{{OutputEnd}}
{{OutputEnd}}
:''Explanation: SCREEN 0 background colors over 7 will return the lower intensity color attribute values: EX: attribute - 8




{{PageSeeAlso}}
{{PageSeeAlso}}
* [[_DEFAULTCOLOR]]
* [[_DEFAULTCOLOR]]
* [[COLOR]], [[SCREEN]]
* [[COLOR]], [[_DEST]]
* [[SCREEN (function)]]
* [[SCREEN]], [[SCREEN (function)]]
* [[Windows_Libraries#Color_Dialog_Box|Color Dialog Box]]
* [[Windows Libraries#Color_Dialog_Box|Color Dialog Box]]




{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 16:19, 19 March 2023

The _BACKGROUNDCOLOR function returns the current background color for an image handle or page.


Syntax

col~& = _BACKGROUNDCOLOR [(imageHandle&)]


Parameters

  • If imageHandle& is omitted, it is assumed to be the current write page or image designated by _DEST.
  • If imageHandle& is an invalid handle, an Invalid handle error occurs. Check handle values first. Zero designates the current screen.


Description

  • Use it to get the current background color to restore it later in a program.
  • In legacy SCREEN modes and in _NEWIMAGE 256 colors mode the color attribute/palette index is returned.
  • In _NEWIMAGE 32-bit mode the _RGBA32 value (&H00000000 to &HFFFFFFFF) is returend, make sure to store it in an _UNSIGNED LONG variable (as seen in the syntax above with the ~& suffix), otherwise the blue component may be lost.


Examples

Example
Storing the background color for later use.
SCREEN 0
COLOR 1, 3 'set color 1 as foreground, color 3 as background
CLS
col~& = _BACKGROUNDCOLOR
PRINT col~&
3


See also



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