352
❘
CHAPTER 16
ExtEnding ironPython Using C#
Defining the GetCurrentDisplayMode() Method
Sometimes you need to know whether the console is presented in a windowed or full-screen mode. A
windowed console can get covered up and needs to share resources with other windows. In addition,
the text in a windowed console can be small and hard to read. On a positive note, using a windowed
console makes it easier to share data between applications. In most cases, the user will prefer that
you use a windowed console to make it easier to multitask between applications. Listing 16-7 shows
how to detect the current console display mode.
LISTINg 16-7:
Obtaining the current display mode
public OutputMode GetCurrentDisplayMode()
{
// Get the current display mode.
if (GetConsoleDisplayMode(ref DisplayMode))
// Determine if the console is in windowed mode.
if (DisplayMode == (UInt32)ConsoleDispMode.CONSOLE_WINDOWED)
return OutputMode.Windowed;
else
{
// If the console is fullscreen mode, determine which
// of the potential conditions are true.
switch (DisplayMode)
{
case (UInt32)ConsoleDispMode.CONSOLE_FULLSCREEN:
return OutputMode.Fullscreen;
case (UInt32)ConsoleDispMode.CONSOLE_FULLSCREEN_HARDWARE:
return OutputMode.HadwareAccess;
case (UInt32)ConsoleDispMode.CONSOLE_FULLSCREEN +
(UInt32)ConsoleDispMode.CONSOLE_FULLSCREEN_HARDWARE:
return OutputMode.FullscreenHardwareAccess;
}
}
// Return a default value.
return OutputMode.Unknown;
}
The code begins by calling
GetConsoleDisplayMode()
to obtain the display mode as a numeric
value. The information is returned in
DisplayMode
, not as a return value from the function call.
The function itself returns a success value that indicates the call was successful. The first
if
state-
ment says that if the call is successful, then
DisplayMode
will contain the console display mode, and
that the application should proceed to process it. Because
DisplayMode
provides a return value, you
must include the
ref
keyword when passing it to the Win32 API.
Now that the code has a display mode value, it needs to process it. If a console is in windowed
mode, all the code has to do is return a value that says it’s windowed. However, full-screen mode
548592c16.indd 352
2/24/10 12:49:27 PM
www.finebook.ir
Do'stlaringiz bilan baham: |