/*
* NewGame
*/
#include <windows.h>
#include <stdlib.h>
#define WINDOWTITLE "Newgame"
#define WINDOWCLASS "wndClass"
HWND hwndMain;
HINSTANCE hInstMain;
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
// Check the messages being sent
switch(uMsg)
{
case WM_DESTROY:
{
// Tell the application we are quitting
PostQuitMessage(0);
return(0);
} break;
case WM_PAINT:
{
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
return(0);
} break;
}
// Pass away any other messages to default message handler
return(DefWindowProc(hwnd, uMsg, wParam, lParam));
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
// Assign instance to global variable
hInstMain = hInstance;
// Message structure
MSG msg;
// Create window class
WNDCLASSEX wcx;
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wcx.lpfnWndProc = WndProc;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = hInstMain;
wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
wcx.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wcx.lpszClassName = WINDOWCLASS;
wcx.hIconSm = NULL;
// register the window class
if(!RegisterClassEx(&wcx))
{
return(0);
}
hwndMain = CreateWindowEx(0, WINDOWCLASS, WINDOWTITLE, WS_BORDER | WS_SYSMENU | WS_CAPTION | WS_VISIBLE,
0, 0, 320, 240, NULL, NULL, hInstMain, NULL);
if(!hwndMain)
{
return(0);
}
for(;;)
{
// Look for a message
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// There is a message
// Check that we aren''t quitting
if(msg.message == WM_QUIT)
{
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// gameLoop();
}
//gameDone();
return(msg.wParam);
}
All programs I make crash??!?!
Everytime I make a win32 application even if its the simplest one it crashes, i get no errors or warnings and when it runs I get those stupid "Do you want to send report" things poping up!
Heres my code:
You''ve done atleast 2 mistakes here.
First of all, what makes your code crash is that you haven''t set the menuname to NULL. Secondly, the classname is supposed to be a string, so use "WINDOWCLASS" instead. I recommend using another name for it though. Use the string in the createwindow aswell.
Another small thing; instead of the for(;, use a while(PeekMessage(&msg,NULL,0,0,false)!=WM_QUIT). This ensures the loop isn''t run at all if the first message in the queue is a WM_QUIT. Otherwise, small bugs can creep in, that you won''t notice.
First of all, what makes your code crash is that you haven''t set the menuname to NULL. Secondly, the classname is supposed to be a string, so use "WINDOWCLASS" instead. I recommend using another name for it though. Use the string in the createwindow aswell.
Another small thing; instead of the for(;, use a while(PeekMessage(&msg,NULL,0,0,false)!=WM_QUIT). This ensures the loop isn''t run at all if the first message in the queue is a WM_QUIT. Otherwise, small bugs can creep in, that you won''t notice.
Thou shalt set all properties of thy window class, heathen!
(hint: wcx.lpszMenuName = ??)
Later,
ZE.
(hint: wcx.lpszMenuName = ??)
Later,
ZE.
quote:Original post by tok_junior
Secondly, the classname is supposed to be a string, so use "WINDOWCLASS" instead. I recommend using another name for it though.
Read the top of the window...
#define WINDOWCLASS "wndClass"
If a plant cannot live according to its nature, it dies; so a man.
(princ(substitute #\Space #\0(format()"~36R"5688852237040631986030796883)))
quote:Original post by ZealousElixir
Thou shalt set all properties of thy window class, heathen!
I dont know why but I found this quote to be amusing. Its like the 10 commandments of Windows programming.
"Give a man a fish and he will eat for a day, drown a man in the water and the fish will eat for a week!
Argh, beaten by half a minute. Oh well, ''least I got style.
@tok: WM_QUIT can never be the first message in the queue (get min/max info, then nccreate come first I think), and even if it were, the loop would break before the game logic was executed, as written. You should also be aware that the return value of PeekMessage is not Msg.message, but a Boolean indicator of whether messages were processed.
@tok: WM_QUIT can never be the first message in the queue (get min/max info, then nccreate come first I think), and even if it were, the loop would break before the game logic was executed, as written. You should also be aware that the return value of PeekMessage is not Msg.message, but a Boolean indicator of whether messages were processed.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement