#include <windows.h>
#include <cstdio>
#include <stdarg.h>
HINSTANCE g_hInst;
HWND g_hWnd;
#define WNDWIDTH 400
#define WNDHEIGHT 400
#define WNDTYPE WS_OVERLAPPEDWINDOW
const char g_szClass[] = "FrameClass";
const char g_szCaptation[] = "Frame Captation";
//entry point
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev,
LPSTR szCmdLine, int nCmdShow);
void AppError(BOOL Fatal, char *Text, ...);
long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);
//register and unregister classes
bool RegisterWindowsClasses(HINSTANCE hInst);
bool UnregisterWindowsClasses(HINSTANCE hInst);
//creates window
HWND CreateMainWindow(HINSTANCE hInst);
//funktions to init, shutdown, and handel per-frame funktions
BOOL DoInit();
BOOL DoShutDown();
BOOL DoPreFrame();
BOOL DoPostFrame();
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev,
LPSTR szCmdLine, int CmdShow)
{
MSG Msg;
g_hInst = hInst;
//register window
if((RegisterWindowsClasses(hInst)) == FALSE)
return FALSE;
//create window
if((g_hWnd = CreateMainWindow(hInst)) == NULL)
return FALSE;
if(DoInit() == TRUE)
{
ZeroMemory(&Msg, sizeof(MSG));
while(Msg.message != WM_QUIT)
{
if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
else
{
//do preframe rendering
if(DoPreFrame() == FALSE)
break;
//do postframe rendering
if(DoPostFrame() == FALSE)
break;
}
}
}
DoShutDown();
//unregister class
UnregisterWindowsClasses(hInst);
return TRUE;
}
BOOL RegisterWindowsClassex(HINSTANCE hInst)
{
WNDCLASSEX wcex;
//create and register window
wcex.cbSize = sizeof(wcex);
wcex.style = CS_CLASSDC;
wcex.lpfnWndProc = WindowProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInst;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = NULL;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = g_szClass;
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wcex))
return FALSE;
return TRUE;
}
BOOL UnregisterWindowClasses(HINSTANCE hInst)
{
UnregisterClass(g_szClass, hInst);
return TRUE;
}
HWND CreateMainWindow(HINSTANCE hInst)
{
HWND hWnd;
hWnd = CreateWindow(g_szClass, g_szCaptation, WNDTYPE, 0, 0,
WNDWIDTH, WNDHEIGHT,
NULL, NULL, hInst, NULL);
if(!hWnd)
return NULL;
ShowWindow(hWnd, SW_NORMAL);
UpdateWindow(hWnd);
return hWnd;
}
void AppError(BOOL Fatal, char *Text, ...)
{
char CaptationText[12];
char ErrorText[2048];
va_list valist;
if(Fatal == FALSE)
strcpy(CaptationText, "ERROR");
else
strcpy(CaptationText, "FATAL ERROR");
//build variable text buffer
va_start(valist, Text);
vsprintf(ErrorText, Text, valist);
va_end(valist);
//display the message
MessageBox(NULL, ErrorText, CaptationText, MB_OK | MB_ICONEXCLAMATION);
if(Fatal == TRUE)
PostQuitMessage(0);
}
long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
BOOL DoInit()
{
/*
performe application init functions here,
souch as those who setup grafics sound etc...
return true for succes
*/
return TRUE;
}
BOOL DoShutDown()
{
/*
performe application shutdowns here souch as shuting
down grafics sound etc...
returns true for succes
*/
return TRUE;
}
BOOL DoPreFrame()
{
/*
performe pre-frame proccesing here, souch as setting up timer...
return true for succes.
*/
return TRUE;
}
BOOL DoFrame()
{
/*
performe rendering and souch,
true if succes
*/
return TRUE;
}
BOOL DoPostFrame()
{
/*
performe postframe proccesing souch as synching
*/
return TRUE;
}
I cant get this windows app to work,
this code is from "programing roleplaying games with directx" and I must have missed something because I get these errors
X error LNK2019: unresolved external symbol "bool __cdecl RegisterWindowsClasses(struct HINSTANCE__ *)" (?RegisterWindowsClasses@@YA_NPAUHINSTANCE__@@@Z) referenced in function _WinMain@16
X error LNK2019: unresolved external symbol "bool __cdecl UnregisterWindowsClasses(struct HINSTANCE__ *)" (?UnregisterWindowsClasses@@YA_NPAUHINSTANCE__@@@Z) referenced in function _WinMain@16
X fatal error LNK1120: 2 unresolved externals
c:\Documents and Settings\Fredrik Sjöborg\Mina dokument\Visual Studio Projects\X\windows.cpp(165): warning C4244: ''return'' : conversion from ''LRESULT'' to ''long'', possible loss of data
and I have no clue what I did wrong.
here is the code
Link errors are generally the result of failure to link the appropriate source file/library in your project settings. I''m assuming LNK prefixes are link errors - certainly the error messages look like they could be link errors, but I don''t know MSVC++ well enough to suggest a detailed fix. Try rereading the book and checking your project settings. Somewhere there should be an option for which libraries are included. Possibly you chose the wrong options in setting up your project.
If anyone actually knows what they''re talking about with MSVC++, feel free to jump in...
If anyone actually knows what they''re talking about with MSVC++, feel free to jump in...
You have some typos in functions in the program:
You have:
BOOL RegisterWindowsClassex(HINSTANCE hInst){
Which should be:
BOOL RegisterWindowsClasses(HINSTANCE hInst){
You have:
BOOL UnregisterWindowClasses(HINSTANCE hInst){
Which should be:
BOOL UnregisterWindowsClasses(HINSTANCE hInst){
First thing you should check for on these kinds of errors is spelling mistakes.
First make it work,
then make it fast.
--Brian Kernighan
"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book
[edited by - CaptainJester on December 16, 2002 12:36:52 PM]
You have:
BOOL RegisterWindowsClassex(HINSTANCE hInst){
Which should be:
BOOL RegisterWindowsClasses(HINSTANCE hInst){
You have:
BOOL UnregisterWindowClasses(HINSTANCE hInst){
Which should be:
BOOL UnregisterWindowsClasses(HINSTANCE hInst){
First thing you should check for on these kinds of errors is spelling mistakes.
First make it work,
then make it fast.
--Brian Kernighan
"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book
[edited by - CaptainJester on December 16, 2002 12:36:52 PM]
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement