29.09.2008, 10:46
общий
это ответ
Здравствуйте, Кулешов Владимир Григорьевич!
Platform SDK, пример SetDisp, ключевая функция в приложении
Приложение:
/****************************************************************************
*
* FUNCTION : ChangeResolution (UINT nNewMode, HWND hwnd)
*
* PURPOSE : Change the resolution to the nNewMode index DEVMODE
*
\****************************************************************************/
BOOL ChangeResolution (
UINT nNewMode,
HWND hwnd )
{
LONG lResult; //Result of ChangeDisplaySettings
INT_PTR nUserResponse; //Return from VerifyRes Dlg
UINT nOldMode;
/*
ChangeDisplaySettings can set
dmBitsPerPel Bits per pixel
dmPelsWidth Pixel width
dmPelsHeight Pixel height
dmDisplayFlags Mode flags
dmDisplayFrequency Mode frequency
but one of these must be set in the DEVMODE dmFields
DM_BITSPERPEL Use the dmBitsPerPel value.
DM_PELSWIDTH Use the dmPelsWidth value.
DM_PELSHEIGHT Use the dmPelsHeight value.
DM_DISPLAYFLAGS Use the dmDisplayFlags value.
DM_DISPLAYFREQENCY Use the dmDisplayFrequency value.
dmSize must be set to the size, in bytes, of the DEVMODE structure.
*/
//
// First select a DevMode to use
// to start, just cycling through them
//
nOldMode = gnCurrentMode;
gnCurrentMode = nNewMode;
//
// Increment ptr to the new mode
//
gpCurrentMode = gpDevModes;
gpCurrentMode += nNewMode;
//
// Verify that the DEVMODE select will change something
//
if (!(DM_BITSPERPEL & gpCurrentMode->dmFields ||
DM_PELSWIDTH & gpCurrentMode->dmFields ||
DM_PELSHEIGHT & gpCurrentMode->dmFields ||
DM_DISPLAYFLAGS & gpCurrentMode->dmFields ||
DM_DISPLAYFREQUENCY & gpCurrentMode->dmFields ) )
{
//
// Note our DEVMODE returned from EnumDisplaySettings
// So we should never enter here
//
gnCurrentMode = nOldMode;
gpCurrentMode = gpDevModes;
gpCurrentMode += gnCurrentMode;
return (FALSE);
}
/************************************************************\
* *
* Possible Flags for param 2 of ChangeDisplay Settings *
* 0 The graphics mode for the current *
* screen will be changed dynamically. *
* CDS_UPDATEREGISTRY The graphics mode for the *
* current screen will be changed dynamically *
* and the graphics mode will be updated in *
* the registry. The mode information is *
* stored in the USER profile. *
* CDS_TEST The system tests if the requested *
* graphics mode could be set. *
* *
\************************************************************/
//
// First have the system test if we can set it
//
//
// Param 1 is the new DEVMODE
// Param 2 is Test Flag,
// which asks the operating system if this is a valid setting
// to change to -- wedon't want to make the system unusable
//
// Note: ChangeDisplaySettings required dmSize to be
// set to structSize, so we set that here
lResult = ChangeDisplaySettings
( gpCurrentMode,
CDS_TEST );
if (lResult == DISP_CHANGE_RESTART)
{
MessageBox(hwnd, "This mode requires a reboot which\n" \
"is not supported in this sample.",
"SetDisp Message", IDOK);
gnCurrentMode = nOldMode;
gpCurrentMode = gpDevModes;
gpCurrentMode += gnCurrentMode;
return FALSE;
}
if (DISP_CHANGE_SUCCESSFUL ==lResult)
{
//
// Param 2 is 0 to change dynamically
// hence the app name SetDisp!
//
// Note: ChangeDisplaySettings required dmSize to be
// set to structSize, so we set that here
lResult = ChangeDisplaySettings
( gpCurrentMode,
0 );
}
switch (lResult)
{
case DISP_CHANGE_SUCCESSFUL: //The settings change was successful.
TRC("DISP_CHANGE_SUCCESSFUL\n");
break;
case DISP_CHANGE_RESTART: //The computer must be restarted in order
// for the graphics mode to work.
TRC("DISP_CHANGE_RESTART\n");
break;
case DISP_CHANGE_BADFLAGS: //An invalid set of flags was passed in.
TRC("DISP_CHANGE_BADFLAGS\n");
break;
case DISP_CHANGE_FAILED: //The display driver failed the specified
// graphics mode.
TRC("DISP_CHANGE_FAILED\n");
break;
case DISP_CHANGE_BADMODE: //The graphics mode is not supported.
TRC("DISP_CHANGE_BADMODE\n");
break;
case DISP_CHANGE_NOTUPDATED: //Windows NT only: Unable to write settings
// to the registry.
TRC("DISP_CHANGE_NOTUPDATED\n");
break;
default:
TRC("Undocumented return value!!!!\n");
break;
}
//
// Set a timer to only give the user so much
// time to dedice incase the screen is garbled
//
SetTimer(hwnd, VERIFY_RESCHANGE, VERIFY_TIMEOUT, VerifyTimerProc);
//
// Have the user verify the new resolution and depth
//
nUserResponse = DialogBox(g_hinst,// handle this application
MAKEINTRESOURCE(IDD_VERIFYRES),// identifies dialog box template
NULL, // handle to owner window
VerifyDlgProc); // the dialog box procedure
//
// The verification is over, kill the timer
//
KillTimer(hwnd, VERIFY_RESCHANGE);
if (IDYES == nUserResponse)
{
//
// Keep resolution and update registry
//
char szTip[50];
//
// TODO: give them three choices:
// Dynamic only, Registry too, or Abort
//
// Note: ChangeDisplaySettings required dmSize to be
// set to structSize, so we set that here
lResult = ChangeDisplaySettings
( gpCurrentMode,
CDS_UPDATEREGISTRY ); // Flag to update registry
switch (lResult)
{
case DISP_CHANGE_SUCCESSFUL:
//
// The settings change was successful.
//
TRC("DISP_CHANGE_SUCCESSFUL - reg\n");
wsprintf(szTip,"%d x %d, %d bit color at %d hz",
gpCurrentMode->dmPelsWidth,
gpCurrentMode->dmPelsHeight,
gpCurrentMode->dmBitsPerPel,
gpCurrentMode->dmDisplayFrequency);
{
//
// Update the Menu informtion, just a check mark for now
//
HMENU hMenu, hMenu2;
hMenu = GetMenu(hwnd);
hMenu2 = GetSubMenu (hMenu, 0);
//
// Uncheck the old
//
CheckMenuItem (hMenu2, nOldMode, MF_BYPOSITION | MF_UNCHECKED);
//
// Check the new
//
CheckMenuItem (hMenu2, gnCurrentMode, MF_BYPOSITION | MF_CHECKED);
}
//
// Update the Notify_Icon quick tip
//
TrayMessage(hwnd, NIM_MODIFY, g_sDlgItems[0].uNotify,
LoadImage(g_hinst, MAKEINTRESOURCE(IDI_SETDISP),
IMAGE_ICON, 16, 16, 0), szTip);
break;
case DISP_CHANGE_RESTART: //The computer must be restarted in order
// for the graphics mode to work.
TRC("DISP_CHANGE_RESTART - reg\n");
break;
case DISP_CHANGE_BADFLAGS: //An invalid set of flags was passed in.
TRC("DISP_CHANGE_BADFLAGS - reg\n");
break;
case DISP_CHANGE_FAILED: //The display driver failed the specified
// graphics mode.
TRC("DISP_CHANGE_FAILED - reg\n");
break;
case DISP_CHANGE_BADMODE: //The graphics mode is not supported.
TRC("DISP_CHANGE_BADMODE - reg\n");
break;
case DISP_CHANGE_NOTUPDATED: //Windows NT only: Unable to write settings
// to the registry.
TRC("DISP_CHANGE_NOTUPDATED - reg\n");
break;
default:
TRC("Undocumented return value!!!! - reg\n");
break;
}
}
else
{
//
// The user chose to not keep the setting or we timed out
// so they may not have seen the dialog box to choose
//
// Change resolution back by calling
// ChangeDisplaySettings
// with a NULL DEVMODE which returns us to the current
// registry settings
//
// Note: ChangeDisplaySettings required dmSize to be
// set to structSize, so we set that here
lResult = ChangeDisplaySettings
( NULL,
0 ); // 0 to change dynamically
gnCurrentMode = nOldMode;
gpCurrentMode = gpDevModes;
gpCurrentMode += gnCurrentMode;
}
return (TRUE);
}