Skip to main content
gamedev.net
🔒 Locked

Window not changing

Started by fitfool Mar 16, 2007 at 9:21 PM 2 replies 650+ views
Original Post
fitfool
fitfool
hello, ive just started to lean directx. right now im on the basic's(making a window, clearing it to a certain color handling input). Everything's been great into i ran into a slight bug. This bug is that i have to options of display, fullscreen and windowed. I let the user toggle display modes while the program is running. If the user switch's the display mode to fullscreen, then switches back to windowed mode, it will remove the window's border, miniminze, maximize and close boxes. the stuff that has to do with dealing with changing the display modes is at the very bittom thanks, any help is appreciated, fitfool

#include <windows.h>
#include "c_D3D_settings.h"
#include "macros.h"

#define FSCREEN_HEIGTH 768
#define FSCREEN_WIDTH 1024

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

D3D_Settings::D3D_Settings( void )
{
	szClassName = "J-Fps";
	Vertex[0] = CUSTOMVERTEX( 150.0f,  50.0f, 0.5f, 1.0f, 0xffff0000 );
}

void D3D_Settings::Intilize( void )
{
	wincl.hInstance = hThisInstance;
    wincl.lpszClassName = (LPCWSTR)szClassName.c_str();
    wincl.lpfnWndProc = WindowProcedure;
    wincl.style = CS_DBLCLKS;                 
    wincl.cbSize = sizeof(WNDCLASSEX);
	wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 
    wincl.cbClsExtra = 0;                      
    wincl.cbWndExtra = 0;                      
    wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
	RegisterClassEx (&wincl);
	
	return;
}

void D3D_Settings::SetupWindow( void )
{
	if( Fullscreen == true)
	{
	InFullScreen = true;
	hwnd = CreateWindowEx (
           0,                   
           (LPCWSTR)szClassName.c_str(),         
           (LPCWSTR)L"J-Fps",      
           WS_EX_TOPMOST | WS_POPUP, 
           0,      
           0,       
           FSCREEN_WIDTH,              
           FSCREEN_HEIGTH,                 
           HWND_DESKTOP,       
           NULL,              
           hThisInstance,       
           NULL                 
           );
	}
	else
	{
		InFullScreen = false;
		hwnd = CreateWindowEx (
			0,                   
           (LPCWSTR)szClassName.c_str(),         
           (LPCWSTR)L"J-Fps",      
           WS_OVERLAPPEDWINDOW, 
           CW_USEDEFAULT,      
           CW_USEDEFAULT,       
           700,              
           700,                 
           HWND_DESKTOP,       
           NULL,              
           hThisInstance,       
           NULL                 
           );
	}
	
	ShowWindow (hwnd, nFunsterStil);

	return;
}

MSG D3D_Settings::RtrnMessage( void ) const
{
	return messages;
}

void D3D_Settings::SetThisInstance( HINSTANCE value )
{
	hThisInstance = value;
}
			
void D3D_Settings::SetPrevInstance( HINSTANCE value )
{
	hPrevInstance = value;
}

void D3D_Settings::SetPszArgument( LPSTR value )
{
	lpszArgument = value;
}

void D3D_Settings::SetFunsterStil( int value )
{
	nFunsterStil = value;
}

void D3D_Settings::SetupD3D( void )
{
	d3d = Direct3DCreate9(D3D_SDK_VERSION);
	
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	
	if(Fullscreen == true)
	{
		d3dpp.Windowed = false;
		d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
		d3dpp.BackBufferWidth = FSCREEN_WIDTH;   
		d3dpp.BackBufferHeight = FSCREEN_HEIGTH;   
	}
	else
	{
		d3dpp.Windowed = true;
	}
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.hDeviceWindow = hwnd; 
	
	d3d->CreateDevice(D3DADAPTER_DEFAULT,
                      D3DDEVTYPE_HAL,
                      hwnd,
                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                      &d3dpp,
                      &d3ddev);
	return;
}

void D3D_Settings::Render( void )
{
	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);
	d3ddev->BeginScene();    

    

    d3ddev->EndScene();    
	d3ddev->Present(NULL, NULL, NULL, NULL);    

    return;
}

