admin 管理员组

文章数量: 1184232

前言

	电脑没找到调节亮度在哪里,网上查找了一些资料模仿写了一个简单的,记录一下方便以后使用。

提示:以下是本篇文章正文内容,下面案例可供参考

1.效果展示( 尝试了GIF、录屏、截图都没法记录屏幕亮度变化的画面,这里只能用手机录像 )




2.CGammaRamp.h

代码如下(示例):

#ifndefGAMMARAMP_H_#defineGAMMARAMP_H_/*
CGammaRamp class
Encapsulates the Gamma Ramp API and changes the brightness of 
the entire screen.
Written by Nir Sofer.
*/
class CGammaRamp
{
   
   
protected:
	HMODULE hGDI32;
	HDC hScreenDC;typedefBOOL(WINAPI *Type_SetDeviceGammaRamp)(HDC hDC, LPVOID lpRamp);
	Type_SetDeviceGammaRamp pGetDeviceGammaRamp;
	Type_SetDeviceGammaRamp pSetDeviceGammaRamp;
public:CGammaRamp();~CGammaRamp();
	BOOL LoadLibrary();voidFreeLibrary();
	BOOL LoadLibraryIfNeeded();
	BOOL SetDeviceGammaRamp(HDC hDC, LPVOID lpRamp);
	BOOL GetDeviceGammaRamp(HDC hDC, LPVOID lpRamp);
	BOOL SetBrightness(HDC hDC, WORD wBrightness);};#endif

3.CGammaRamp.cpp

代码如下(示例):

#include<windows.h>#include"gammaramp.h"/*
CGammaRamp class
Encapsulates the Gamma Ramp API and changes the brightness of 
the entire screen.
Written by Nir Sofer.
*/
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(TEXT("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 CGammaRa

本文标签: 代码如下 示例 编程