为什么更改未应用于c中的系统 [英] why the changes not applied to the system in c

查看:71
本文介绍了为什么更改未应用于c中的系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的编码:

my coding:

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
	DEVMODE dm;
	ZeroMemory(&dm, sizeof(dm));
	
   dm.dmSize = sizeof(dm);
   int index = 0;
   if (0 != EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
   {

	  DWORD dwTemp = dm.dmPelsHeight;
      dm.dmPelsHeight= 800;
      dm.dmPelsWidth = 600;
	  dm.dmDisplayFlags =  DM_DISPLAYFLAGS;
	  dm.dmBitsPerPel = 16;
	  dm.dmFields = 16;
	  if(DISP_CHANGE_SUCCESSFUL  == ChangeDisplaySettings(&dm,0))
	  {
		  printf("\nSuccess\n");
	  }
	  else
	  {
		  printf("\nFailure\n");
	  }
	  
	return 0;
}



我想更改屏幕分辨率..

我为那个写的上面的程序..

但是,即使没有应用到屏幕上的更改也可以成功.

为什么?



i want to change the screen resolution..

The above program i wrote for that one..

But it produces success even-through the changes not applied to the screen ..

Why?

推荐答案

似乎您尚未完全指定DEVMODE的哪些字段有效.

您为标志设置的值相当奇怪-0x10(对应于DM_SCALE)
您需要设置一个位来指示结构的每个有效字段.

只需更改行即可:
It seems that you''ve not fully specified which fields of DEVMODE are valid.

The value you set for flags is rather odd - 0x10 (corresponds to DM_SCALE)
You need to set a bit that indicates each of the valid fields of the structure.

Just change the line:
dm.dmFields = 16;






To

dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;



哦!另外,您是要设置600x800屏幕(如代码所示)还是更可能的800x600屏幕?当我尝试这样做时,尽管屏幕分辨率没有变化,但位/像素却发生了变化-我也收到了成功的结果.猜测最好的办法是在尝试更改屏幕设置后检查实际值是否为预期值..



Oh! Also, do you mean to set a 600x800 screen (as shown in code) or the more likely 800x600? When I tried that, the bits/pixel changed, though the screen res didn''t - I also received a success result. Guess the best thing to do is to check that the actual values are the expected ones after an attempt to change the screen settings..

//#include "stdafx.h"
#include <windows.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
	DEVMODE dm;
	ZeroMemory(&dm, sizeof(dm));

   dm.dmSize = sizeof(dm);
   int index = 0;
   if (0 != EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
   {

	  DWORD dwTemp = dm.dmPelsHeight;
	  dm.dmPelsWidth = 800;
	  dm.dmPelsHeight= 600;
	  dm.dmDisplayFlags =  DM_DISPLAYFLAGS;
	  dm.dmBitsPerPel = 16;
	  dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
	  if(DISP_CHANGE_SUCCESSFUL  == ChangeDisplaySettings(&dm,0))
	  {
		  printf("\nSuccess\n");
	  }
	  else
	  {
		  printf("\nFailure\n");
	  }
    }
    return 0;
}


尝试一下:
Try this:
dm.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL;


祝你好运!


Good luck!


这篇关于为什么更改未应用于c中的系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