⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 faq26.htm

📁 C++builder学习资料C++builder
💻 HTM
字号:


<HTML>

<HEAD>

   <TITLE>Determine the color resolution of screen(256 color, 16 bit, etc)</TITLE>

   <META NAME="Author" CONTENT="Harold Howe">

</HEAD>

<BODY BGCOLOR="WHITE">



<CENTER>

<TABLE  BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="640">



<TR>

<TD>







<H3>

Determine the color resolution of screen(256 color, 16 bit, etc)

</H3>

<P>

 The API <TT>GetDeviceCaps</TT> function allows you to determine

the color resolution of the screen. <TT>GetDeviceCaps</TT> takes two arguments;

a handle to a device context and an identifier for the parameter that you want

to find.

</P>

<pre>

<b>int</b> GetDeviceCaps<b>(</b> HDC hdc<b>,</b>       <font color="navy">// device-context handle</font>

                   <b>int</b> nIndex<b>)</b><b>;</b>   <font color="navy">// parameter index</font>

</pre>

<P>

In order to call <TT>GetDeviceCaps</TT>, you must provide a handle to a device

context. In other programming environments, you would have to create a DC just

for the sake of calling <TT>GetDeviceCaps</TT>, but in BCB, you can just borrow

the <TT>Handle</TT> property of the form's <TT>Canvas</TT> property. To get the

color resolution, you pass either <TT>BITSPIXEL</TT> or <TT>PLANES</TT> as the

index value. <TT>BITSPIXEL</TT> returns the number of bits used to store the

color of a single pixel. <TT>PLANES</TT> returns the number of color planes

used by the system. Most systems use one color plane and multiple bits to

represent the color of a pixel. Some systems use one pixel with multiple color

planes. Either way, one of the values will be one. You can multiply the return

values to yield one value that represents the color resolution of the system.

</P>

<P>

The following code snippet demonstrates how to determine the color resolution

of the system. As a bonus, it also shows how <TT>GetDeviceCaps</TT> can tell you

directly if a system is using palettes.

</P>

<pre>

<b>int</b> BitsPerPixel  <b>=</b> GetDeviceCaps<b>(</b>Canvas<b>-></b>Handle<b>,</b>BITSPIXEL<b>)</b><b>;</b>

<b>int</b> Planes        <b>=</b> GetDeviceCaps<b>(</b>Canvas<b>-></b>Handle<b>,</b>PLANES<b>)</b><b>;</b>

BitsPerPixel <b>*</b><b>=</b> Planes<b>;</b> <font color="navy">// either Planes or BitsPerPixel will be</font>

                        <font color="navy">// equal to 1, so eliminate one of the values.</font>

<b>bool</b> UsesPalettes <b>=</b>

     <b>(</b><b>bool</b><b>)</b><b>(</b>GetDeviceCaps<b>(</b>Canvas<b>-></b>Handle<b>,</b> RASTERCAPS<b>)</b> <b>&</b> RC_PALETTE<b>)</b><b>;</b>

<b>if</b><b>(</b>UsesPalettes<b>)</b>

  Label1<b>-></b>Caption <b>=</b> <font color="blue">"The screen utilizes palettes"</font><b>;</b>

<b>else</b>

  Label1<b>-></b>Caption <b>=</b> <font color="blue">"The screen does not use palettes"</font><b>;</b>



<b>switch</b> <b>(</b>BitsPerPixel<b>)</b>

<b>{</b>

  <b>case</b> <font color="blue">24</font><b>:</b>

    Label2<b>-></b>Caption <b>=</b> <font color="blue">"24-bit true color"</font><b>;</b>

    <b>break</b><b>;</b>

  <b>case</b> <font color="blue">16</font><b>:</b>

    Label2<b>-></b>Caption <b>=</b> <font color="blue">"16-bit high color"</font><b>;</b>

    <b>break</b><b>;</b>

  <b>case</b> <font color="blue">8</font><b>:</b>

    Label2<b>-></b>Caption <b>=</b> <font color="blue">"256 color mode"</font><b>;</b>

    <b>break</b><b>;</b>

  <b>case</b> <font color="blue">4</font><b>:</b>

    Label2<b>-></b>Caption <b>=</b> <font color="blue">"16 color mode"</font><b>;</b>

    <b>break</b><b>;</b>

  <b>case</b> <font color="blue">1</font><b>:</b>

    Label2<b>-></b>Caption <b>=</b> <font color="blue">"Monochrome mode"</font><b>;</b>

    <b>break</b><b>;</b>

  <b>default</b><b>:</b>

    Label2<b>-></b>Caption <b>=</b> <font color="blue">"The screen supports "</font> <b>+</b> IntToStr<b>(</b><font color="blue">1</font><b><<</b> BitsPerPixel<b>)</b> <b>+</b>

                      <font color="blue">" different colors"</font><b>;</b>

    <b>break</b><b>;</b>

<b>}</b>

</pre>





</TD> </TR>



</TABLE>

</CENTER>

</BODY>

</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -