I am trying to learn Direct 3D, but this issue has nothing to do with DirectX...
I have a simple application that creates a device and clears the screen to a standard color each frame. I wanted to make it full screen, because I'm just playing with settings...and I'm having an issue with the CreateWindowEx function.
My Code:
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#pragma comment (lib, "d3d9.lib")
#define SCREEN_WIDTH 640;
#define SCREEN_HEIGHT 480;
//Global Declerations
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
void initD3D(HWND hWnd);
void render_frame();
void cleanD3D();
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nShowCmd)
{
HWND hWnd;
WNDCLASSEX wndclass;
MSG msg;
ZeroMemory(&wndclass, sizeof(WNDCLASSEX));
wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.hIcon = NULL;
wndclass.hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hInstance = hInstance;
wndclass.cbClsExtra = 0;
wndclass.lpszClassName = "WindowClass";
//wndclass.hbrBackground = (HBRUSH)COLOR_WINDOW;
RegisterClassEx(&wndclass);
hWnd = CreateWindowEx(NULL,
"WindowClass",
"D3D WEB TUTOR",
WS_EX_TOPMOST | WS_POPUP,
0, 0,
SCREEN_WIDTH, //This line and
SCREEN_HEIGHT, //this line are giving me problems...errors below
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, nShowCmd);
initD3D(hWnd);
while(TRUE)
{
DWORD starting_point = GetTickCount();
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
render_frame();
while((GetTickCount() - starting_point) < 25);
}
cleanD3D();
return msg.wParam;
}
void initD3D(HWND hWnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = SCREEN_WIDTH;
d3dpp.BackBufferHeight = SCREEN_HEIGHT;
d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);
return;
}
void render_frame()
{
//Clear Window
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 cleanD3D()
{
d3ddev->Release();
d3d->Release();
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}break;
}
return ::DefWindowProc(hWnd, msg, wParam, lParam);
}
When I compile I get:
Error 1 error C2143: syntax error : missing ')' before ';' d:\learning\gameprogramming\dx\docu\dxlearning\webtut1\main.cpp 47
Error 2 error C2660: 'CreateWindowExA' : function does not take 7 arguments d:\learning\gameprogramming\dx\docu\dxlearning\webtut1\main.cpp 47
Error 3 error C2143: syntax error : missing ';' before ',' d:\learning\gameprogramming\dx\docu\dxlearning\webtut1\main.cpp 47
Error 4 error C2143: syntax error : missing ';' before ',' d:\learning\gameprogramming\dx\docu\dxlearning\webtut1\main.cpp 48
Error 5 error C2059: syntax error : ')' d:\learning\gameprogramming\dx\docu\dxlearning\webtut1\main.cpp 52
The only way I have been able to get rid of the errors is to change the lines to:
//...
hWnd = CreateWindowEx(NULL,
"WindowClass",
"D3D WEB TUTOR",
WS_EX_TOPMOST | WS_POPUP,
0, 0,
640, //Width and
480, //Height, can't use my #define variables??
NULL,
NULL,
hInstance,
NULL);
//...
This compiles and runs fine, but I don't like using "Magic Numbers" in my programs. Anyone have any idea?