🔒 Locked
Problematic code...
Advertisement
Original Post
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
?
post the code and we can get a better look at it. 
and yes the message handler should be in the wndproc part
and yes the message handler should be in the wndproc part
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
#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
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
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
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
should be in your winmain function in a loop like so
|
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
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
Edited by - Authustian on September 28, 2000 4:07:19 AM
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
sorry about leaving that out
-------------------------------------------------
Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
bool keys[256];
and in your message handler you need to have
|
sorry about leaving that out
-------------------------------------------------
Don't take life too seriously, you''ll never get out of it alive. -Bugs Bunny
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
?
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement