Hi all.
I have the following code in Visual C++ 6.0.
to dim the screen.
I know there is wmi but I use a TV that doesn't work.
This code works fine but I would like to be able to make the screen darker.

GammaRamp.cpp
Code:
#include <windows.h>
#include "gammaramp.h"
#include <cmath>

/*
CGammaRamp class

Encapsulates the Gamma Ramp API and changes the brightness of 
the entire screen.

Written by Nir Sofer.
http://www.nirsoft.net


*/

CGammaRamp::CGammaRamp()
{
	//Initialize all variables.
	hGDI32 = NULL;
	hScreenDC = NULL;
	pGetDeviceGammaRamp = NULL;
	pSetDeviceGammaRamp = NULL;
}


CGammaRamp::~CGammaRamp()
{
	FreeLibrary();
}


BOOL CGammaRamp::LoadLibrary()
{
	BOOL bReturn = FALSE;

	FreeLibrary();
	//Load the GDI library.
	hGDI32 = ::LoadLibrary("gdi32.dll");
	if (hGDI32 != NULL)
	{
		//Get the addresses of GetDeviceGammaRamp and SetDeviceGammaRamp API functions.
		pGetDeviceGammaRamp = (Type_SetDeviceGammaRamp)GetProcAddress(hGDI32, "GetDeviceGammaRamp");
		pSetDeviceGammaRamp = (Type_SetDeviceGammaRamp)GetProcAddress(hGDI32, "SetDeviceGammaRamp");
		
		//Return TRUE only if these functions exist.
		if (pGetDeviceGammaRamp == NULL || pSetDeviceGammaRamp == NULL)
			FreeLibrary();
		else
			bReturn = TRUE;
	}

	return bReturn;
}


void CGammaRamp::FreeLibrary()
{
	//Free the GDI library.
	if (hGDI32 != NULL) 
	{
		::FreeLibrary(hGDI32);
		hGDI32 = NULL;
	}
}


BOOL CGammaRamp::LoadLibraryIfNeeded()
{
	BOOL bReturn = FALSE;

	if (hGDI32 == NULL)
		LoadLibrary();

	if (pGetDeviceGammaRamp != NULL && pSetDeviceGammaRamp != NULL)
		bReturn = TRUE;

	return bReturn;
}


BOOL CGammaRamp::SetDeviceGammaRamp(HDC hDC, LPVOID lpRamp)
{
	//Call to SetDeviceGammaRamp only if this function is successfully loaded.
	if (LoadLibraryIfNeeded())
	{
		return pSetDeviceGammaRamp(hDC, lpRamp);
	}
	else
		return FALSE;
}


BOOL CGammaRamp::GetDeviceGammaRamp(HDC hDC, LPVOID lpRamp)
{
	//Call to GetDeviceGammaRamp only if this function is successfully loaded.
	if (LoadLibraryIfNeeded())
	{
		return pGetDeviceGammaRamp(hDC, lpRamp);
	}
	else
		return FALSE;

}


BOOL CGammaRamp::SetBrightness(HDC hDC, WORD wBrightness)
{
	/*
	Changes the brightness of the entire screen.
	This function may not work properly in some video cards.

	The wBrightness value should be a number between 0 and 255.
	128 = Regular brightness
	above 128 = brighter
	below 128 = darker

    If hDC is NULL, SetBrightness automatically load and release 
	the display device context for you.

	*/
	BOOL bReturn = FALSE;
	HDC hGammaDC = hDC;

	//Load the display device context of the entire screen if hDC is NULL.
	if (hDC == NULL)
		hGammaDC = GetDC(NULL);

	if (hGammaDC != NULL)
	{
		//Generate the 256-colors array for the specified wBrightness value.
		WORD GammaArray[3][256];

		for (int iIndex = 0; iIndex < 256; iIndex++)
		{
			int iArrayValue = iIndex * (wBrightness + 128);

			if (iArrayValue > 65535)
				iArrayValue = 65535;

			GammaArray[0][iIndex] = 
			GammaArray[1][iIndex] = 
			GammaArray[2][iIndex] = (WORD)iArrayValue;
			
		}

		//Set the GammaArray values into the display device context.
		bReturn = SetDeviceGammaRamp(hGammaDC, GammaArray);
	}

	if (hDC == NULL)
		ReleaseDC(NULL, hGammaDC);

	return bReturn;
}