void D3D_Settings::Start( void )
{
	if(MessageBox(NULL,(LPCWSTR)L"Would you like to go fullscreen?",(LPCWSTR)L"Fullscreen?", MB_YESNO | MB_ICONQUESTION) == IDYES)
	{
		Fullscreen = true;
	}
	else
	{
		Fullscreen = false;
	}
}

void D3D_Settings::CleanUp( void )
{
	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, NULL, NULL, NULL);
	d3ddev->Release();
	d3d->Release();
}

MSG *D3D_Settings::GetMessage( void ) 
{
	return &messages
}

HWND *D3D_Settings::GetWindow( void )
{
	return &hwnd
}

void D3D_Settings::HandleInput( void )
{
	if(KEY_DOWN(VK_F2))
	{
		SwitchGraphicsModes();
	}
}

void D3D_Settings::SwitchGraphicsModes( void )
{
	if(InFullScreen)
	{
		hwnd = CreateWindowEx (
			0,                   
           (LPCWSTR)szClassName.c_str(),         
           (LPCWSTR)L"J-Fps",      
           WS_OVERLAPPEDWINDOW | WS_EX_TOPMOST | WS_THICKFRAME, 
           1000,      
           1000,       
           700,              
           700,                 
           HWND_DESKTOP,       
           NULL,              
           hThisInstance,       
           NULL                 
           );


		d3dpp.Windowed = true;


		InFullScreen = false;

	}

	else if(!InFullScreen)
	{
		d3dpp.Windowed = false;
		
		d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
		d3dpp.BackBufferWidth = FSCREEN_WIDTH;   
		d3dpp.BackBufferHeight = FSCREEN_HEIGTH;
		
		InFullScreen = true;
		
		hwnd = CreateWindowEx (
           0,                   
           (LPCWSTR)szClassName.c_str(),         
           (LPCWSTR)L"Windows App",   
           WS_EX_TOPMOST | WS_POPUP, 
           0,      
           0,       
           FSCREEN_WIDTH,              
           FSCREEN_HEIGTH,                 
           HWND_DESKTOP,       
           NULL,              
           hThisInstance,       

           NULL                 
           );
	}

	d3ddev->Reset(&d3dpp);
}

F1N1TY
F1N1TY
Try this maybe: http://msdn2.microsoft.com/en-us/library/ms632600.aspx

Here's the LINKED version...

WS_POPUP probably isn't EXACTLY what you're looking for....
"I'd rather know one thing, no matter how ordinary, than discourse endlessly on great issues." -- Galileo
Crypter
Crypter
For dynamic fullscreen/windowed support, I never recreate the window.

I just manipulate the window directly, to support the options I want it
to[smile]

Just an idea
fitfool
fitfool
ok i fixed it by when i first allocate the window to fullscreen, i dont set it to WS_POPUP, so they just cant see the border and stuff here the final code

