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);};#endif3.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版权声明:本文标题:掌握显示控制权:C++结合GDI32.dll实现流畅的亮度调整 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1772249890a3553807.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论