I'm prepared to be told this is bleedingly obvious, but I'm just testing the waters of DirectX. Code so far:
App.h
Code:
#ifndef APP_H
#define APP_H
#include <Windows.h>
#include <d3d9.h>
//global finctions
//handle any messages from windows
LRESULT CALLBACK wndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam);
//main entry point
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd);
//global variables
IDirect3D9 *g_pD3D;
IDirect3DDevice9 *g_pD3DDevice;
#define WINDOW_WIDTH 300
#define WINDOW_HEIGHT 200
//error macro debugging
#define ERROR(msg) {MessageBox(NULL,msg,L"Error",MB_OK|MB_ICONEXCLAMATION);}
#endif
WinMain.cpp
Code:
#include "App.h"
#include <Windows.h>
#include <d3d9.h>
LRESULT CALLBACK wndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CLOSE:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
//main method
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) wndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = L"DirectXWindow";
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
RECT rect;
rect.top = (long)0;
rect.left = (long)0;
rect.right = (long)WINDOW_WIDTH;
rect.bottom = (long)WINDOW_HEIGHT;
//REGISTER
if(!RegisterClassEx(&wc))
{
ERROR(L"Error couold not RegisaterClass");
return 0;
}
//calculates the required size of the window
AdjustWindowRectEx(&rect,
WS_OVERLAPPEDWINDOW,
FALSE,
WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
HWND hWindow = CreateWindowEx(NULL,
L"DirectXWidnow",
L"DirectX Window!",
WS_CLIPSIBLINGS | WS_CLIPSIBLINGS,
0,0,
rect.right-rect.left,
rect.bottom-rect.top,
NULL, NULL,
hInstance,
NULL);
if (!hWindow)
{
DestroyWindow(hWindow);
UnregisterClass(L"DirectXWindow", hInstance);
ERROR(L"Window Creation Error.");
return 0;
}
ShowWindow(hWindow,SW_SHOW);
UpdateWindow(hWindow);
SetForegroundWindow(hWindow);
SetFocus(hWindow);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = true;
d3dpp.hDeviceWindow = hWindow;
d3dpp.BackBufferWidth = WINDOW_WIDTH;
d3dpp.BackBufferHeight = WINDOW_HEIGHT;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
//GET A HOLD ON VERSION
g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
//CREATE DEVICE
if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWindow,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&g_pD3DDevice)))
{
ERROR(L"Failed to create device");
}
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
g_pD3DDevice->Clear(0,0,
D3DCLEAR_TARGET,
D3DCOLOR_XRGB(0,0,0),
1.0f,0.0f);
g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
TranslateMessage (&msg);
DispatchMessage (&msg);
}
g_pD3D->Release();
g_pD3DDevice->Release();
return 0;
}
Gives the message LNK1104 cannot open file d3dx9.lib d3d9.lib winmain.lib
If I use d3dx9.h for the include lines, it is not recognised even though that header file appears to be in the relevant folder.
I am using VC++ 2010 and running DirectX 9 (graphics card won't support HiDef or DirectX 10/11 so not an option yet) I have made a separate program just for windows.h and that works fine, just an empty window.