#include <windows.h>#include "c_D3D_settings.h"#include "macros.h"#define FSCREEN_HEIGTH 768#define FSCREEN_WIDTH 1024LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);D3D_Settings::D3D_Settings( void ){	szClassName = "J-Fps";	Vertex[0] = CUSTOMVERTEX( 150.0f,  50.0f, 0.5f, 1.0f, 0xffff0000 );}void D3D_Settings::Intilize( void ){	wincl.hInstance = hThisInstance;    wincl.lpszClassName = (LPCWSTR)szClassName.c_str();    wincl.lpfnWndProc = WindowProcedure;    wincl.style = CS_DBLCLKS;                     wincl.cbSize = sizeof(WNDCLASSEX);	wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);    wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);    wincl.hCursor = LoadCursor(NULL, IDC_ARROW);    wincl.lpszMenuName = NULL;                     wincl.cbClsExtra = 0;                          wincl.cbWndExtra = 0;                          wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND;	RegisterClassEx (&wincl);		return;}void D3D_Settings::SetupWindow( void ){	if( Fullscreen == true)	{	InFullScreen = true;	hwnd = CreateWindowEx (           0,                              (LPCWSTR)szClassName.c_str(),                    (LPCWSTR)L"J-Fps",                 WS_EX_TOPMOST | WS_OVERLAPPEDWINDOW,            0,                 0,                  FSCREEN_WIDTH,                         FSCREEN_HEIGTH,                            HWND_DESKTOP,                  NULL,                         hThisInstance,                  NULL                            );	}	else	{		InFullScreen = false;		hwnd = CreateWindowEx (			0,                              (LPCWSTR)szClassName.c_str(),                    (LPCWSTR)L"J-Fps",                 WS_OVERLAPPEDWINDOW,            CW_USEDEFAULT,                 CW_USEDEFAULT,                  700,                         700,                            HWND_DESKTOP,                  NULL,                         hThisInstance,                  NULL                            );	}		ShowWindow (hwnd, nFunsterStil);	return;}MSG D3D_Settings::RtrnMessage( void ) const{	return messages;}void D3D_Settings::SetThisInstance( HINSTANCE value ){	hThisInstance = value;}			void D3D_Settings::SetPrevInstance( HINSTANCE value ){	hPrevInstance = value;}void D3D_Settings::SetPszArgument( LPSTR value ){	lpszArgument = value;}void D3D_Settings::SetFunsterStil( int value ){	nFunsterStil = value;}void D3D_Settings::SetupD3D( void ){	d3d = Direct3DCreate9(D3D_SDK_VERSION);		ZeroMemory(&d3dpp, sizeof(d3dpp));		if(Fullscreen == true)	{		d3dpp.Windowed = false;		d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;		d3dpp.BackBufferWidth = FSCREEN_WIDTH;   		d3dpp.BackBufferHeight = FSCREEN_HEIGTH;   	}	else	{		d3dpp.Windowed = true;	}	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;	d3dpp.hDeviceWindow = hwnd; 		d3d->CreateDevice(D3DADAPTER_DEFAULT,                      D3DDEVTYPE_HAL,                      hwnd,                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,                      &d3dpp,                      &d3ddev);	return;}void D3D_Settings::Render( void ){	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);	d3ddev->BeginScene();            d3ddev->EndScene();    	d3ddev->Present(NULL, NULL, NULL, NULL);        return;}void D3D_Settings::Start( void ){	if(MessageBox(NULL,(LPCWSTR)L"Would you like to go fullscreen?",(LPCWSTR)L"Fullscreen?", MB_YESNO | MB_ICONQUESTION) == IDYES)	{		Fullscreen = true;	}	else	{		Fullscreen = false;	}}void D3D_Settings::CleanUp( void ){	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, NULL, NULL, NULL);	d3ddev->Release();	d3d->Release();}MSG *D3D_Settings::GetMessage( void ) {	return &messages}HWND *D3D_Settings::GetWindow( void ){	return &hwnd}void D3D_Settings::HandleInput( void ){	if(KEY_DOWN(VK_F2))	{		SwitchGraphicsModes();	}}void D3D_Settings::SwitchGraphicsModes( void ){	if(InFullScreen)	{		/*hwnd = CreateWindowEx (			0,                              (LPCWSTR)szClassName.c_str(),                    (LPCWSTR)L"J-Fps",                 WS_OVERLAPPEDWINDOW | WS_EX_TOPMOST,            1000,                 1000,                  700,                         700,                            HWND_DESKTOP,                  NULL,                         hThisInstance,                  NULL                            );		   */		d3dpp.Windowed = true;		InFullScreen = false;		SetWindowLongPtr(hwnd, GWL_EXSTYLE, WS_OVERLAPPEDWINDOW);		SetWindowLongPtr(hwnd, GWL_EXSTYLE, WS_EX_TOPMOST);	}	else if(!InFullScreen)	{		d3dpp.Windowed = false;				d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;		d3dpp.BackBufferWidth = FSCREEN_WIDTH;   		d3dpp.BackBufferHeight = FSCREEN_HEIGTH;				InFullScreen = true;				hwnd = CreateWindowEx (           0,                              (LPCWSTR)szClassName.c_str(),                    (LPCWSTR)L"Windows App",              WS_EX_TOPMOST | WS_POPUP,            0,                 0,                  FSCREEN_WIDTH,                         FSCREEN_HEIGTH,                            HWND_DESKTOP,                  NULL,                         hThisInstance,                  NULL                            );	}	UpdateWindow(hwnd);	d3ddev->Reset(&d3dpp);}

Topic Locked

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

Sign in to reply to this topic.