Skip to main content
gamedev.net
🔒 Locked

Problematic code...

Started by DarkAvenger 9 replies 800+ views
Original Post
DarkAvenger
DarkAvenger
I went to the Aeon software site, and read the first tutorial on the basics of Windows programming in C++. And, much to my dismay, I get an error message while running the code. Specifically, it''s to do with the PeekMessage function; the three errors are: 1. "Missing '';'' before ''if''" 2. "Missing '';'' before ''{''" 3. "Missing function header(old style formal list?)" As a self-confessed newbie, I have no idea how to fix any of these errors. The last one is just Greek to me, and I''ve checked and checked again, but there seems to be no reason for the first two errors to occur. I''ve placed the message handling and PeekMessage functions outside WinMain(that is right, isn''t it?). What in the world is wrong ?
Authustian
Authustian
post the code and we can get a better look at it.

and yes the message handler should be in the wndproc part
-------------------------------------------------Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
DarkAvenger
DarkAvenger
OK, here's the code.. hope this helps.

#include windows.h
#include windowsx.h //I've removed the braces so that they render properly on the page
#define WIN32_LEAN_AND_MEAN

LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
return(DefWindowProc(hwnd, msg, wparam, lparam));
}

if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
WNDCLASSEX sampleClass;
sampleClass.cbSize = sizeof(WNDCLASSEX);
sampleClass.style = CS_DBLCLKS|CS_OWNDC|CS_HREDRAW|CS_VREDRAW;
sampleClass.lpfnWndProc = MsgHandler;
sampleClass.cbClsExtra = 0;
sampleClass.cbWndExtra = 0;
sampleClass.hInstance = hInstance;
sampleClass.hIcon = LoadIcon(NULL,IDI_WINLOGO);
sampleClass.hCursor = LoadCursor(NULL,IDC_ARROW);
sampleClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
sampleClass.lpszMenuName = NULL;
sampleClass.lpszClassName = "Sample Class";
sampleClass.hIconSm = LoadIcon(NULL,IDI_WINLOGO);

RegisterClassEx(&sampleClass);

HWND hwnd;

if (!(hwnd = CreateWindowEx(NULL,"Sample Class","Sample Window",WS_POPUP|WS_VISIBLE,0,0,320,240,NULL,NULL,hInstance,NULL)))

return(0);

}

Edited by - DarkAvenger on September 28, 2000 3:34:05 AM

Edited by - DarkAvenger on September 28, 2000 3:34:42 AM
Authustian
Authustian
ooo, i think i see your problem,

if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

should be in your winmain function in a loop like so

    
bool done=0; // make a global


while(!done) //loop untill done

{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message==WM_QUIT)
{
done=0; // we're done

}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
if(keys[VK_ESCAPE]) // Was There A Quit Received?

{
done=TRUE;
}
else {
gamemain(); }
}
}



hope that helps



-------------------------------------------------
Don't take life too seriously, you'll never get out of it alive. -Bugs Bunny

Edited by - Authustian on September 28, 2000 4:02:10 AM

Edited by - Authustian on September 28, 2000 4:06:11 AM
-------------------------------------------------Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
Authustian
Authustian
i fianly learned how to use that source block

-------------------------------------------------
Don't take life too seriously, you'll never get out of it alive. -Bugs Bunny

Edited by - Authustian on September 28, 2000 4:07:19 AM
-------------------------------------------------Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
Authustian
Authustian
o, and for my code to work you have to have the global

bool keys[256];

and in your message handler you need to have
    
switch(msg)
{
case WM_KEYDOWN:
{
keys[wParam] = TRUE;// If So, Mark It As TRUE
break;
}
case WM_KEYUP:
{
keys[wParam] = FALSE; break;
}
}




sorry about leaving that out




-------------------------------------------------
Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
-------------------------------------------------Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
DarkAvenger
DarkAvenger
Thanks for pointing that out, those error messages have stopped coming. But, I get another message now, saying that ''msg'' is an undeclared identifier; I assume it''s supposed to be the same variable we use in the message handler. Judging by the code I''ve posted, is there anything I should change? Thanks again for any help on the matter. Oh, and BTW, how do you get that code box ?
alexmoura
alexmoura
Just declare a
MSG msg;
at the start of your winmain function


You know, I never wanted to be a programmer...

Alexandre Moura

Edited by - alexmoura on September 28, 2000 5:45:21 AM
JS
JS
you''ll probably wanna #define WIN32_LEAN_AND_MEAN *before* you include the windows headers...

JS
http://www.thepeel.com/void
JShttp://www.thepeel.com/void

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.