I get an error that says KEY_DOWN and main_window_handle are not declared. Are they suppost to be???Code:if (KEY_DOWN(VK_ESCAPR)) { PostMessage(main_window_handle, WM_DESTROY,0,0); }
I get an error that says KEY_DOWN and main_window_handle are not declared. Are they suppost to be???Code:if (KEY_DOWN(VK_ESCAPR)) { PostMessage(main_window_handle, WM_DESTROY,0,0); }
Your mom is like a struct, she has no class
How many C programmers does it take to screw in a light bulb? One to do it, 99 to tell him how to do it faster.
Got any other code or is that it?
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
Yes! Define them...
Code:#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) #define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1) HWND main_window_handle; //make sure you set this to hwnd passed to WinMain later...Code:if (KEY_DOWN(VK_ESCAPR)) //wrong if (KEY_DOWN(VK_ESCAPE)) //right
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
so how would I do that? Thoe following is my WinMainCode://make sure you set this to hwnd passed to WinMain later...
Code:int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASSEX winclass; // this will hold the class we create HWND hwnd; // generic window handle MSG msg;// generic message // first fill in the window class stucture winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinstance; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = WINDOW_CLASS_NAME; winclass.hIconSm = LoadIcon(NULL, "G3D.ICO"); // register the window class if (!RegisterClassEx(&winclass)) return(0); // create the window if (!(hwnd = CreateWindowEx(0, // extended style WINDOW_CLASS_NAME, // class "Geo 3D Game Engine V1.0 Alpha -- By Ryan ****** ©", // title WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0,0, // initial x,y 800,600, // initial width, height NULL, // handle to parent NULL, // handle to menu hinstance,// instance of this application NULL))) // extra creation parms return(0); //Calls Game Initilizastion int Game_Init(); // enter main event loop while(1) { if (PeekMessage(&msg, NULL,0,0,PM_REMOVE)) { //Test if this is a quit. if (msg.message == WM_QUIT) break; //Translate any accelerator keys TranslateMessage(&msg); //Send message to window proc. DispatchMessage(&msg); } //end IF(PeekMessage); // Calls Game_Shutdown int Game_Shutdown(); }// end while(1); //Call Game_Shutdown int Game_Shutdown(); //Return to windows return(msg.wParam); }//end WinMain
Your mom is like a struct, she has no class
How many C programmers does it take to screw in a light bulb? One to do it, 99 to tell him how to do it faster.
Where is the code that causes the error?
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
look at Jawibs post above.
~Trooper
Your mom is like a struct, she has no class
How many C programmers does it take to screw in a light bulb? One to do it, 99 to tell him how to do it faster.
No, I mean, you haven't actually posted up the code and it's context that actually causes the error. Posting up a few lines isn't enough, I need to know what function it's in and what other code is there. Just post your entire code.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
okay here's the .cpp file
~Trooper
Your mom is like a struct, she has no class
How many C programmers does it take to screw in a light bulb? One to do it, 99 to tell him how to do it faster.
That's where I'd put it. I think WM_CREATE is just about the earliest place you can put the code, except maybe WM_NCCREATE.Code:case WM_CREATE: { // do initialization stuff here main_window_handle=hwnd; return(0); }
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
You could probably put it right after you create the windowCode:if (!(hwnd = CreateWindowEx(0, // extended style WINDOW_CLASS_NAME, // class "Geo 3D Game Engine V1.0 Alpha -- By Ryan ****** ©", // title WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0,0, // initial x,y 800,600, // initial width, height NULL, // handle to parent NULL, // handle to menu hinstance,// instance of this application NULL))) // extra creation parms return(0);
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
Placing it in the WM_NCCREATE handler would come before that, Jawib. A lot happens before CreateWindowEx() returns.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
But that would be even before the message pump begins, handling your WM_NCCREATE message. Unless CreateWindowEx() calls your message handler on its own?
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Ummmmmmmmmm.........
you could put it here
if (!(main_window_handle = CreateWindowEx(0, WINDOW_CLASS_NAME,
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
That's probably the best place to put it really. If you also initialize the variable with NULL in the first place, then you can be assured that whenever you use the handle, it will either point to a window that has been created and is valid, or it will be NULL, in which case it'll just get flagged as invalid. If you were to place the assignment in WM_NCCREATE, and by chance some function used the handle before WM_CREATE returned, you might have some problems.
So I guess novacain is right. Do the following:
This way, main_window_handle does not have the window handle until WM_CREATE returns, which is a good thing IMO.Code://at the top of the file HWND main_window_handle=NULL; . . . int WINAPI WinApi(...) { . . . main_window_handle=CreateWindowEx(...); if (!main_window_handle) exit(1);
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials