Jump to content
  • Advertisement
Sign in to follow this  
GotenRulezU

Why does this close right away?

This topic is 5049 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

A friend and me looked it over and we couldn't figure out how to get it to work right. I can see it displays the right images but it closes right after. None of the messages ever get processed for some reason. Heres my source:
#include<windows.h>
#include<string>
using namespace std;
bool gameover = false;
HBITMAP tictactoe[3];
int Movemap[3][3]={
	{0,0,0},
	{0,0,0},
	{0,0,0}
};
void init(){
	tictactoe[0] = (HBITMAP)LoadImage(NULL,"blank.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
	tictactoe[1] = (HBITMAP)LoadImage(NULL,"x.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
	tictactoe[2] = (HBITMAP)LoadImage(NULL,"y.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
	tictactoe[3] = (HBITMAP)LoadImage(NULL,"lines.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
}
void makemove(int x, int y){
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam){
	switch(iMsg){
	case WM_DESTROY:
		PostQuitMessage(0);
		gameover = true;
		break;
	case WM_PAINT:
		PAINTSTRUCT ps;
		HDC hdc = BeginPaint(hwnd,&ps);
		HDC imagedc = CreateCompatibleDC(hdc);
		SelectObject(imagedc,tictactoe[3]);
		BitBlt(hdc,0,0,330,330,imagedc,0,0,SRCCOPY);
		for(int y = 0; y < 3; y++){
			for(int x = 0; x < 3; x++){
				SelectObject(imagedc,tictactoe[Movemap[x][y]]);
				BitBlt(hdc,(100 * x)+10,(100 * y) + 10,100,100,imagedc,0,0,SRCCOPY);
			}
		}
		
		DeleteDC(imagedc);
		EndPaint(hwnd,&ps);
		break;
		
	}
	return DefWindowProc(hwnd,iMsg,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hpInstance,PSTR cmdLine,int iCmd){
	init();
	WNDCLASS wc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wc.hCursor = LoadCursor(NULL,IDC_ARROW);
	wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
	wc.hInstance = hInstance;
	wc.lpfnWndProc = WndProc;
	wc.lpszClassName = "class";
	wc.lpszMenuName = NULL;
	wc.style = CS_VREDRAW|CS_HREDRAW;
	RegisterClass(&wc);
	HWND hwnd = CreateWindow("class","Window",WS_OVERLAPPEDWINDOW,0,0,800,600,NULL,NULL,hInstance,NULL);
	MSG msg;
	ShowWindow(hwnd,iCmd);
	UpdateWindow(hwnd);
	while(!gameover){
		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else{
		}
	}
	UnregisterClass("class",hInstance);
	return 0;
}

Thanks a lot,

Share this post


Link to post
Share on other sites
Advertisement
Just passing through, spotted this.

Your tictactoe array is defined with 3 elements - and then you load in 4 bitmaps in init(). It could just be a memory-overwrite based crash.

Jim.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!