Hi
This question is outside the scope of this site and needs to be asked either on the Technet or MSDN forums.
**http://social.technet.microsoft.com/Forums/en-us/home**
**http://social.msdn.microsoft.com/Forums/en-US/home**
Regards
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am creating an app in Qt ( Its a cross platform IDE ) in which i want to add the feature of changing screen brightness but when i call GetMonitorBrightness function it returns false and i don't know why. Maybe my code is not right i don't know please help me to fix this.
And i have only monitor so there is no need of calling GetNumberOFPhyscialMonitors function right ??
My Code :
void EyeCare::on_startcaringButton_clicked()
{
HMONITOR monitorHandler = NULL ;
LPDWORD minBrightnessLevel = NULL , maxBrightnessLevel = NULL,
currentBrightnessLevel = NULL ;
HWND windowHandler ;
windowHandler = FindWindow(NULL,NULL) ;
monitorHandler = MonitorFromWindow(windowHandler, MONITOR_DEFAULTTOPRIMARY) ;
if (GetMonitorBrightness(monitorHandler,minBrightnessLevel,
currentBrightnessLevel, maxBrightnessLevel) ){
DWORD newBrightnessLevel = (*maxBrightnessLevel) - 50 ; // my current brightness is 100%
SetMonitorBrightness(monitorHandler,newBrightnessLevel) ;
SaveCurrentMonitorSettings(monitorHandler) ;
style.append("color: green ;") ;
}else
style.append("color: red ;") ;
ui->startcaringButton->setStyleSheet (style) ;
QErrorMessage *errorMessage = new QErrorMessage ;
errorMessage->showMessage(GetLastErrorStdStr());
}
QString GetLastErrorStdStr()
{
DWORD error = GetLastError();
if (error)
{
LPTSTR errorMessage;
FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_ARGUMENT_ARRAY |
FORMAT_MESSAGE_ALLOCATE_BUFFER,NULL,
error,0,(LPWSTR) &errorMessage,0, NULL );
return QString :: fromWCharArray(errorMessage) ;
}
}
My Header Files:
#include <windows.h>
#include <highlevelmonitorconfigurationapi.h>
My Library Files:
dxva2.dll ( copied it from "c:/windows/system32" into my project folder's Dll folder )
dxva2.lib ( copied it from "c:/windows/system32" into my project folder's Library folder )
this is how you include library in Qt:
win32:CONFIG(release,debug|release): LIBS += -L&&PWD/Dll/ -ldxva2
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/Library/ -ldxva2
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/Library/ -ldxva2
else:unix: LIBS += -L$$PWD/Library/ -ldxva2
INCLUDEPATH += $$PWD/Library
DEPENDPATH += $$PWD/Library
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Answer accepted by question author
Hi
This question is outside the scope of this site and needs to be asked either on the Technet or MSDN forums.
**http://social.technet.microsoft.com/Forums/en-us/home**
**http://social.msdn.microsoft.com/Forums/en-US/home**
Regards