Hi, beginner to directX following a tutorial to set up a simple window. nothing fancy just the window.
Two errors.
error C2065: 'wndHandle' : undeclared identifier
error C2065: 'WndProc' : undeclared identifier
These errors are present in
InitWindow.cpp
Heres my code
WinMain
/******************************************************************
* This is the main entry point for the Windows Application. *
* Its used to initialize the application, create the application *
* window and start the message loop. *
******************************************************************/
#include <windows.h>
#include <tchar.h>
//Globals
HINSTANCE hInst; // global handle to hold the application instance
HWND wndHandle; // global variable to hold the window handle
int width = 640;
int height = 480;
//forward declarations
bool InitWindow( HINSTANCE hInstance, int width, int height );
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
//winmain, main entry point for windows apps
int APIENTRY_tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow )
{
//intialize window
if( !InitWindow( hInstance, width, height) )
{
return false;
}
MSG msg = {0};
while (WM_QUIT != msg.message)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//additional game logic can be called from here
}
return (int) msg.wParam;
}
InitWindow
/*********************************************************
This registers a generic window with the system and then
uses this class to create a default window
*********************************************************/
#include <windows.h>
#include <tchar.h>
bool InitWindow(HINSTANCE hInstance, int width, int height)
{
WNDCLASSEX wcex;
//fill in the WNDCLASSEX structure. this describes how the window
//will look to the system
wcex.cbSize = sizeof(WNDCLASSEX); //the size of the structure
wcex.style = CS_HREDRAW | CS_VREDRAW; //the class style
wcex.lpfnWndProc = (WNDPROC)WndProc; //the window procedure callback
wcex.cbClsExtra = 0; //extra bytes to allocate for this class
wcex.cbWndExtra = 0; //extra bytes to allocate for this instance
wcex.hInstance = hInstance; //handle to the application instance
wcex.hIcon = 0; //icon to associate with the application
wcex.hCursor = LoadCursor(NULL, IDC_ARROW); //the default cursor to use
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); //the background colour
wcex.lpszMenuName = NULL; //the reseource name for the menu
wcex.lpszClassName = TEXT("DirectXExample"); //the class name being created
wcex.hIconSm = 0; //the hanndle to the small icon
RegisterClassEx(&wcex);
//resize the window
RECT rect = { 0, 0, width, height };
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
//create the window from the class above
wndHandle = CreateWindow(TEXT("DirectXExample"),
TEXT("DirectXExample"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
rect.right - rect.left,
rect.bottom - rect.top,
NULL,
NULL,
hInstance,
NULL);
if (!wndHandle)
{
return false;
}
//Display the window on the screen
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
return true;
}
WndProc
#include <windows.h>
#include <tchar.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//check available messages from the queue
switch (message)
{
//Allow the user to press the Escape key to end the application
case WM_KEYDOWN:
switch(wParam)
{
//check if the user hit the escape key
case VK_ESCAPE:
PostQuitMessage(0);
break;
}
break;
//The user hit the close button, close the application
case WM_DESTROY:
PostQuitMessage(0);
break;
}
//Always return the message to the default window procedure for further
//processing
return DefWindowProc(hWnd, message, wParam, lParam);
}
I have tried changing the character set from Unicode to Multi-byte character set but I still get the same two errors.
Would appreciate any help with this problem