출처 : http://www.daniweb.com/software-development/cpp/threads/370926/windows-api-screen-resolution
I'm pretty sure I'm doing everything in there except for the OpenGL stuff, I'm not using that yet. Basically I have a Window 'Init' function, it goes like this:
bool CWindow::Init( HINSTANCE hInst, int width, int height, bool fullscreen, char *caption, WindowProcedure_t proc )
{
RECT rScreenRect;
RECT rWndRect = { 0, 0, width, height };
// the actual size of the window, including menu
int iWndWidth = ( rWndRect.right - rWndRect.left );
int iWndHeight = ( rWndRect.bottom - rWndRect.top );
// Register the windows class
memset(&m_WindowClass, 0, sizeof(m_WindowClass));
m_WindowClass.cbSize = sizeof(m_WindowClass);
m_WindowClass.lpfnWndProc = (WNDPROC)WindowProc;
m_WindowClass.hInstance = hInst;
m_WindowClass.hCursor = LoadCursor(0, IDC_ARROW);
m_WindowClass.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
m_WindowClass.lpszClassName = "WindowClass";
if( !m_bRegistered )
{
if( !RegisterClassEx(&m_WindowClass) )
return false;
//m_bRegistered = true;
}
DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
DWORD dwStyle = WS_OVERLAPPEDWINDOW;
if( fullscreen )
{
DEVMODE dmScreenSettings;
memset( &dmScreenSettings, 0, sizeof( dmScreenSettings ) );
dmScreenSettings.dmSize = sizeof( dmScreenSettings );
dmScreenSettings.dmPelsWidth = width;
dmScreenSettings.dmPelsHeight = height;
dmScreenSettings.dmBitsPerPel = 32;
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if( ChangeDisplaySettings( &dmScreenSettings, CDS_FULLSCREEN ) != DISP_CHANGE_SUCCESSFUL )
return false;
dwExStyle = WS_EX_APPWINDOW;
dwStyle = WS_POPUP;
ShowCursor( FALSE );
}
AdjustWindowRectEx( &rWndRect, dwStyle, false, dwExStyle );
GetWindowRect( GetDesktopWindow(), &rScreenRect );
int iX = ( (rScreenRect.right - rScreenRect.left) - iWndWidth ) >> 1;
int iY = ( (rScreenRect.bottom - rScreenRect.top) - iWndHeight ) >> 1;
m_pWindowHandle = CreateWindowEx( dwExStyle, "WindowClass", caption, dwStyle,
iX, iY, iWndWidth, iWndHeight,
NULL, 0, GetModuleHandle( 0 ), 0 );
ShowWindow( m_pWindowHandle, SW_SHOW );
UpdateWindow( m_pWindowHandle );
m_nWidth = iWndWidth;
m_nHeight = iWndHeight;
m_bFullscreen = fullscreen;
m_pModule = hInst;
V_strncpy( m_WindowCaption, caption, 1024 );
s_WindowProcedure = proc;
return true;
}
Which works fine when in windowed mode, but does the thing I described when I try to switch to fullscreen. This is the function I call when I want to change the size/fullscreen state of the window:
NOTE: I have fullscreen as an int here to allow you to specify -1 to tell the function to not change the fullscreen state.
void CWindow::SetSize( int width, int height, int fullscreen )
{
WindowProcedure_t temp = s_WindowProcedure;
s_WindowProcedure = NULL;
DestroyWindow( m_pWindowHandle );
UnregisterClass( m_WindowClass.lpszClassName, m_pModule );
#define fs ( ( fullscreen == -1 ) ? m_bFullscreen : ( ( fullscreen == 1 ) ? true : false ) )
if( !m_bFullscreen )
{
Init( m_pModule, width, height, fs, m_WindowCaption, temp );
return;
}
int screenwidth = 1366; //GetSystemMetrics( SM_CXFULLSCREEN );
int screenheight = 768; //GetSystemMetrics( SM_CYFULLSCREEN );
Init( m_pModule, screenwidth, screenheight, fs, m_WindowCaption, temp );
}
'Windows' 카테고리의 다른 글
[Windows API][Tip] 전체화면/윈도우 모드 구현 팁 (0) | 2013.12.07 |
---|