具体资源见:http://download.csdn.net/detail/zhouyelihua/7604765
在学习windows程序设计中,我们希望通过一个完整的程序来学习windows API这是本人在上杨力祥老师的课程是自己写的扫雷程序。
下面是。cpp文件
#include <windows.h> #include"resource.h" #include<stdlib.h> #pragma comment( lib,"winmm.lib") //地雷的结构 class Mine{ int x,y; int value; bool zeroCursor; bool dis_or_not; int cur3; public: bool getZerocursor(); void setZerocursor(bool cur); void setDisOrNot(bool d); void setX(int xx); void setY(int yy); void setValue(int val); void dispaly(); int getvalue() ; bool getdisval() ; int getcur3(); void setcur3(int d); }; int Mine::getcur3() { return cur3; } void Mine::setcur3(int d) { cur3=d; } bool Mine::getZerocursor() { return zeroCursor; } void Mine::setZerocursor(bool cur) { zeroCursor=cur; } bool Mine::getdisval() { return (dis_or_not); } void Mine::setDisOrNot(bool d) { dis_or_not=d; } void Mine::setX(int xx) { x=xx; } void Mine::setY(int yy) { y=yy; } void Mine::setValue(int val) { value=val; } void Mine::dispaly() { if(dis_or_not==true)//如果这块被翻起了,那么显示这一块的值 { ; } else{//没有被翻过,那么遮盖 ; } ; } int Mine::getvalue() { return value; } //=======函数声明=========== void SearchZeroMine(Mine*mat,int row,int column,HDC hdc,int x,int y); void SetMinesAround(Mine*mat,int row,int coulumn); LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; void display(Mine*mineMat,int row,int column,HDC hdc); void WindowSize(HWND hwnd,int width,int height); void initMineMatrix(Mine*mineMat,int row,int column); void clickRespond(Mine*mineMat,int x,int y,HDC hdc,HWND hwnd); VOID TimerProc(HWND hwnd); void landMineFunc(Mine*mineMat,int row,int column,int mineNum); //======全局变量声明============ static int row,column,NumMine; static int Tswitch=0; static int time; static int pickMineNum=0; static bool sound=false; Mine* mineMatrix; static bool dis;//判断是否踩雷了,踩了则不继续 static HBITMAP hBitmap1,hBitmap2,hBitmap3,hBitmap4,hBitmap5,hBitmap6; static HDC hdcMem1,hdcMem2,hdcMem3,hdcMem4,hdcMem5,hdcMem6; DWORD g_tPre=0,g_tNow=0; //声明l两个函数来记录时间,g_tPre记录上一次绘图的时间,g_tNow记录此次准备绘图的时间 //=======改变窗口大小的函数======= //=======初始化雷区矩阵========= BOOL CALLBACK HeroProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam) //英雄榜 { switch(msg) { case WM_COMMAND: switch(LOWORD(wParam)) { case IDOK: case IDCANCEL: EndDialog(hDlg,0); return TRUE; } } return false; } BOOL CALLBACK dlgProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) { // BOOL flag; int rowtmp,coltmp,minetmp; switch (msg) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: rowtmp=GetDlgItemInt(hwnd,IDC_EDIT1,NULL,true); coltmp=GetDlgItemInt(hwnd,IDC_EDIT2,NULL,true); minetmp=GetDlgItemInt(hwnd,IDC_EDIT3,NULL,true); if((rowtmp>=9)&&(coltmp>=9)&&(rowtmp*coltmp>minetmp)) { row=rowtmp; column=coltmp; NumMine=minetmp; } EndDialog(hwnd, IDOK); case IDCANCEL: EndDialog(hwnd, IDOK); return TRUE; } break; case WM_DESTROY: return TRUE; } return FALSE; } int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("winmine") ; HWND hwnd ; MSG msg= { 0 };; WNDCLASS wndclass ; HMENU hMenu; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (hInstance,MAKEINTRESOURCE(IDI_ICON1)) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; hMenu=LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENU1)); if (!RegisterClass (&wndclass)) { MessageBox (NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow (szAppName, // window class name TEXT ("扫雷"), // window caption WS_OVERLAPPED |WS_CAPTION |WS_SYSMENU| WS_MINIMIZEBOX, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position CW_USEDEFAULT, // initial x size CW_USEDEFAULT, // initial y size NULL, // parent window handle hMenu, // window menu handle hInstance, // program instance handle NULL) ; // creation parameters row=9; column=9; HDC hdc=GetDC(hwnd); hdcMem1 = CreateCompatibleDC (hdc) ; hdcMem2 = CreateCompatibleDC (hdc) ; hdcMem3 = CreateCompatibleDC (hdc) ; hdcMem4 = CreateCompatibleDC (hdc) ; hdcMem5 = CreateCompatibleDC (hdc) ; hdcMem6 = CreateCompatibleDC (hdc) ; WindowSize(hwnd,18+column*16,row*16+59); NumMine=10; initMineMatrix(mineMatrix, row, column); landMineFunc(mineMatrix, row, column, NumMine); SetMinesAround(mineMatrix,row,column); ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while( msg.message != WM_QUIT ) //使用while循环,如果消息不是WM_QUIT消息,就继续循环 { if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) ) //查看应用程序消息队列,有消息时将队列中的消息派发出去。 { TranslateMessage( &msg ); //将虚拟键消息转换为字符消息 DispatchMessage( &msg ); //分发一个消息给窗口程序。 } else { g_tNow = GetTickCount(); //获取当前系统时间 if(g_tNow-g_tPre >= 1000) //当此次循环运行与上次绘图时间相差0.03秒时再进行重绘操作 TimerProc(hwnd); } } return msg.wParam ; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps ; RECT rect1 ; HPEN hPen1; HBRUSH hbrush1; HMENU hMenu; HINSTANCE hInstance; static int iSelection=ID_40002; static int iSelection1=ID_40008; //int i,j,k; int locr; wchar_t szbuf[7]={0}; int x,y; switch (message) { case WM_CREATE: hInstance = ((LPCREATESTRUCT) lParam)->hInstance ; hBitmap1 = LoadBitmap (hInstance,MAKEINTRESOURCE (IDB_BITMAP1)) ; hBitmap2=LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP2)); hBitmap3=LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP3)); hBitmap4= LoadBitmap (hInstance,MAKEINTRESOURCE (IDB_BITMAP4)) ; hBitmap5=LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP5)); hBitmap6=LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP6)); return 0; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; SetRect(&rect1,0,0,18+column*16,row*16+59); hbrush1=CreateSolidBrush(RGB(192,192,192)); FillRect(hdc,&rect1,hbrush1); hPen1=CreatePen(PS_SOLID,3,RGB(128,128,128)); SelectObject(hdc,hPen1); Rectangle(hdc,6,6,18+column*16-6,41); SetRect(&rect1,8,8,18+column*16-8,39); FillRect(hdc,&rect1,hbrush1); Rectangle(hdc,6,50,18+column*16-6,row*16+59-6); SelectObject(hdcMem3,hBitmap3); //{column*16-30,12,column*16+9,35}; BitBlt (hdc, 12 ,12, 13, 23, hdcMem3, 0,253-23*(NumMine/100%10), SRCCOPY) ; BitBlt (hdc,25 ,12, 13, 23, hdcMem3, 0,253-23*(NumMine/10%10), SRCCOPY) ; BitBlt (hdc, 38 ,12, 13, 23, hdcMem3, 0,253-23*(NumMine%10), SRCCOPY) ; BitBlt (hdc,column*16-33 ,12, 13, 23, hdcMem3, 0,23, SRCCOPY) ; BitBlt (hdc,column*16-20 ,12, 13, 23, hdcMem3, 0,23, SRCCOPY) ; BitBlt (hdc,column*16-7 ,12, 13, 23, hdcMem3, 0,23, SRCCOPY) ; SelectObject(hdcMem5,hBitmap5); BitBlt (hdc, column*8-3,10 , 24, 24, hdcMem5, 0,96, SRCCOPY) ; display(mineMatrix,row,column,hdc); EndPaint (hwnd, &ps) ; return 0 ; case WM_COMMAND: hMenu=GetMenu(hwnd); hInstance=GetModuleHandle(0); switch(LOWORD(wParam)) { // CheckMenuItem (hMenu,LOWORD (wParam), MF_CHECKED) ; case ID_40001://开局 hdc=GetDC(hwnd); // CheckMenuItem (hMenu, iSelection, MF_UNCHECKED) ; // iSelection = LOWORD (wParam) ; CheckMenuItem (hMenu, iSelection, MF_UNCHECKED) ; iSelection = LOWORD (wParam) ; CheckMenuItem (hMenu, iSelection, MF_CHECKED) ; //KillTimer(hwnd,ID_TIMER1); Tswitch=0; time=0; pickMineNum=0; BitBlt (hdc,column*16-33 ,12, 13, 23, hdcMem3, 0,23, SRCCOPY) ; BitBlt (hdc,column*16-20 ,12, 13, 23, hdcMem3, 0,23, SRCCOPY) ; BitBlt (hdc,column*16-7 ,12, 13, 23, hdcMem3, 0,23, SRCCOPY) ; initMineMatrix(mineMatrix,row, column); display(mineMatrix, row, column, hdc); landMineFunc(mineMatrix, row, column, NumMine);//布雷函数 SetMinesAround(mineMatrix,row,column); DeleteDC(hdc); return 0; case ID_40002://初级 CheckMenuItem (hMenu, iSelection, MF_UNCHECKED) ; iSelection = LOWORD (wParam) ; CheckMenuItem (hMenu, iSelection, MF_CHECKED) ; column=9; row=9; NumMine=10; Tswitch=0; time=0; WindowSize(hwnd,18+column*16,row*16+59); initMineMatrix(mineMatrix, row, column); landMineFunc(mineMatrix, row, column, NumMine); SetMinesAround(mineMatrix,row,column); return 0; case ID_40003://中级 CheckMenuItem (hMenu, iSelection, MF_UNCHECKED) ; iSelection = LOWORD (wParam) ; CheckMenuItem (hMenu, iSelection, MF_CHECKED) ; column=16; row=16; NumMine=40; Tswitch=0; time=0; WindowSize(hwnd,18+column*16,row*16+59); initMineMatrix(mineMatrix, row, column); landMineFunc(mineMatrix, row, column, NumMine); SetMinesAround(mineMatrix,row,column); return 0; case ID_Menu://高级 CheckMenuItem (hMenu, iSelection, MF_UNCHECKED) ; iSelection = LOWORD (wParam) ; CheckMenuItem (hMenu, iSelection, MF_CHECKED) ; column=30; row=16; NumMine=99; Tswitch=0; time=0; WindowSize(hwnd,18+column*16,row*16+59); initMineMatrix(mineMatrix, row, column); landMineFunc(mineMatrix, row, column, NumMine); SetMinesAround(mineMatrix,row,column); return 0; case ID_40005: CheckMenuItem (hMenu, iSelection, MF_UNCHECKED) ; iSelection = LOWORD (wParam) ; CheckMenuItem (hMenu, iSelection, MF_CHECKED) ; DialogBox(hInstance,MAKEINTRESOURCE(IDD_USERDEFINE),NULL,dlgProc); Tswitch=0; time=0; WindowSize(hwnd,18+column*16,row*16+59); initMineMatrix(mineMatrix, row, column); landMineFunc(mineMatrix, row, column, NumMine); SetMinesAround(mineMatrix,row,column); return 0; case ID_40008: CheckMenuItem (hMenu, iSelection1, MF_UNCHECKED) ; iSelection1 = LOWORD (wParam) ; CheckMenuItem (hMenu, iSelection1, MF_CHECKED) ; sound=!sound; return 0; case ID_40009: DialogBox(hInstance,MAKEINTRESOURCE(IDD_HERO),NULL,HeroProc); return 0; case ID_40014://关于扫雷 MessageBox(hwnd,TEXT("研究所:深圳先进技术研究\n实验室:智能设计与计算机视觉实验室\n姓名 :叶于平"),TEXT("关于扫雷"),NULL); } break; case WM_LBUTTONDOWN: hdc=GetDC(hwnd); x= LOWORD (lParam) ; y = HIWORD (lParam) ; clickRespond(mineMatrix,x, y,hdc,hwnd); DeleteDC(hdc); return 0; case WM_RBUTTONDOWN: hdc=GetDC(hwnd); x= LOWORD (lParam) ; y = HIWORD (lParam) ; if(dis==false) if((x>=9)&&(x<9+16*column)&&(y>=52)&&(y<52+16*row)) { locr=((y-52)/16)*column+(x-9)/16; if(mineMatrix[locr].getdisval()==false) { if(mineMatrix[locr].getcur3()==-1) mineMatrix[locr].setcur3(0); if(mineMatrix[locr].getcur3()==0) { BitBlt (hdc,((x-9)/16)*16+9,((y-52)/16)*16+52, 16, 16, hdcMem1, 0,16, SRCCOPY) ; } if(mineMatrix[locr].getcur3()==1) { BitBlt (hdc,((x-9)/16)*16+9,((y-52)/16)*16+52, 16, 16, hdcMem1, 0,32, SRCCOPY) ; } if(mineMatrix[locr].getcur3()==2) { BitBlt (hdc,((x-9)/16)*16+9,((y-52)/16)*16+52, 16, 16, hdcMem1, 0,0, SRCCOPY) ; } if(mineMatrix[locr].getcur3()==2) mineMatrix[locr].setcur3(0); else mineMatrix[locr].setcur3(mineMatrix[locr].getcur3()+1); } } DeleteDC(hdc); return 0; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; } void initMineMatrix(Mine*mineMat,int row,int column) { int i; dis=false; for(i=0;i<row*column;i++) { mineMat[i].setX(i/column); mineMat[i].setY(i%column); mineMat[i].setValue(0); mineMat[i].setDisOrNot(false); mineMat[i].setZerocursor(false); mineMat[i].setcur3(-1); } } //----输入:窗口的宽和高.并且设置雷区矩阵大小。 void WindowSize(HWND hwnd,int width,int height) { RECT sizeWin; RECT sizeClient; int borderWidth,borderHeight; GetWindowRect(hwnd,&sizeWin); GetClientRect(hwnd,&sizeClient); borderWidth = (sizeWin.right-sizeWin.left)-(sizeClient.right-sizeClient.left); borderHeight = (sizeWin.bottom-sizeWin.top)-(sizeClient.bottom-sizeClient.top); SetWindowPos(hwnd,0,0,0,borderWidth+width,borderHeight+height,SWP_NOMOVE|SWP_NOZORDER); mineMatrix=new Mine[row*column]; } //======显示函数========= void display(Mine*mineMat,int row,int column,HDC hdc) { //HDC hdcMemOld; SelectObject (hdcMem1, hBitmap1) ; int i, j; for(j=0;j<row;j++) for(i=0;i<column;i++) //if((mineMat[i*column+j].getdisval())==false)//如果不显示 则是显示用盖住 BitBlt (hdc, i*16+9, j*16+52, 16, 16, hdcMem1, 0,0, SRCCOPY) ; } void clickRespond(Mine*mineMat,int x,int y,HDC hdc,HWND hwnd) { int i; //点击区域落在笑脸区域;column*8-3,10 if((x>column*8-3)&&(x<column*8+20)&&(y>10)&&(y<33)) { hdc=GetDC(hwnd); KillTimer(hwnd,ID_TIMER1); Tswitch=0; time=0; BitBlt (hdc,column*16-33 ,12, 13, 23, hdcMem3, 0,23, SRCCOPY) ; BitBlt (hdc,column*16-20 ,12, 13, 23, hdcMem3, 0,23, SRCCOPY) ; BitBlt (hdc,column*16-7 ,12, 13, 23, hdcMem3, 0,23, SRCCOPY) ; BitBlt (hdc, column*8-3,10 , 24, 24, hdcMem5, 0,96, SRCCOPY) ; initMineMatrix(mineMat,row, column); display(mineMat, row, column, hdc); landMineFunc(mineMat, row, column, NumMine);//布雷函数 SetMinesAround(mineMat,row,column); DeleteDC(hdc); } //点击区域落在雷区内。 if((x>=9)&&(x<9+16*column)&&(y>=52)&&(y<52+16*row)) { //Beep(1000,1000); if(Tswitch!=2) Tswitch=1; // SetTimer (hwnd, ID_TIMER1, 1000, TimerProc); int loc=((y-52)/16)*column+(x-9)/16; int value=mineMat[loc].getvalue(); if(value==0) { //BitBlt (hdc,((x-9)/16)*16+9,((y-52)/16)*16+52, 16, 16, hdcMem1, 0,16*15, SRCCOPY) ; if(dis==false) { SearchZeroMine(mineMat, row,column, hdc,((y-52)/16),(x-9)/16); BitBlt (hdc, column*8-3,10 , 24, 24, hdcMem5, 0,72, SRCCOPY) ; Sleep(100); BitBlt (hdc, column*8-3,10 , 24, 24, hdcMem5, 0,96, SRCCOPY) ; } } else if(value==-1) { dis=true; Tswitch=2; if(sound==true) PlaySound (TEXT ("434.wav"), NULL, SND_FILENAME | SND_ASYNC) ; for(i=0;i<row*column;i++) if(mineMat[i].getvalue()==-1) { BitBlt (hdc, (i%column)*16+9,( i/column)*16+52, 16, 16, hdcMem1, 0,48, SRCCOPY) ; mineMat[i].setDisOrNot(true); } BitBlt (hdc, column*8-3,10 , 24, 24, hdcMem5, 0,48, SRCCOPY) ; } else { SelectObject (hdcMem1, hBitmap1) ; if(dis==false) { if(x>8&&y>51) BitBlt (hdc,((x-9)/16)*16+9,((y-52)/16)*16+52, 16, 16, hdcMem1, 0,16*15-value*16, SRCCOPY) ; mineMat[(y-52)/16*column+(x-9)/16].setDisOrNot(true); BitBlt (hdc, column*8-3,10 , 24, 24, hdcMem5, 0,72, SRCCOPY) ; Sleep(100); BitBlt (hdc, column*8-3,10 , 24, 24, hdcMem5, 0,96, SRCCOPY) ; } } pickMineNum=0; for(i=0;i<row*column;i++) if((mineMat[i].getdisval()==true)&&(mineMat[i].getvalue()!=-1)) { pickMineNum++; } if(pickMineNum==column*row-NumMine) { if(sound==true) PlaySound (TEXT ("433.wav"), NULL, SND_FILENAME | SND_ASYNC) ; Tswitch=0; for(i=0;i<row*column;i++) if(mineMat[i].getvalue()==-1) { BitBlt (hdc, (i%column)*16+9,( i/column)*16+52, 16, 16, hdcMem1, 0,16, SRCCOPY) ; mineMat[i].setDisOrNot(true); } } } } //===============显示时钟函数==========================。 VOID TimerProc(HWND hwnd) { //RECT rect={column*16-30,12,column*16+9,35}; //wchar_t szbuf[7]={0}; //wsprintf(szbuf,TEXT("%03d"),time); HDC hdc; if( Tswitch==2 || Tswitch ==3) { //KillTimer(hwnd,ID_TIMER1); time=0; } if(Tswitch==1) { time+=1; hdc=GetDC(hwnd); //SetTextColor(hdc,RGB(255,0,0)); //SetBkColor(hdc,RGB(12,12,12)); //wsprintf(szbuf,TEXT("%03d"),time); //DrawText(hdc,szbuf,3,&rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER); if(time<1000){ BitBlt (hdc, column*16-33 ,12, 13, 23, hdcMem3, 0,253-23*(time/100%10), SRCCOPY) ; BitBlt (hdc,column*16-20 ,12, 13, 23, hdcMem3, 0,253-23*(time/10%10), SRCCOPY) ; BitBlt (hdc, column*16-7 ,12, 13, 23, hdcMem3, 0,253-23*(time%10), SRCCOPY) ; if(sound==true) PlaySound (TEXT ("432.wav"), NULL, SND_FILENAME | SND_ASYNC) ; } ReleaseDC(hwnd,hdc); } g_tPre = GetTickCount(); } //=====布雷函数======= void landMineFunc(Mine*mineMat,int row,int column,int mineNum) { int i=0; int ii,jj,cursor; int val; srand(GetTickCount()); for(i=0;i<mineNum;i++) { do{ ii=rand()%row; jj=rand()%column; cursor=ii*column+jj; val=mineMat[cursor].getvalue(); }while(val==-1); mineMat[cursor].setValue(-1); } } void SetMinesAround(Mine*mat,int row,int column) { int val; int tmp; int sum; int i,j; for(i=0;i<row;i++) for(j=0;j<column;j++) { sum=0; val=mat[i*column+j].getvalue(); if(val!=-1)//当这个位置不是地雷时候,将四周有的地雷数目填入其中。 { if((i-1>=0)&&(j-1>=0)) { tmp=mat[(i-1)*column+j-1].getvalue(); if(tmp==-1) sum++; } if((j-1>=0)) { tmp=mat[(i)*column+j-1].getvalue(); if(tmp==-1) sum++; } if((i+1<row)&&(j-1>=0)) { tmp=mat[(i+1)*column+j-1].getvalue(); if(tmp==-1) sum++; } if((i-1>=0)) { tmp=mat[(i-1)*column+j].getvalue(); if(tmp==-1) sum++; } if((i+1<row)) { tmp=mat[(i+1)*column+j].getvalue(); if(tmp==-1) sum++; } if((i-1>=0)&&(j+1<column)) { tmp=mat[(i-1)*column+j+1].getvalue(); if(tmp==-1) sum++; } if((j+1<column)) { tmp=mat[(i)*column+j+1].getvalue(); if(tmp==-1) sum++; } if((i+1<row)&&(j+1<column)) { tmp=mat[(i+1)*column+j+1].getvalue(); if(tmp==-1) sum++; } mat[i*column+j].setValue(sum); } //if(i) } } void SearchZeroMine(Mine*mat,int row,int column,HDC hdc,int i,int j) { int ValTmp; bool ZeroTmp; if(i>=0) { if((i>=0)&&(j>=0)) BitBlt (hdc,j*16+9,i*16+52, 16, 16, hdcMem1, 0,16*15, SRCCOPY) ; mat[i*column+j].setDisOrNot(true); } mat[i*column+j].setZerocursor(true); if((i-1>=0)&&(j-1>=0)) { ValTmp=mat[(i-1)*column+j-1].getvalue(); ZeroTmp=mat[(i-1)*column+j-1].getZerocursor(); if((ValTmp==0)&&(ZeroTmp==false)) { SearchZeroMine(mat, row, column,hdc,i-1,j-1); } if((0<ValTmp)&&(ValTmp<9)) { if((i>=0)&&(j>=0)) BitBlt (hdc,(j-1)*16+9,(i-1)*16+52, 16, 16, hdcMem1, 0,16*15-ValTmp*16, SRCCOPY) ; mat[(i-1)*column+j-1].setDisOrNot(true); } } if((j-1>=0)) { ValTmp=mat[(i)*column+j-1].getvalue(); ZeroTmp=mat[(i)*column+j-1].getZerocursor(); if((ValTmp==0)&&(ZeroTmp==false)) { SearchZeroMine(mat, row, column,hdc,i,j-1); } if((0<ValTmp)&&(ValTmp<9)) { if((i>=0)&&(j>=0)) BitBlt (hdc,(j-1)*16+9,(i)*16+52, 16, 16, hdcMem1, 0,16*15-ValTmp*16, SRCCOPY) ; mat[(i)*column+j-1].setDisOrNot(true); } } if((i+1<column)&&(j-1>=0)) { ValTmp=mat[(i+1)*column+j-1].getvalue(); ZeroTmp=mat[(i+1)*column+j-1].getZerocursor(); if((ValTmp==0)&&(ZeroTmp==false)) { SearchZeroMine(mat, row, column,hdc,i+1,j-1); } if((0<ValTmp)&&(ValTmp<9)) { if((i>=0)&&(j>=0)) BitBlt (hdc,(j-1)*16+9,(i+1)*16+52, 16, 16, hdcMem1, 0,16*15-ValTmp*16, SRCCOPY) ; mat[(i+1)*column+j-1].setDisOrNot(true); } } if((i-1>=0)) { ValTmp=mat[(i-1)*column+j].getvalue(); ZeroTmp=mat[(i-1)*column+j].getZerocursor(); if((ValTmp==0)&&(ZeroTmp==false)) { SearchZeroMine(mat, row, column,hdc,i-1,j); } if((0<ValTmp)&&(ValTmp<9)) { mat[(i-1)*column+j].setDisOrNot(true); if((i>=0)&&(j>=0)) BitBlt (hdc,(j)*16+9,(i-1)*16+52, 16, 16, hdcMem1, 0,16*15-ValTmp*16, SRCCOPY) ; } } if((i+1<row)) { ValTmp=mat[(i+1)*column+j].getvalue(); ZeroTmp=mat[(i+1)*column+j].getZerocursor(); if((ValTmp==0)&&(ZeroTmp==false)) { SearchZeroMine(mat, row, column,hdc,i+1,j); } if((0<ValTmp)&&(ValTmp<9)) { if((i>=0)&&(j>=0)) BitBlt (hdc,(j)*16+9,(i+1)*16+52, 16, 16, hdcMem1, 0,16*15-ValTmp*16, SRCCOPY) ; mat[(i+1)*column+j].setDisOrNot(true); } } if((i-1>=0)&&(j+1<column)) { ValTmp=mat[(i-1)*column+j+1].getvalue(); ZeroTmp=mat[(i-1)*column+j+1].getZerocursor(); if((ValTmp==0)&&(ZeroTmp==false)) { SearchZeroMine(mat, row, column,hdc,i-1,j+1); } if((0<ValTmp)&&(ValTmp<9)) { if((i>=0)&&(j>=0)) BitBlt (hdc,(j+1)*16+9,(i-1)*16+52, 16, 16, hdcMem1, 0,16*15-ValTmp*16, SRCCOPY) ; mat[(i-1)*column+j+1].setDisOrNot(true); } } if((j+1<column)) { ValTmp=mat[(i)*column+j+1].getvalue(); ZeroTmp=mat[(i)*column+j+1].getZerocursor(); if((ValTmp==0)&&(ZeroTmp==false)) { SearchZeroMine(mat, row, column,hdc,i-1,j+1); } if((0<ValTmp)&&(ValTmp<9)) { if((i>=0)&&(j>=0)) BitBlt (hdc,(j+1)*16+9,(i)*16+52, 16, 16, hdcMem1, 0,16*15-ValTmp*16, SRCCOPY) ; mat[(i)*column+j+1].setDisOrNot(true); } } if((i+1<row)&&(j+1<column)) { ValTmp=mat[(i+1)*column+j+1].getvalue(); ZeroTmp=mat[(i+1)*column+j+1].getZerocursor(); if((ValTmp==0)&&(ZeroTmp==false)) { SearchZeroMine(mat, row, column,hdc,i-1,j+1); } if((0<ValTmp)&&(ValTmp<9)) { if((i>=0)&&(j>=0)) BitBlt (hdc,(j+1)*16+9,(i+1)*16+52, 16, 16, hdcMem1, 0,16*15-ValTmp*16, SRCCOPY) ; mat[(i+1)*column+j+1].setDisOrNot(true); } } }
具体文件及见下载地址:
http://download.csdn.net/detail/zhouyelihua/7604765
http://download.csdn.net/detail/zhouyelihua/7604765