BOOL CGammaRamp::SetBrightness2(HDC hDC, WORD wBrightness, float fContrast)
{
	/*
	Changes the brightness of the entire screen.
	This function may not work properly in some video cards.

	The wBrightness value should be a number between 0 and 255.
	128 = Regular brightness
	above 128 = brighter
	below 128 = darker

    If hDC is NULL, SetBrightness automatically load and release 
	the display device context for you.

	*/
	BOOL bReturn = FALSE;
	HDC hGammaDC = hDC;

	//Load the display device context of the entire screen if hDC is NULL.
	if (hDC == NULL)
		hGammaDC = GetDC(NULL);

	if (hGammaDC != NULL)
	{
		//Generate the 256-colors array for the specified wBrightness value.
		WORD GammaArray[3][256];

		for (int iIndex = 0; iIndex < 256; iIndex++)
		{
            int iArrayValue = iIndex * (wBrightness + 128) - 32768;

            // Ajusta el valor para el contraste
            iArrayValue = (int)(iArrayValue * fContrast) + 32768;

            // Asegura que el valor esté en el rango permitido
            if (iArrayValue < 0)
                iArrayValue = 0;
            else if (iArrayValue > 65535)
                iArrayValue = 65535;

            GammaArray[0][iIndex] =
                GammaArray[1][iIndex] =
                GammaArray[2][iIndex] = (WORD)iArrayValue;
			
		}

		//Set the GammaArray values into the display device context.
		bReturn = SetDeviceGammaRamp(hGammaDC, GammaArray);
	}

	if (hDC == NULL)
		ReleaseDC(NULL, hGammaDC);

	return bReturn;
}

BOOL CGammaRamp::SetBrightness3(HDC hDC, WORD wBrightness)
{
    BOOL bReturn = FALSE;
    HDC hGammaDC = hDC;

    // Load the display device context of the entire screen if hDC is NULL.
    if (hDC == NULL)
        hGammaDC = GetDC(NULL);

    if (hGammaDC != NULL)
    {
        // Generate the 256-colors array for the specified wBrightness value.
        WORD GammaArray[3][256];

        for (int iIndex = 0; iIndex < 256; iIndex++)
        {
            int iArrayValue = iIndex * (wBrightness + 128);

            if (iArrayValue > 65535)
                iArrayValue = 65535;

            // Adjusting not only brightness but also making the color darker (towards black).
			GammaArray[0][iIndex] =
			GammaArray[1][iIndex] =
			GammaArray[2][iIndex] = static_cast<WORD>((iArrayValue - 32768) > 0 ? (iArrayValue - 32768) / 257 : 0);  // Adjust towards black
        }
									//(WORD)iArrayValue;
        // Set the GammaArray values into the display device context.
        bReturn = SetDeviceGammaRamp(hGammaDC, GammaArray);
    }

    if (hDC == NULL)
        ReleaseDC(NULL, hGammaDC);

    return bReturn;
}


BOOL CGammaRamp::SetDimmerOverlay(HDC hDC, int dimmerOpacity)
{
	BOOL bReturn = FALSE;
    HDC hGammaDC = GetDC(NULL);

    if (hGammaDC != NULL)
    {
        // Generate the 256-colors array for darkening the screen.
        WORD GammaArray[3][256];

        for (int iIndex = 0; iIndex < 256; iIndex++)
        {
            // Set all color channels to a darkened value based on dimmer opacity
            int iArrayValue = iIndex * dimmerOpacity / 100;

            GammaArray[0][iIndex] =
                GammaArray[1][iIndex] =
                GammaArray[2][iIndex] = (WORD)iArrayValue;
        }

        // Set the GammaArray values into the display device context.
        bReturn = SetDeviceGammaRamp(hGammaDC, GammaArray);
    }

    // Release the device context
    ReleaseDC(NULL, hGammaDC);

	return bReturn;
}

