#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;
}
Why does this close right away?
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:
Thanks a lot,
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement