请教ChangeDisplaySettings函数的用法

sunstrom 2003-04-13 08:15:35
我想动态修改屏幕的分辨率有人告诉我说用ChangeDisplaySettings这个函数可是我找不到这个函数的原型,哪位知道的请告诉我一下,如果带示范就最好了:D例如我想将屏幕设置为800X600我该怎么用这个函数?
...全文
487 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
HUANG_JH 2003-04-14
  • 打赏
  • 举报
回复

全屏幕OpenGL程序

其实在BCB中实现全屏幕OpenGL的原理是很简单的,只要在窗口OpenGL程序的基础上做一个小小的改动即可:只要将窗口属性修改为WS_POPUP就可以了。

具体如下:

在窗口类的CreateParam()成员函数中加入如下语句:
Params.Style=WS_POPUP|WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
将相应窗口修改成WS_POPUP型窗口,另两个是为支持OpenGL为设的。
仍在窗口类的CreateParam()成员函数,加入如下语句:
ChangeResolution(800,600);
Params.Width=800;
Params.Height=600;
Params.X=Params.Y=0;
第一句将屏幕分辨率设定为800X600(可以是显示卡支持的任意值)
然后修改窗体大小使之占满全屏。
ChangeResolution()是一个自编的小函数,其原理如下:
用WINAPI:EnumDisplaySettings()查询并取得所需的显示模式
用WINAPI:ChangeDisplaySettings()修改显示模式。
ChangeResolution()的完整代码:

BOOL ChangeResolution(DWORD w, DWORD h) {
DEVMODE devMode;
LONG modeSwitch;
LONG i;
CHAR buf[256];
i = 0;
do {
modeSwitch = EnumDisplaySettings(NULL, i, &devMode);
i++;
} while(( (devMode.dmBitsPerPel!=16)
||(devMode.dmPelsWidth != w)
||(devMode.dmPelsHeight != h) )
&& (modeSwitch) );
/* Okay see if we found a mode */
if (!modeSwitch) { }
else {
modeSwitch = ChangeDisplaySettings(&devMode, 0);
if (modeSwitch!=DISP_CHANGE_SUCCESSFUL)
{
//Might be running in Windows95, let's try without the hertz change
devMode.dmBitsPerPel = 16;
devMode.dmPelsWidth = w;
devMode.dmPelsHeight = h;
devMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
modeSwitch = ChangeDisplaySettings(&devMode, 0);
}
}
return TRUE;
}
Behard 2003-04-14
  • 打赏
  • 举报
回复
void __fastcall TForm1::Button1Click(TObject *Sender)
{
DEVMODE stDEVMODE;

stDEVMODE.dmPelsWidth = 800;
stDEVMODE.dmPelsHeight = 600;
stDEVMODE.dmSize = sizeof ( DEVMODE );
stDEVMODE.dmDisplayFrequency = 75;
stDEVMODE.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;

ChangeDisplaySettings ( &stDEVMODE, 0 );
}
chinayang 2003-04-14
  • 打赏
  • 举报
回复
ChangeDisplaySettings

The ChangeDisplaySettings function changes the settings of the default display device to the graphics mode specified in lpDevMode. To change the settings of a specified display device, use the ChangeDisplaySettingsEx function.

LONG ChangeDisplaySettings(
LPDEVMODE lpDevMode,
DWORD dwflags
);

Parameters
lpDevMode
Pointer to a DEVMODE structure that describes the graphics mode to switch to.
The dmSize member of DEVMODE must be initialized to the size, in bytes, of the DEVMODE structure.

The dmDriverExtra member of DEVMODE must be initialized to indicate the number of bytes of private driver data following the DEVMODE structure.

In addition, you can use any or all of the following members of the DEVMODE structure. Member Meaning
dmBitsPerPel Bits per pixel
dmPelsWidth Pixel width
dmPelsHeight Pixel height
dmDisplayFlags Mode flags
dmDisplayFrequency Mode frequency
dmPosition Windows 98, Windows NT 5.0 and later: Position of the device in a multi-monitor configuration



In addition to setting a value in one or more of the preceding DEVMODE members, you must also set the appropriate flags in the dmFields member. The flags indicate which members of the DEVMODE structure are used for the display settings change. If the appropriate bit is not set in dmFields, the display setting will not be changed. Set one or more of the following flags: Flag Meaning
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_DISPLAYFREQUENCY Use the dmDisplayFrequency value.
DM_POSITION Windows 98, Windows NT 5.0 and later: Use the dmPosition value.



If lpDevMode is NULL, all the values currently in the registry will be used for the display setting. Passing NULL for the lpDevMode parameter and 0 for the dwFlags parameter is the easiest way to return to the default mode after a dynamic mode change.

dwflags
Indicates how the graphics mode should be changed. May be one of the following: Flag Meaning
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.
CDS_FULLSCREEN The mode is temporary in nature.
Windows NT: If you change to and from another desktop, this mode will not be reset.

CDS_GLOBAL The settings will be saved in the global settings area so that they will affect all users on the machine. Otherwise, only the settings for the user are modified. This flag is only valid when specified with the CDS_UPDATEREGISTRY flag.
CDS_SET_PRIMARY This device will become the primary device.
CDS_RESET The settings should be changed, even if the requested settings are the same as the current settings.
CDS_NORESET The settings will be saved in the registry, but will not take affect. This flag is only valid when specified with the CDS_UPDATEREGISTRY flag.


Specifying CDS_TEST allows an application to determine which graphics modes are actually valid, without causing the system to change to that graphics mode.

If CDS_UPDATEREGISTRY is specified and it is possible to change the graphics mode dynamically, the information is stored in the registry and DISP_CHANGE_SUCCESSFUL is returned. If it is not possible to change the graphics mode dynamically, the information is stored in the registry and DISP_CHANGE_RESTART is returned.

Windows NT: If CDS_UPDATEREGISTRY is specified and the information could not be stored in the registry, the graphics mode is not changed and DISP_CHANGE_NOTUPDATED is returned.

favorit 2003-04-13
  • 打赏
  • 举报
回复
winuser.h

1,221

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