Skip to main content
gamedev.net
🔒 Locked

Windows API Full Screen (C++)

Started by Programmierer 6 replies 2.3k views
Original Post
Programmierer
Programmierer
I'm programming my own game engine in C++ right now from the Windows API (Windows XP). Does anyone know where I can find a resource that tells me how to set full screen mode? Right now all I can do is manually set resolutions for a windowed mode. Thanks in advance
My_Mind_Is_Going
My_Mind_Is_Going
ChangeDisplaySettings(&ScreenSettings, CDS_FULLSCREEN)

ScreenSettings there is a DEVMODE structure you need to fill out specifying the resolution, and bitdepth and stuff.

Here's the MSDN

http://msdn2.microsoft.com/en-us/library/ms533260.aspx
Programmierer
Programmierer
I'm not sure exactly how to use this.

When I create a new instance of my game engine it sets the windowed resolution in the constructor. How can I rewrite this? Do I have to rewrite this ChangeDisplaySettings() into my constructor?

Thanks
My_Mind_Is_Going
My_Mind_Is_Going
How is the constructor setting the resolution to begin with, can you show me some code? But yes you probably will want to call ChangeDisplaySettings() in that part of your code where you're intializing everything.
Programmierer
Programmierer
This is how the initialize function works right now. By the way I'm getting most of the code from a book I'm reading. Is it common practice NOT to define resolution in the constructor? That is what this books has me doing evidently.

<code>
BOOL GameEngine::Initialize(int iCmdShow)
{
WNDCLASSEX wndclass;

// Create the window class for the main window
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = m_hInstance;
wndclass.hIcon = LoadIcon(m_hInstance,
MAKEINTRESOURCE(GetIcon()));
wndclass.hIconSm = LoadIcon(m_hInstance,
MAKEINTRESOURCE(GetSmallIcon()));
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = m_szWindowClass;

// Register the window class
if (!RegisterClassEx(&wndclass))
return FALSE;

// Calculate the window size and position based upon the game size
int iWindowWidth = m_iWidth + GetSystemMetrics(SM_CXFIXEDFRAME) * 2;
int iWindowHeight = m_iHeight + GetSystemMetrics(SM_CYFIXEDFRAME) * 2 +
GetSystemMetrics(SM_CYCAPTION);
if (wndclass.lpszMenuName != NULL)
iWindowHeight += GetSystemMetrics(SM_CYMENU);
int iXWindowPos = (GetSystemMetrics(SM_CXSCREEN) - iWindowWidth) / 2,
iYWindowPos = (GetSystemMetrics(SM_CYSCREEN) - iWindowHeight) / 2;

// Create the window
m_hWindow = CreateWindow(m_szWindowClass, m_szTitle, WS_POPUPWINDOW |
WS_CAPTION | WS_MINIMIZEBOX, iXWindowPos, iYWindowPos, iWindowWidth,
iWindowHeight, NULL, NULL, m_hInstance, NULL);
if (!m_hWindow)
return FALSE;

// Show and update the window
ShowWindow(m_hWindow, iCmdShow);
UpdateWindow(m_hWindow);

return TRUE;
}
</code>
Programmierer
Programmierer
Code for game engine. By the way how do I get my code into a little scrollable window when I post?

<code>
GameEngine::GameEngine(HINSTANCE hInstance, LPTSTR szWindowClass,
LPTSTR szTitle, WORD wIcon, WORD wSmallIcon, int iWidth, int iHeight)
{
// Set the member variables for the game engine
m_pGameEngine = this;
m_hInstance = hInstance;
m_hWindow = NULL;
if (lstrlen(szWindowClass) > 0)
lstrcpy(m_szWindowClass, szWindowClass);
if (lstrlen(szTitle) > 0)
lstrcpy(m_szTitle, szTitle);
m_wIcon = wIcon;
m_wSmallIcon = wSmallIcon;
m_iWidth = iWidth;
m_iHeight = iHeight;
m_iFrameDelay = 50; // 20 FPS default
m_bSleep = TRUE;
m_uiJoystickID = 0;
m_vSprites.reserve(100);
m_uiMIDIPlayerID = 0;
}
</code>

Here's the call:

// Create the game engine
g_pGame = new GameEngine(hInstance, TEXT("GAME NAME HERE"),
TEXT("GAME NAME HERE"), IDI_ICON, IDI_ICON_SM, 500, 400);
//500 and 400 would be the window's resolution...

Thanks again
My_Mind_Is_Going
My_Mind_Is_Going
The short answer is, yes make the call to ChangeDisplaySettings after (I think) you register your new window class but before you actually create the window. The longer answer is there are things you're probably going to want to play with like different WS flags when you call CreateWindow so just beware.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.