Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

nickwinters

Why is this full screen?

This topic is 5283 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I really feel bad just posting a bunch of sourcecode here, but I can't figure out why this is full screen. I've taken this from Chapter 6 of Direct3D Kick Start. I've set every flag to windowed mode. Why is this full screen? Thanks. -Nick
//////////////////////////////////////////////////////
// BasicWindowsApp.cpp
//////////////////////////////////////////////////////

#include <windows.h>
#include <d3d9.h>
#include <d3dx9tex.h>
#include <dxerr9.h>

// Function prototypes.
LRESULT WINAPI WndProc(HWND hWnd, UINT msg,
    WPARAM wParam, LPARAM lParam);
void RegisterWindowClass(HINSTANCE hInstance);
void CreateAppWindow(HINSTANCE hInstance);
WPARAM StartMessageLoop();
HRESULT InitDirect3D();
void Render();
void CleanUpDirect3D();

// Global variables.
HWND g_hWnd;
IDirect3D9* g_pDirect3D=NULL;
IDirect3DDevice9* g_pDirect3DDevice=NULL;
IDirect3DSurface9* g_pBitmapSurface=NULL;
HRESULT g_hResult=D3D_OK;
char g_szErrorMsg[256];


//////////////////////////////////////////////////////
// WinMain()
//////////////////////////////////////////////////////
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, INT)
{
    RegisterWindowClass(hInstance);
    CreateAppWindow(hInstance);
    ShowWindow(g_hWnd, SW_SHOWDEFAULT);
    UpdateWindow(g_hWnd);
    HRESULT hResult=InitDirect3D();
	if(SUCCEEDED(hResult))
	{
		WPARAM result=StartMessageLoop();
	}
	CleanUpDirect3D();
	CloseWindow(g_hWnd);
	if(g_hResult!=D3D_OK)
	{
		DXTRACE_ERR(g_szErrorMsg, g_hResult);
	}
    return 0;
}

//////////////////////////////////////////////////////
// WndProc()
//////////////////////////////////////////////////////
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
		case WM_CREATE:
			return 0;

		case WM_DESTROY:
			PostQuitMessage( 0 );
			return 0;

		case WM_PAINT:
			ValidateRect(g_hWnd, NULL);
			return 0;
		
		case WM_KEYDOWN:
			switch(wParam)
			{
				case VK_ESCAPE:
					PostQuitMessage(WM_QUIT);
					break;
			}

    }
    return DefWindowProc(hWnd, msg, wParam, lParam);
}

//////////////////////////////////////////////////////
// RegisterWindowClass()
//////////////////////////////////////////////////////
void RegisterWindowClass(HINSTANCE hInstance)
{
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0; 
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = (HCURSOR)LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "SurfaceApp";
    wc.hIconSm = NULL;

    RegisterClassEx(&wc);
}

//////////////////////////////////////////////////////
// CreateAppWindow()
//////////////////////////////////////////////////////
void CreateAppWindow(HINSTANCE hInstance)
{
    g_hWnd = CreateWindowEx(
        NULL,
        "SurfaceApp",
        "Direct3D Surface Application", 
        WS_OVERLAPPEDWINDOW,
        100,
        100,
        648,
        514,
        GetDesktopWindow(),
        NULL,
        hInstance,
        NULL);
}

//////////////////////////////////////////////////////
// StartMessageLoop()
//////////////////////////////////////////////////////
WPARAM StartMessageLoop()
{
    MSG msg;
    while(1)
    {
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            if (msg.message == WM_QUIT)
                break;
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
        {
            Render();
        }
    }
    return msg.wParam;
}

