TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) /* konstruktor klasy formularza */
: TForm(Owner)
{
hGDI32 = NULL;
tSetDevBright = NULL;
}
//---------------------------------------------------------------------------
void TForm1::LoadLibrary()
{
FreeLibrary();
hGDI32 = ::LoadLibrary(L"gdi32.dll");
if(hGDI32 != NULL)
{
tSetDevBright = (TypSetDevBright)GetProcAddress(hGDI32, "SetDeviceGammaRamp");
if(tSetDevBright == NULL) FreeLibrary();
}
}
//---------------------------------------------------------------------------
void TForm1::FreeLibrary()
{
if(hGDI32 != NULL)
{
::FreeLibrary(hGDI32);
hGDI32 = NULL;
}
}
//---------------------------------------------------------------------------
void TForm1::ChangeBrightness(HDC hDC, int Brightness)
{
HDC hGDC = hDC;
if(hDC == NULL) hGDC = GetDC(NULL); /* NULL = uchwyt do ekranu */
if(hGDC != NULL)
{
unsigned short gArray[3][256];
for (int x = 0; x < 256; x++)
{
int aValue = x * (Brightness + 128);
if(aValue > 65535) aValue = 65535;
gArray[0][x] = gArray[1][x] = gArray[2][x] = (USHORT)aValue;
}
if(hGDI32 == NULL) LoadLibrary();
if(tSetDevBright != NULL) tSetDevBright(hGDC, gArray);
}
if (hDC == NULL) ReleaseDC(NULL, hGDC);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender) /* zdarzenie OnClick - zmiana jasności */
{
static int brightness = 128;
if(brightness == 128) brightness = 256;
else brightness = 128;
ChangeBrightness(NULL, brightness);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
FreeLibrary();
}