请帮我检查一下这段代码哪里错了?谢谢!
程序可以运行,图也出来了,反应也是对的,但是按了一会儿鼠标后程序会卡住,我怀疑是leak了。。。但是实在找不到错误。。。还请您看一下。。。谢谢了!!
//*****************************************************************//#include"stdafx.h"#include <windows.h>#include <stdio.h>#include"mineswepper.h" LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);struct Block { bool ifOpened; //if the block has been clicked bool ifMined; //if the block contains a mine bool ifFlaged; //if user has flgged the block as a mine int minesAround; }; static Block blocks[20][20]; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ TCHAR szAppName[]=TEXT("Minesweeper"); TCHAR szClassName[]=TEXT("MinesweeperClassName"); HWND hwnd; MSG msg; WNDCLASS wndclass; wndclass.style=CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc =WndProc; wndclass.cbClsExtra =0; wndclass.cbWndExtra =0; wndclass.hInstance =hInstance; wndclass.hIcon =LoadIcon(NULL,IDI_APPLICATION); wndclass.hCursor =LoadCursor(NULL,IDC_ARROW); wndclass.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName =NULL; wndclass.lpszClassName =szClassName; RegisterClass(&wndclass); hwnd=CreateWindow(szClassName,TEXT("Mineswepper"), WS_OVERLAPPEDWINDOW &~ WS_SIZEBOX,CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL); ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while (GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam ;} LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){ PAINTSTRUCT ps; RECT rect; HDC hdc , hdcMem; static HBITMAP hBitmap; BITMAP bm; static int bmX = 0; static int bmY = 0; static int mouseX; static int mouseY; static int row = 20; static int coloum = 20; switch (message) { case WM_CREATE: { for(int i=0;i<row;++i) { for(int l=0;l<coloum;++l) { blocks[i][l].ifMined=false; blocks[i][l].ifFlaged=false; blocks[i][l].ifOpened=false; } } return 0; } case WM_PAINT: { hdc=BeginPaint(hwnd,&ps); for(int i=0;i<row;++i) { for(int l=0;l<coloum;++l) { if(!blocks[i][l].ifOpened) { //draw normal(unopened) hBitmap=(HBITMAP)LoadImage(NULL,TEXT("Blocks.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE); GetObject(hBitmap,sizeof(BITMAP),&bm); bmX=bm.bmWidth; bmY=bm.bmHeight; hdcMem=CreateCompatibleDC(hdc); SelectObject(hdcMem,hBitmap); BitBlt(hdc,(i*bmX),(l*bmY),bmX,bmY,hdcMem,0,0,SRCCOPY); DeleteDC(hdcMem); } if(blocks[i][l].ifOpened) { hBitmap=(HBITMAP)LoadImage(NULL,TEXT("mineKEYDOWN.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE); GetObject(hBitmap,sizeof(BITMAP),&bm); bmX=bm.bmWidth; bmY=bm.bmHeight; hdcMem=CreateCompatibleDC(hdc); SelectObject(hdcMem,hBitmap); BitBlt(hdc,(i*bmX),(l*bmY),bmX,bmY,hdcMem,0,0,SRCCOPY); DeleteDC(hdcMem); //draw opende box } } } EndPaint(hwnd,&ps); return 0; } case WM_LBUTTONDOWN: { mouseX=LOWORD(lParam); mouseY=HIWORD(lParam); if( (mouseX<(coloum*bmX)) && (mouseY<(row*bmY)) ) { int box_Y = (mouseX/bmX); int box_X = (mouseY/bmY); blocks[box_Y][box_X].ifOpened=true; rect.left=mouseX/bmX*bmX; rect.right=mouseX/bmX*bmX+bmX; rect.top=mouseY/bmY*bmY; rect.bottom=mouseY/bmY*bmY+bmY; } InvalidateRect(hwnd,&rect,true); return 0; } case WM_DESTROY: { DeleteObject(hBitmap); PostQuitMessage(0); return 0; } } return DefWindowProc(hwnd,message,wParam,lParam);}