HRESULT InitDirect3D()
{
	g_pDirect3D=Direct3DCreate9(D3D_SDK_VERSION);
	if(g_pDirect3D==NULL)
	{
		MessageBox(g_hWnd, "Couldn't create DirectX object.", "DirectX Error", MB_OK);
		return E_FAIL;
	}

	HRESULT hResult=g_pDirect3D->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
												D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, FALSE);

	D3DPRESENT_PARAMETERS D3DPresentParams;
	ZeroMemory(&D3DPresentParams, sizeof(D3DPRESENT_PARAMETERS));
	D3DPresentParams.Windowed=FALSE;
	D3DPresentParams.BackBufferCount=1;
	D3DPresentParams.BackBufferWidth=640;
	D3DPresentParams.BackBufferHeight=480;
	D3DPresentParams.BackBufferFormat=D3DFMT_X8R8G8B8;
	D3DPresentParams.SwapEffect=D3DSWAPEFFECT_DISCARD;
	D3DPresentParams.hDeviceWindow=g_hWnd;
	hResult=g_pDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING,
			&D3DPresentParams, &g_pDirect3DDevice);
	if(FAILED(hResult))
	{
		MessageBox(g_hWnd, "Failed to create Direct3D device.", "DirectX Error", MB_OK);
		return E_FAIL;
	}

	g_hResult=g_pDirect3DDevice->CreateOffscreenPlainSurface(640, 480, D3DFMT_X8R8G8B8,
									D3DPOOL_DEFAULT, &g_pBitmapSurface, NULL);
	if(FAILED(g_hResult))
	{
		strcpy(g_szErrorMsg, "Error creating bitmap surface.");
		PostQuitMessage(WM_QUIT);
	}
	g_hResult=D3DXLoadSurfaceFromFile(g_pBitmapSurface, NULL, NULL, "image.bmp", NULL,
									D3DX_DEFAULT, 0, NULL);
	if(FAILED(g_hResult))
	{
		strcpy(g_szErrorMsg, "Couldn't load bitmap file.");
		PostQuitMessage(WM_QUIT);
	}
	return D3D_OK;
}

void CleanUpDirect3D()
{
	if(g_pBitmapSurface)
	{
		g_pBitmapSurface->Release();
	}
	if(g_pDirect3DDevice)
	{
		g_pDirect3DDevice->Release();
	}
	if(g_pDirect3D)
	{
		g_pDirect3D->Release();
	}
}

void Render()
{
	IDirect3DSurface9* pBackBuffer=NULL;
	g_hResult=g_pDirect3DDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);
	if(FAILED(g_hResult))
	{
		strcpy(g_szErrorMsg, "Error getting back buffer.");
		PostQuitMessage(WM_QUIT);
	}
	g_hResult=g_pDirect3DDevice->StretchRect(g_pBitmapSurface, NULL, pBackBuffer, NULL, D3DTEXF_NONE);
	if(FAILED(g_hResult))
	{
		strcpy(g_szErrorMsg, "Error copying image buffer.");
		PostQuitMessage(WM_QUIT);
	}
	g_pDirect3DDevice->Present(NULL, NULL, NULL, NULL);
	if(pBackBuffer)
	{
		pBackBuffer->Release();
	}
}  
[edited by - nickwinters on June 2, 2004 1:59:40 PM]

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by nickwinters
I''ve set every flag to windowed mode.

Umm, you missed one:

D3DPresentParams.Windowed=FALSE;

Share this post


Link to post
Share on other sites
quote:
Original post by nickwinters
I've set every flag to windowed mode.


No, you haven't.
The most important setting for windowed mode, from your code:
D3DPresentParams.Windowed=FALSE;  


-Nik

EDIT: Machaira outpaced me

[edited by - Nik02 on June 2, 2004 2:09:32 PM]

Share this post


Link to post
Share on other sites
I''m an idiot. I kept thinking that true would make it fullscreen. Not sure which API has the variable fullscreen instead of windowed... Oh well.

Thank you for your help.

Share this post


Link to post
Share on other sites
quote:
Original post by nickwinters
I''m an idiot. I kept thinking that true would make it fullscreen. Not sure which API has the variable fullscreen instead of windowed... Oh well.

Thank you for your help.


SDL.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!