Odczyt liczby kolorów używanych przez Windowsa

Aby po kliknięciu przycisku Button1 na etykiecie Label wyświetlić liczbę kolorów używanych przez Windows:

Unit1.cpp

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   HDC DC;
   DC = GetDC(0);

   switch (GetDeviceCaps(DC, PLANES) * GetDeviceCaps(DC, BITSPIXEL))
   {
      case 1:  Label1->Caption = "Monochrome";          break;
      case 4:  Label1->Caption = "16 kolorów";          break;
      case 8:  Label1->Caption = "256 kolorów";         break;
      case 16: Label1->Caption = "True Color 16 bitów"; break;
      case 24: Label1->Caption = "True Color 24 bity";  break;
      case 32: Label1->Caption = "True Color 32 bity";  break;
   }

   ReleaseDC(0, DC);
}



29-03-2001

Drugi sposób, aby po kliknięciu przycisku Button1 na etykiecie Label wyświetlić liczbę kolorów używanych przez Windows:

Unit1.cpp

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   int BitsPerPixel = GetDeviceCaps(Canvas->Handle, BITSPIXEL);
   int Planes = GetDeviceCaps(Canvas->Handle, PLANES);
   BitsPerPixel *= Planes;

   switch (BitsPerPixel)
   {
      case 32: Label1->Caption = "24-bit true color"; break;
      case 24: Label1->Caption = "24-bit true color"; break;
      case 16: Label1->Caption = "16-bit high color"; break;
      case 8:  Label1->Caption = "Tryb 256-kolorowy"; break;
      case 4:  Label1->Caption = "Tryb 16-kolorowy";  break;
      case 1:  Label1->Caption = "Tryb czarno-biały"; break;
      default:
         Label1->Caption = "Tryb pozwala na wyświetlania" +
                           IntToStr(1 << BitsPerPixel) +
                           " różnych kolorów"; break;
}