BOOL CGammaRamp::SetBrightness4(HDC hDC, WORD wBrightness, float fContrast)
{
    /*
    Changes the brightness and contrast of the entire screen.
    This function may not work properly in some video cards.

    The wBrightness value should be a number between 0 and 255.
    128 = Regular brightness
    above 128 = brighter
    below 128 = darker

    If hDC is NULL, SetBrightness automatically loads and releases 
    the display device context for you.
    */
    BOOL bReturn = FALSE;
    HDC hGammaDC = hDC;

    // Load the display device context of the entire screen if hDC is NULL.
    if (hDC == NULL)
        hGammaDC = GetDC(NULL);

    if (hGammaDC != NULL)
    {
        // Generate the 256-colors array for the specified wBrightness value.
        WORD GammaArray[3][256];

        for (int iIndex = 0; iIndex < 256; iIndex++)
        {
            int iArrayValue = iIndex * (wBrightness + 128) - 32768;

            // Adjust the value for contrast
            iArrayValue = (int)(iArrayValue * fContrast) + 32768;

            // Reduce brightness (make it darker) even when wBrightness > 0
            iArrayValue = (int)(iArrayValue * 0.8);  // You can adjust the factor for further darkness

            // Ensure that the value is in the allowed range
            if (iArrayValue < 0)
                iArrayValue = 0;
            else if (iArrayValue > 65535)
                iArrayValue = 65535;

            GammaArray[0][iIndex] =
                GammaArray[1][iIndex] =
                GammaArray[2][iIndex] = (WORD)iArrayValue;
        }

        // Set the GammaArray values into the display device context.
        bReturn = SetDeviceGammaRamp(hGammaDC, GammaArray);
    }

    if (hDC == NULL)
        ReleaseDC(NULL, hGammaDC);

    return bReturn;
}
GammaRamp.h
Code:
#ifndef GAMMARAMP_H_
#define GAMMARAMP_H_


/*
CGammaRamp class

Encapsulates the Gamma Ramp API and changes the brightness of 
the entire screen.

Written by Nir Sofer.
http://www.nirsoft.net


*/

class CGammaRamp
{
protected:
	HMODULE hGDI32;
	HDC hScreenDC;
	typedef BOOL (WINAPI *Type_SetDeviceGammaRamp)(HDC hDC, LPVOID lpRamp);

	Type_SetDeviceGammaRamp pGetDeviceGammaRamp;
	Type_SetDeviceGammaRamp pSetDeviceGammaRamp;

public:

	CGammaRamp();
	~CGammaRamp();
	BOOL LoadLibrary();
	void FreeLibrary();
	BOOL LoadLibraryIfNeeded();
	BOOL SetDeviceGammaRamp(HDC hDC, LPVOID lpRamp);
	BOOL GetDeviceGammaRamp(HDC hDC, LPVOID lpRamp);
	BOOL SetBrightness(HDC hDC, WORD wBrightness);
	BOOL SetBrightness2(HDC hDC, WORD wBrightness, float fContrast);
	BOOL SetBrightness3(HDC hDC, WORD wBrightness);
	BOOL SetBrightness4(HDC hDC, WORD wBrightness, float fContrast);
	BOOL SetDimmerOverlay(HDC hDC, int dimmerOpacity);
};
#endif
main.cpp
Code:
#include <windows.h>
#include "gammaramp.h"
#include "windows.h"
#include <shellapi.h>
#include <stdio.h>
#include <process.h>
#include <tchar.h>
#include <iostream>
#include <cstdlib>


int WINAPI WinMain(
  HINSTANCE hInstance,      // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,          // command line
  int nCmdShow              // show state
)
{
	//Example for changing the brightness with CGammaRamp class:
	//Be aware that this exmaple may not work properly in all
	//Video cards.
    int argc;
    LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
    if (argv == NULL) {
        wprintf(L"CommandLineToArgvW failed\n");
        return 1;
    }
    for (int i = 0; i < argc; i++) {
        wprintf(L"Argument %d: %s\n", i, argv[i]);
    }

	int number = _wtoi(argv[1]);
    // Don't forget to free the allocated memory
    LocalFree(argv);
	int start = 5;

	std::cout << "Another instance is already running." << std::endl;
	CGammaRamp GammaRamp;


        GammaRamp.SetBrightness(NULL, number);
	return 0;
}
Greetings, thank you