东方project改变lol分辨率黑屏屏

directx(2)
采用ChangeDisplaySettings这个API函数就可以了。
Windows GDI
ChangeDisplaySettings
The ChangeDisplaySettings function changes the settings of the default display device to the specified graphics mode.
To change the settings of a specified display device, use the
LONG ChangeDisplaySettings(
&&& LPDEVMODE lpDevMode,&&// graphics mode
&&& DWORD dwflags&&&&&&&&&// graphics mode options
Parameters
[in] Pointer to a
structure that describes the new graphics mode. 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.
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.
dmBitsPerPel
Bits per pixel
dmPelsWidth
Pixel width
dmPelsHeight
Pixel height
dmDisplayFlags
Mode flags
dmDisplayFrequency
Mode frequency
dmPosition
Windows 98/Me, Windows 2000/XP: Position of the device in a multimonitor configuration
In addition to using one or more of the preceding DEVMODE members, you must also set one or more of the following values in the dmFields member to change the display setting.
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/Me, Windows 2000/XP: Use the dmPosition value.
[in] Indicates how the graphics mode should be changed. This parameter can be one of the following values.
The graphics mode for the current screen will be changed dynamically.
CDS_FULLSCREEN
The mode is temporary in nature.
Windows NT/2000/XP: 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_NORESET
The settings will be saved in the registry, but will not take effect. This flag is only valid when specified with the CDS_UPDATEREGISTRY flag.
The settings should be changed, even if the requested settings are the same as the current settings.
CDS_SET_PRIMARY
This device will become the primary device.
The system tests if the requested graphics mode could be set.
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.
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/2000/XP: 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.
Return Values
The ChangeDisplaySettings function returns one of the following values.
DISP_CHANGE_SUCCESSFUL
The settings change was successful.
DISP_CHANGE_BADDUALVIEW
Windows XP: The settings change was unsuccessful because system is DualView capable.
DISP_CHANGE_BADFLAGS
An invalid set of flags was passed in.
DISP_CHANGE_BADMODE
The graphics mode is not supported.
DISP_CHANGE_BADPARAM
An invalid parameter was passed in. This can include an invalid flag or combination of flags.
DISP_CHANGE_FAILED
The display driver failed the specified graphics mode.
DISP_CHANGE_NOTUPDATED
Windows NT/2000/XP: Unable to write settings to the registry.
DISP_CHANGE_RESTART
The computer must be restarted in order for the graphics mode to work.
To ensure that the
structure passed to ChangeDisplaySettings is valid and contains only values supported by the display driver, use the DEVMODE returned by the
When the display mode is changed dynamically, the WM_DISPLAYCHANGE message is sent to all running applications with the following message parameters.
Parameters
New bits per pixel
LOWORD(lParam)
New pixel width
HIWORD(lParam)
New pixel height
Windows 95/98/Me: If the calling thread has any windows, ChangeDisplaySettings sends them the WM_DISPLAYCHANGE message immediately (for windows in all other threads, the message is sent when the thread can receive nonqueued messages). This may cause the shell to get its message too soon and could squash icons. To avoid this problem, have ChangeDisplaySettings do resolution switching by calling on a thread with no windows, for example, a new thread.
Windows 95/98/Me: ChangeDisplaySettingsW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in .
&&& Windows NT/2000/XP/Vista: Included in Windows NT 3.5 and later.&&& Windows 95/98/Me: Included in Windows 95 and later.&&& Header: Declared in Winuser.h; include Windows.h.&&& Library: Use User32.lib.&&& Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000/XP. Also supported by Microsoft Layer for Unicode.
, , , , , , ,
Introduction
A common problem that some or all Windows developers are facing is changing the Screen Resolution dynamically. The resolution of the user screen is not necessarily the same as that of the development environment screen. Here what we will do is, in the requirement and installation note, we will mention that the user has to use xxxx * xxx resolution for better performance. Is this good?. If the end user does not have enough experience, what will happen? In this case, the user tries to open that product in lesser or greater resolution than the developed screen resolution and that will
problem in the sense that some portion of the window won't be visible to the user if he uses a lesser resolution or the window will become stretched if he uses a higher resolution. So here, you will get the ultimate solution for this sort of problem.
Through this article I will explain how we can:
get the end user resolution
change the resolution to our software/product compatible resolution
get the end user resolution back
Getting the end user resolution
In dotnet we can access the values of the user's screen resolution through the Screen class which ships with the Framework. Here we can get the Screen resolution through a Screen.PrimaryScreen Property, the signature of this property is as follows: public static Screen PrimaryScreen {}
This property is a read-only property which has a return of type Screen. So our first goal has been achieved: that is getting the screen resolution. Screen screen = Screen.PrimaryS
int S_width=screen.Bounds.W
int S_height=screen.Bounds.H
Note: You can see the implementation of this logic in the project file (see download file above). You can apply this logic to any event you want.
Changing the resolution to our software/product compatible resolution
Our next goal is to set the screen resolution. Here you have to put in a little effort. In .NET there is no supported built-in class or classes for setting the resolution. You can achieve this through calling some Win32 API.
Before continuing, better read something about
in dotnet (early and late binding), ,
I will explain the above technologies a little. I can't go into detail because here, my aim is something different.
Using the DllImport Attribute you are going to read the definition of unmanaged code to your managed environment. Here there are two functions available in the User32.dll file which are related to changing the screen resolution.
EnumDisplaySettings
ChangeDisplaySettings
If you want to use this unmanaged code definition here in your managed environment what you will do? There comes the DllImport Attribute. Using DllImport attribute you can access the functionality of the user32.dll file. See the code block.
Note: You can see the implementation of this logic in the project file (see download file above). You can apply this logic to any event that you want.
Here you are calling the Win32 API's User32.dll files. class User32
&&&&&&&&& [DllImport("user32.dll")]
&&&&&&&&& public static extern int EnumDisplaySettings (
&&&&&&&&&&& string deviceName, int modeNum, ref DEVMODE devMode );&&&&&&&&&&
&&&&&&&&& [DllImport("user32.dll")]
&&&&&&&&& public static extern int ChangeDisplaySettings(
&&&&&&&&&&&&&&& ref DEVMODE devMode, int flags);
&&&&&&&&& public const int ENUM_CURRENT_SETTINGS = -1;
&&&&&&&&& public const int CDS_UPDATEREGISTRY = 0x01;
&&&&&&&&& public const int CDS_TEST = 0x02;
&&&&&&&&& public const int DISP_CHANGE_SUCCESSFUL = 0;
&&&&&&&&& public const int DISP_CHANGE_RESTART = 1;
&&&&&&&&& public const int DISP_CHANGE_FAILED = -1;
The line [DllImport("user32.dll")] is for importing the DLL file to your managed environment.
If you want to use the Win32 API functions then you have to give the full signature of the function that you are going to use in your managed environment. public static extern int EnumDisplaySettings
&&&&& (string deviceName, int modeNum, ref DEVMODE devMode);
And the remaining lines are self explanatory. If you check the signature of both functions above, you can see DEVMODE references. What is this?
DEVMODE is a structure that is explained in the platform documentation as well as included with Visual Studio .NET. The structure is defined in C#. [StructLayout(LayoutKind.Sequential)]
public struct DEVMODE
&&&&&&&&& [MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]
&&&&&&&&&&& public string dmDeviceN
&&&&&&&&& public short&&& dmSpecV
&&&&&&&&& public short&&& dmDriverV
&&&&&&&&& ...
Note: You will get the full code block in project file that you can download at the top of this article. You can apply this logic to any event that you want.
Special care needs to be taken to make sure that the types are the right size and that fixed length strings are appropriately defined. In this case WORD maps to short, DWORD to int and short stays as short.
The function EnumDisplaySettings is called and as long as the return is non-zero we can call the ChangeDisplaySettings after changing the appropriate values in the DEVMODE structure: DEVMODE dm = new DEVMODE();
dm.dmDeviceName = new String (new char[32]);
dm.dmFormName = new String (new char[32]);
dm.dmSize = (short)Marshal.SizeOf (dm);
if (0 != User32.EnumDisplaySettings (null,
&&&&&&&& User32.ENUM_CURRENT_SETTINGS, ref dm))
At this point the DEVMODE structure is filled with the settings for the default display. We can modify it and then call the change function: dm.dmPelsWidth = iW
dm.dmPelsHeight = iH
int iRet = User32.ChangeDisplaySettings (
&&& ref dm, User32.CDS_UPDATEREGISTRY);
The code in the download does this a little differently to cope with various error conditions and to test that we can set the display mode before we actually do so. I would encourage you to look at the full source file and see what it does. That's all there is to it. Now we achieved our second goal.
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:2191次
排名:千里之外<div class="spf_off1" style="width:%">5.0分
<div class="spf_off1" style="width:%">5.0分
<div class="spf_off1" style="width:%">5.0分
<div class="spf_off1" style="width:%">5.0分
<div class="spf_off1" style="width:%">5.0分
<div class="spf_off1" style="width:%">5.0分
<div class="spf_off1" style="width:%">10分
<div class="spf_off1" style="width:%">5.0分
从2008年-2014年 快猴网一直在努力做到最好
备案编号:粤ICP备号-1}

我要回帖

更多关于 lol分辨率黑屏 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信