現在の部屋の明るさでモニターの明るさを調整する小さなプログラムをセットアップしようとしています。
MSDN の指示に従って、これをセットアップしました。
cout << "Legen Sie das Fenster bitte auf den zu steuernden Monitor.\n";
system("PAUSE");
HMONITOR hMon = NULL;
char OldConsoleTitle[1024];
char NewConsoleTitle[1024];
GetConsoleTitle(OldConsoleTitle, 1024);
SetConsoleTitle("CMDWindow7355608");
Sleep(40);
HWND hWnd = FindWindow(NULL, "CMDWindow7355608");
SetConsoleTitle(OldConsoleTitle);
hMon = MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY);
DWORD cPhysicalMonitors;
LPPHYSICAL_MONITOR pPhysicalMonitors = NULL;
BOOL bSuccess = GetNumberOfPhysicalMonitorsFromHMONITOR(
hMon,
&cPhysicalMonitors
);
if(bSuccess)
{
pPhysicalMonitors = (LPPHYSICAL_MONITOR)malloc(
cPhysicalMonitors* sizeof(PHYSICAL_MONITOR));
if(pPhysicalMonitors!=NULL)
{
LPDWORD min = NULL, max = NULL, current = NULL;
GetPhysicalMonitorsFromHMONITOR(hMon, cPhysicalMonitors, pPhysicalMonitors);
HANDLE pmh = pPhysicalMonitors[0].hPhysicalMonitor;
if(!GetMonitorBrightness(pmh, min, current, max))
{
cout << "Fehler: " << GetLastError() << endl;
system("PAUSE");
return 0;
}
//cout << "Minimum: " << min << endl << "Aktuell: " << current << endl << "Maximum: " << max << endl;
system("PAUSE");
}
}
しかし、問題: GetMonitorBrightness() を使用しようとするたびに、プログラムがクラッシュしAccess Violation while writing at Position 0x00000000
ます (このエラーをドイツ語から翻訳しました) 。
デバッグしようとしているときに、pPhysicalMonitors には実際に使用したいモニターが含まれていることがわかりましたが、含まれているのpPhysicalMonitors[0].hPhysicalMonitor
は 0x0000000 のみです。これは問題の一部でしょうか?