In Windows 95, changes to the display mode, we know that the "Start" menu is generally made: "Start" menu settings? Control panel, double-click "display", change the screen resolution, the number of colors displayed, etc.
But sometimes we need a program to control the display mode, the most common is the game program. The general application may also have such a requirement, for example, suppose to display a picture in the program, the picture is originally 16-bit color, if this display mode is set to 256 colors (ie 8-bit color), then The picture displayed is very ugly. Then, as a window is designed, it is performed at the resolution of 800 ╳600, then when the window is displayed at 640 ╳480 resolution, it is possible to make the window to be smaller because the screen can be displayed. Scope of the screen. These issues can be solved by directly controlling display mode in the program.
The following is an example to illustrate how to directly control the screen display mode.
Suppose such a program requires the screen resolution of 800 ╳600, the color is 16 bit color. That is, when the program is executed, the screen mode will change the screen mode to 800 ╳600, 16, whether the screen is the number of resolutions and color.
The author's program is implemented in the C Builder 3 environment, but the programming principle is equally applicable to the readers of Visusl C , Visual Basic, Borland C , Delphi. This procedure has no specific function, just displaying a window while changing the screen mode.
Direct modifications to display modes are implemented by means of DirectDraw technology. First run Borland C Builder 3.0, create a new project, add the header file in Uni1.cpp, to use DirectDraw technology:
#include
Changing the code of the display mode is placed in the ONSHOW event of Form1, the code is as follows:
Void __fastcall tform1 :: formshow (TOBJECT * Sender)
{
LPDIRECTDRAW LPDD; // Declare a DirectDraw object pointer
HRESULT DDRVAL;
DDRVAL = DirectDrawCreate (NULL, & LPDD, NULL); // Create a DirectDraw object
IF (DDRVAL! = DD_OK)
{
ShowMessage ("ERROR1!");
Return;
}
HWND HandleDesk; // Declare a desktop window handle
Handledesk = getDesktopWindow (); // Get a desktop window handle
DDRVAL = LPDD-> SetCoopeRATIVELEVEL (Handledesk,
DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN;
IF (DDRVAL! = DD_OK)
{
ShowMessage ("ERROR2!");
Return;
}
LPDD-> SetDisplayMode (800, 600, 16);
/ / Set screen mode (800 ╳600 resolution, 16-bit color)
}
Compile operation, no matter how the screen display mode you attend, the display mode will change to 800 ╳600, 16. When the program is turned off, the screen is automatically recovered to the original display mode.
Netying
Zrh1999@163.net website
Filesee
January 1999