15,979
社区成员
发帖
与我相关
我的任务
分享
// Codes are shown here for reading ! not tested !
void CVcDispResDlg::ChangeResolution()
{
if(!m_bAllowToChange) return;
//
LPCTSTR psz;
UINT nMBBtn;
// Keep the current refresh rate
m_DevSelect.dmDisplayFrequency = GetDeviceCaps((HDC)GetDC(), VREFRESH);
// Attempt to change the display resolution.
switch (ChangeDisplaySettings(&m_DevSelect, CDS_UPDATEREGISTRY))
{
case DISP_CHANGE_SUCCESSFUL:
psz = __TEXT("Display change successful.");
break;
case DISP_CHANGE_RESTART:
psz = __TEXT("You must restart your computer before the ")
__TEXT("new settings will take effect.\n\n")
__TEXT("Do you want to restart your computer now?");
nMBBtn = MB_YESNO;
break;
case DISP_CHANGE_BADFLAGS:
psz = __TEXT("An invalid set of flags was passed in.");
break;
case DISP_CHANGE_FAILED:
psz =__TEXT("The display driver couldn't change the display.");
break;
case DISP_CHANGE_BADMODE:
psz = __TEXT("Invalid settings.");
break;
case DISP_CHANGE_NOTUPDATED:
psz = __TEXT("Unable to write settings to the registry.");
break;
}
// Show the user the results
if (IDYES == AfxMessageBox( psz, nMBBtn | MB_ICONINFORMATION))
{ // If the user wants to reboot the computer, do so.
// Windows NT: We must enable our shutdown privilege,assumming we have it.
// Windows 95: OpenProcessToken, LookupPrivilegeValue, and
// AdjustTokenPrivileges are not implemented and
// are ignored.
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// We want to adjust our process's privileges.
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken);
// Get the LUID for shutdown privilege
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Turn the SE_SHUTDOWN_NAME privilege on for our process
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0);
CloseHandle(hToken);
// Shut down and reboot the system.
ExitWindowsEx(EWX_REBOOT, 0);
}
}