GridPicture.cpp
上传用户:z3308516
上传日期:2013-01-23
资源大小:703k
文件大小:32k
源码类别:

2D图形编程

开发平台:

Visual C++

  1. #include "StdAfx.h"
  2. #include "gridpicture.h"
  3. #include "resource.h"
  4. #include "TimeElapse.h"
  5. #include "Registry.h"
  6. extern CTimeElapse timeElapse;
  7. extern CRegistry reg;
  8. #define ShowMessage(X) MessageBox(NULL,X,"发生错误",MB_OK|MB_TOPMOST|MB_ICONWARNING); 
  9. PostQuitMessage(0);
  10. int PICTURE_WIDTH=34;
  11. #define PICTURE_SPACE 0
  12. CGridPicture::CGridPicture(){
  13. leftEdge=0;
  14. rightEdge=0;
  15. topEdge=0;
  16. bottomEdge=0;
  17. bSound=TRUE;
  18. ifen=0;
  19. ilevel=0;
  20. lv=0;
  21. }
  22. void CGridPicture::SetFenLevel(int ifen,int ilevel,int lv){
  23. this->ifen =ifen;
  24. this->ilevel =ilevel;
  25. this->lv=lv;
  26. }
  27. void CGridPicture::GetLevelAndFen(int &ifen,int &lv){
  28. ifen=this->ifen;
  29. lv=this->lv;
  30. }
  31. void CGridPicture::CancelFocus(){
  32. int id;
  33. id=focusid;
  34. focusid=-1;
  35. if(id!=-1){
  36. InvalidateRect(hParent,(CONST RECT*)&arrayPic[id].rc ,TRUE);
  37. }
  38. }
  39. void CGridPicture::ReadMap(LPCTSTR pszRes){
  40. HRSRC hsrc;
  41. HGLOBAL hGlobal;
  42. size_t sz;
  43. int ifor;
  44. int max;
  45. int icount;
  46. int v;
  47. LPVOID pData;
  48. max=horzNum*vertNum;
  49. if(pszRes!=NULL){
  50. hsrc=FindResource(GetModuleHandle(NULL),(LPCTSTR)pszRes,(LPCTSTR)"RT_JPGDATA");
  51. if(hsrc){
  52. sz=SizeofResource(GetModuleHandle(NULL),hsrc);
  53. hGlobal=LoadResource(GetModuleHandle(NULL),hsrc);
  54. if(hGlobal){
  55. pData=GlobalLock(hGlobal);
  56. ///////////////////calc picture number
  57. icount=0;
  58. for(ifor=0;ifor<sz;ifor++){
  59. if(*((char*)pData+ifor)=='1')
  60. icount++;
  61. }
  62. if(icount%4!=0){
  63. for(ifor=0;ifor<max;ifor++){
  64. if(*((char*)pData+ifor)=='1'){ //fill 1
  65. *((char*)pData+ifor)='0';
  66. icount--;
  67. if(icount%4==0)
  68. break;
  69. }
  70. }
  71. }
  72. picNum=icount/4;
  73. ////////////////////////////////////////////
  74. icount=0;
  75. for(ifor=0;ifor<max;ifor++){
  76. if(*((char*)pData+ifor)=='1'){
  77. arrayPic[ifor].resourceid =icount%picNum;
  78. icount++;
  79. }else{
  80. arrayPic[ifor].resourceid =-1;
  81. }
  82. }
  83. GlobalUnlock(hGlobal);
  84. }
  85. FreeResource(hsrc);
  86. }
  87. }else{ //randomize
  88. srand((unsigned int)time(NULL));
  89. icount=0;
  90. for(ifor=0;ifor<max;ifor++){
  91. arrayPic[ifor].resourceid =-1;
  92. }
  93. for(ifor=0;ifor<max;ifor++){
  94. v=(rand()%2);
  95. arrayPic[ifor].resourceid =v;
  96. if(v>0)
  97. icount++;
  98. if(icount>144) //图片数目极限
  99. break;
  100. }
  101. if(icount%4!=0){
  102. for(ifor=0;ifor<max;ifor++){
  103. if(arrayPic[ifor].resourceid>0){ //fill 1
  104. arrayPic[ifor].resourceid=0;
  105. icount--;
  106. if(icount%4==0)
  107. break;
  108. }
  109. }
  110. }
  111. picNum=icount/4;
  112. icount=0;
  113. for(ifor=0;ifor<max;ifor++){
  114. if(arrayPic[ifor].resourceid>0){
  115. arrayPic[ifor].resourceid =icount%picNum;
  116. icount++;
  117. }else{
  118. arrayPic[ifor].resourceid =-1;
  119. }
  120. }
  121. }
  122. }
  123. void CGridPicture::CGridPictureInit(HWND hParent,int iHorz,int iVert,long lThumb,BOOL bSpecial)
  124. {
  125. FILE *fp;
  126. char szReadBuf[512];
  127. BITMAP bm;
  128. RECT rc;
  129. int ifor;
  130. int max,val;
  131. HANDLE hThread;
  132. DWORD tid;
  133. bFirstDraw=TRUE;
  134. this->bSpecial =bSpecial;
  135. ///////////////////check and destroy
  136. if(allThumb){
  137. DeleteObject(allThumb);
  138. allThumb=NULL;
  139. }
  140. if(tempDC)
  141. DeleteDC(tempDC);
  142. if(arrayPic)
  143. delete[] arrayPic;
  144. arrayPic=NULL;
  145. focusid=-1;
  146. if(!IsWindow(hParent)){
  147. ShowMessage("父窗口句柄无效");
  148. }
  149. this->hParent =hParent;
  150. this->lThumb =lThumb;
  151. horzNum=iHorz;
  152. vertNum=iVert;
  153. int cx,cy;
  154. if(fp=fopen("beautifulGame.ini","r")){
  155. while(fgets((char*)szReadBuf,sizeof(szReadBuf),fp)){
  156. if((strlen(szReadBuf)>0) && (szReadBuf[0]!='/')){
  157. if(atoi((const char*)szReadBuf)>0){
  158. sscanf((const char*)szReadBuf,"%dX%d",&cx,&cy);
  159. }else{
  160. fclose(fp);
  161. break;
  162. }
  163. }
  164. }
  165. }
  166. if(cx>10 && cy>10){
  167. if(_access((const char*)szReadBuf,0)!=-1){
  168. allThumb=(HBITMAP)LoadImage(NULL,(LPCTSTR)szReadBuf,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_DEFAULTSIZE);
  169. if(allThumb){
  170. PICTURE_WIDTH=cx;
  171. }
  172. }
  173. }
  174. if(!allThumb)
  175. allThumb=LoadBitmap((HINSTANCE)GetModuleHandle(NULL),(LPCTSTR)lThumb);
  176. if(!allThumb){
  177. ShowMessage("装入图片库失败,可能内存不够,请关闭一些程序后再试");
  178. }
  179. GetObject(allThumb,sizeof(bm),(LPVOID)&bm);
  180. if(!bSpecial){
  181. if(bm.bmWidth/PICTURE_WIDTH<(iHorz*iVert/4)){
  182. ShowMessage("图片数目太少,无法运行,请确定有36个34X34像素的图片");
  183. }
  184. }
  185. GetClientRect(hParent,&rc);
  186. startPoint.x=((rc.right -rc.left)-(PICTURE_WIDTH*iHorz))/2;
  187. if(!bSpecial){
  188. startPoint.y=((rc.bottom -rc.top)-(bm.bmHeight*iVert))/2;
  189. }else{
  190. startPoint.y=((rc.bottom - rc.top)-(bm.bmHeight*iVert))/2+50;
  191. }
  192. picture_height=bm.bmHeight;
  193. rcPicture_region.left=startPoint.x;
  194. rcPicture_region.top =startPoint.y;
  195. rcPicture_region.right =rcPicture_region.left+((PICTURE_WIDTH+PICTURE_SPACE)*iHorz);
  196. rcPicture_region.bottom =rcPicture_region.top+((picture_height+PICTURE_SPACE)*iVert);
  197. leftEdge=startPoint.x-((PICTURE_WIDTH+PICTURE_SPACE)/2);
  198. topEdge=startPoint.y-((picture_height+PICTURE_SPACE)/2);
  199. rightEdge=rcPicture_region.right+((PICTURE_WIDTH+PICTURE_SPACE)/2);
  200. bottomEdge=rcPicture_region.bottom+((picture_height+PICTURE_SPACE)/2);
  201. arrayPic=new SINGLE_BLOCK[iVert*iHorz];
  202. memset((void*)arrayPic,0,sizeof(SINGLE_BLOCK)*iVert*iHorz);
  203. //init
  204. max=vertNum*horzNum;
  205. if(!bSpecial){
  206. val=max/4;
  207. picNum=val;
  208. for(ifor=0;ifor<max;ifor++){
  209. arrayPic[ifor].resourceid=ifor%val;
  210. }
  211. }else{
  212. switch(ilevel){
  213. case 4:
  214. ReadMap((LPCTSTR)IDR_MAP1);
  215. break;
  216. case 0:
  217. ReadMap((LPCTSTR)IDR_MAP2);
  218. break;
  219. case 3:
  220. ReadMap((LPCTSTR)IDR_MAP3);
  221. break;
  222. case 2:
  223. ReadMap((LPCTSTR)IDR_MAP4);
  224. break;
  225. case 1:
  226. ReadMap((LPCTSTR)IDR_MAP5);
  227. break;
  228. case 5:
  229. ReadMap((LPCTSTR)IDR_MAP6);
  230. break;
  231. case 6:
  232. ReadMap((LPCTSTR)IDR_MAP7);
  233. break;
  234. case 7:
  235. ReadMap((LPCTSTR)IDR_MAP8);
  236. break;
  237. case 8:
  238. ReadMap((LPCTSTR)IDR_MAP9);
  239. break;
  240. case 9:
  241. ReadMap((LPCTSTR)IDR_MAP10);
  242. break;
  243. case 10:
  244. ReadMap((LPCTSTR)IDR_MAP11);
  245. break;
  246. default:
  247. ReadMap((LPCTSTR)NULL);
  248. break;
  249. }
  250. }
  251. Shuffle();
  252. tempDC=NULL;
  253. bTerminate=FALSE;
  254. hThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadWatch,(LPVOID)this,0,&tid);
  255. if(hThread)
  256. CloseHandle(hThread);
  257. }
  258. CGridPicture::~CGridPicture(void)
  259. {
  260. if(allThumb)
  261. DeleteObject(allThumb);
  262. if(tempDC)
  263. DeleteDC(tempDC);
  264. if(arrayPic)
  265. delete[] arrayPic;
  266. arrayPic=NULL;
  267. }
  268. #define DRAW_EDGE(color,w,x,y,tox,toy) 
  269. hpen=CreatePen(PS_SOLID,w,color); 
  270. oldpen=(HPEN)SelectObject(hDC,hpen); 
  271. MoveToEx(hDC,x,y,NULL); 
  272. LineTo(hDC,tox,toy); 
  273. SelectObject(hDC,oldpen); 
  274. DeleteObject(hpen);
  275. void CGridPicture::Draw(HDC hDC,PSINGLE_BLOCK arrayPic){
  276. int ifor;
  277. int vPos;
  278. int hPos;
  279. HBRUSH hbr;
  280. HPEN hpen,oldpen;
  281. RECT rcfill;
  282. if(!tempDC){
  283. tempDC=CreateCompatibleDC(hDC);
  284. SelectObject(tempDC,allThumb);
  285. }
  286. hPos=startPoint.x;
  287. vPos=startPoint.y;
  288. for(ifor=0;ifor<horzNum*vertNum;ifor++){
  289. if(ifor!=0 && ifor%horzNum==0){
  290. vPos+=picture_height+PICTURE_SPACE;
  291. hPos=startPoint.x;
  292. }
  293. if(arrayPic[ifor].resourceid ==-1){ //已经打掉了
  294. if(bFirstDraw)
  295. SetRect(&arrayPic[ifor].rc,hPos-PICTURE_SPACE-3,vPos-PICTURE_SPACE-3,PICTURE_WIDTH+hPos+PICTURE_SPACE+5,picture_height+vPos+PICTURE_SPACE+5);
  296. hPos+=PICTURE_WIDTH+PICTURE_SPACE;
  297. continue;
  298. }
  299. if(focusid==ifor){
  300. SetRect(&rcfill,hPos,vPos,PICTURE_WIDTH+hPos,picture_height+vPos);
  301. hbr=CreateSolidBrush(RGB(200,200,200));
  302. FillRect(hDC,&rcfill,hbr);
  303. DeleteObject(hbr);
  304. }else{
  305. SetRect(&rcfill,hPos,vPos,PICTURE_WIDTH+hPos,picture_height+vPos);
  306. hbr=CreateSolidBrush(RGB(249,254,214));
  307. FillRect(hDC,&rcfill,hbr);
  308. DeleteObject(hbr);
  309. }
  310. DRAW_EDGE(RGB(209,182,161),2,hPos,vPos,hPos,vPos+picture_height);
  311. DRAW_EDGE(RGB(209,182,161),2,hPos,vPos+picture_height,hPos+PICTURE_WIDTH,vPos+picture_height);
  312. DRAW_EDGE(RGB(255,255,255),1,hPos+PICTURE_WIDTH-2,vPos,hPos+PICTURE_WIDTH-2,vPos+picture_height);
  313. DRAW_EDGE(RGB(248,182,94),1,hPos+PICTURE_WIDTH,vPos,hPos+PICTURE_WIDTH+4,vPos+4);
  314. DRAW_EDGE(RGB(248,182,94),1,hPos+PICTURE_WIDTH,vPos+picture_height,hPos+PICTURE_WIDTH+4,vPos+picture_height+4);
  315. //fill
  316. DRAW_EDGE(RGB(242,203,66),1,hPos+PICTURE_WIDTH,vPos+1,hPos+PICTURE_WIDTH,vPos+picture_height+1);
  317. DRAW_EDGE(RGB(242,203,66),1,hPos+PICTURE_WIDTH+1,vPos+2,hPos+PICTURE_WIDTH+1,vPos+picture_height+2);
  318. DRAW_EDGE(RGB(242,203,66),1,hPos+PICTURE_WIDTH+2,vPos+3,hPos+PICTURE_WIDTH+2,vPos+picture_height+3);
  319. DRAW_EDGE(RGB(242,203,66),1,hPos+PICTURE_WIDTH+3,vPos+4,hPos+PICTURE_WIDTH+3,vPos+picture_height+4);
  320. DRAW_EDGE(RGB(242,203,66),1,hPos+PICTURE_WIDTH+4,vPos+5,hPos+PICTURE_WIDTH+4,vPos+picture_height+5);
  321. //////////////
  322. DRAW_EDGE(RGB(248,182,94),1,hPos,vPos+picture_height,hPos+4,vPos+picture_height+4);
  323. //fill
  324. DRAW_EDGE(RGB(238,162,64),1,hPos+1,vPos+picture_height,hPos+PICTURE_WIDTH+1,vPos+picture_height);
  325. DRAW_EDGE(RGB(238,162,64),1,hPos+2,vPos+picture_height+1,hPos+PICTURE_WIDTH+2,vPos+picture_height+1);
  326. DRAW_EDGE(RGB(238,162,64),1,hPos+3,vPos+picture_height+2,hPos+PICTURE_WIDTH+3,vPos+picture_height+2);
  327. DRAW_EDGE(RGB(238,162,64),1,hPos+4,vPos+picture_height+3,hPos+PICTURE_WIDTH+4,vPos+picture_height+3);
  328. DRAW_EDGE(RGB(238,162,64),1,hPos+5,vPos+picture_height+4,hPos+PICTURE_WIDTH+5,vPos+picture_height+4);
  329. ///////////////////
  330. BitBlt(hDC,hPos,vPos,PICTURE_WIDTH,picture_height,tempDC,arrayPic[ifor].resourceid*PICTURE_WIDTH,0,SRCAND);
  331. if(bFirstDraw)
  332. SetRect(&arrayPic[ifor].rc,hPos-PICTURE_SPACE-3,vPos-PICTURE_SPACE-3,PICTURE_WIDTH+hPos+PICTURE_SPACE+5,picture_height+vPos+PICTURE_SPACE+5);
  333. hPos+=PICTURE_WIDTH+PICTURE_SPACE;
  334. }
  335. RECT rc;
  336. HFONT hfont,oldfont;
  337. char szfen[20];
  338. GetClientRect(hParent,&rc);
  339. hfont=CreateFont(55,0,0,0,0,0,0,0,0,0,0,0,0,FONTNAME);
  340. oldfont=(HFONT)SelectObject(hDC,hfont);
  341. SetTextColor(hDC,RGB(0,255,0));
  342. wsprintf((LPTSTR)szfen,"   %d   ",ifen);
  343. TextOut(hDC,rc.right -200,rc.top,(LPCTSTR)szfen,strlen(szfen));
  344. GetClientRect(hParent,(LPRECT)&rc);
  345. wsprintf((LPTSTR)szfen,"Level %d ",ilevel+1);
  346. SetTextColor(hDC,RGB(80,80,80));
  347. TextOut(hDC,0,0,(LPCTSTR)szfen,strlen(szfen));
  348. SelectObject(hDC,oldfont);
  349. DeleteObject(hfont);
  350. bFirstDraw=FALSE;
  351. }
  352. void CGridPicture::Shuffle(){
  353. int ifor;
  354. // int val;
  355. int max;
  356. int temp;
  357. int num1,num2,num3,num4;
  358. max=vertNum*horzNum;
  359. srand((unsigned int)time(NULL));
  360. // val=max/4;
  361. //打乱
  362. for(ifor=0;ifor<(max*4);ifor++){
  363. num1=((rand())%max);
  364. num2=((rand())%max);
  365. if(arrayPic[num1].resourceid !=-1 && arrayPic[num2].resourceid !=-1){
  366. if(num1!=num2){
  367. num3=num1;
  368. num4=num2;
  369. num1=arrayPic[num3].resourceid;
  370. num2=arrayPic[num4].resourceid;
  371. temp=num1;
  372. num1=num2;
  373. num2=temp;
  374. arrayPic[num3].resourceid=num1;
  375. arrayPic[num4].resourceid=num2;
  376. }
  377. }
  378. }
  379. }
  380. void CGridPicture::OrderPicture(int id1,int id2){ //排序图片
  381. int temp;
  382. RECT rc;
  383. HDC hDC;
  384. HFONT hfont,oldfont;
  385. char szfen[20];
  386. #define EXCHANGE_NUM(x1,x2) temp=arrayPic[x1].resourceid; 
  387. arrayPic[x1].resourceid=arrayPic[x2].resourceid; 
  388. arrayPic[x2].resourceid=temp; 
  389. InvalidateRect(hParent,&arrayPic[x1].rc,TRUE); 
  390. InvalidateRect(hParent,&arrayPic[x2].rc,TRUE);
  391. if(id2<id1){
  392. temp=id1;
  393. id1=id2;
  394. id2=temp;
  395. }
  396. InvalidateRect(hParent,&arrayPic[id1].rc,TRUE);
  397. InvalidateRect(hParent,&arrayPic[id2].rc,TRUE);
  398. if(!bSpecial)
  399. switch(ilevel){
  400. case 0: //不变
  401. break;
  402. case 1: //向下
  403. id1-=horzNum;
  404. while(id1>-1){
  405. EXCHANGE_NUM(id1,id1+horzNum);
  406. id1-=horzNum;
  407. }
  408. id2-=horzNum;
  409. while(id2>-1){
  410. EXCHANGE_NUM(id2,id2+horzNum);
  411. id2-=horzNum;
  412. }
  413. break;
  414. case 2: //向上
  415. if(id2>id1){
  416. temp=id1;
  417. id1=id2;
  418. id2=temp;
  419. }
  420. id1+=horzNum;
  421. while(id1<horzNum*vertNum){
  422. EXCHANGE_NUM(id1,id1-horzNum);
  423. id1+=horzNum;
  424. }
  425. id2+=horzNum;
  426. while(id2<horzNum*vertNum){
  427. EXCHANGE_NUM(id2,id2-horzNum);
  428. id2+=horzNum;
  429. }
  430. break;
  431. case 3: //向左
  432. if(id2>id1){
  433. temp=id1;
  434. id1=id2;
  435. id2=temp;
  436. }
  437. id1++;
  438. while(id1%horzNum!=0){
  439. EXCHANGE_NUM(id1,id1-1);
  440. id1++;
  441. }
  442. id2++;
  443. while(id2%horzNum!=0){
  444. EXCHANGE_NUM(id2,id2-1);
  445. id2++;
  446. }
  447. break;
  448. case 4: //向右
  449. id1--;
  450. while(id1%horzNum!=(horzNum-1) && id1>-1){
  451. EXCHANGE_NUM(id1,id1+1);
  452. id1--;
  453. }
  454. id2--;
  455. while(id2%horzNum!=(horzNum-1) && id2>-1){
  456. EXCHANGE_NUM(id2,id2+1);
  457. id2--;
  458. }
  459. break;
  460. }
  461. GetClientRect(hParent,&rc);
  462. hfont=CreateFont(55,0,0,0,0,0,0,0,0,0,0,0,0,FONTNAME);
  463. hDC=GetDC(hParent);
  464. oldfont=(HFONT)SelectObject(hDC,hfont);
  465. SetTextColor(hDC,RGB(0,255,0));
  466. wsprintf((LPTSTR)szfen,"   %d   ",ifen);
  467. TextOut(hDC,rc.right -200,rc.top,(LPCTSTR)szfen,strlen(szfen));
  468. SelectObject(hDC,oldfont);
  469. DeleteObject(hfont);
  470. ReleaseDC(hParent,hDC);
  471. UpdateWindow(hParent);
  472. }
  473. bool CGridPicture::Picture_Click(POINT &ptPos){
  474. BOOL bContinue;
  475. int ifor;
  476. int x,y;
  477. int v;
  478. int id1,id2;
  479. static int prevtime=0;
  480. static int preid=-10;
  481. int id;
  482. int tid;
  483. if(PtInRect(&rcPicture_region,ptPos)){
  484. x=ptPos.x-startPoint.x;
  485. y=ptPos.y-startPoint.y;
  486. x=x/(PICTURE_WIDTH+PICTURE_SPACE);
  487. y=y/(picture_height+PICTURE_SPACE);
  488. v=(int)y*horzNum+(int)x;
  489. pt1.x=0;
  490. pt1.y=0;
  491. pt2.x=0;
  492. pt2.y=0;
  493. if(focusid!=-1 && v!=focusid && arrayPic[v].resourceid!=-1)
  494. if(arrayPic[v].resourceid ==arrayPic[focusid].resourceid &&isCanLink(v,focusid,enumAny)){
  495. ////test explore
  496. // HANDLE hThread;
  497. // DWORD tid;
  498. DrawLinkLine(v,focusid);
  499. Play((LPCTSTR)IDR_CLEAR);
  500. /* pe=new EXPLORE_STRUCT;
  501. pe->hParent=hParent;
  502. memcpy((void*)&pe->rc,(const void*)&arrayPic[focusid].rc,sizeof(RECT));
  503. hThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadExplore,(LPVOID)pe,0,&tid);
  504. if(hThread)
  505. CloseHandle(hThread);
  506. pe=new EXPLORE_STRUCT;
  507. pe->hParent=hParent;
  508. memcpy((void*)&pe->rc,(const void*)&arrayPic[v].rc,sizeof(RECT));
  509. hThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadExplore,(LPVOID)pe,0,&tid);
  510. if(hThread)
  511. CloseHandle(hThread);
  512. */
  513. id1=focusid;
  514. id2=v;
  515. id=arrayPic[focusid].resourceid;
  516. arrayPic[focusid].resourceid =-1;
  517. arrayPic[v].resourceid =-1;
  518. focusid=-1;
  519. bContinue=FALSE;
  520. for(ifor=0;ifor<vertNum*horzNum;ifor++){ //是否还没打完
  521. if(arrayPic[ifor].resourceid!=-1){
  522. bContinue=TRUE;
  523. break;
  524. }
  525. }
  526. if(timeElapse.totalSecond -prevtime<4) //二秒
  527. ifen+=18;
  528. else if(timeElapse.totalSecond-prevtime<8)
  529. ifen+=16;
  530. else if(timeElapse.totalSecond-prevtime<12)
  531. ifen+=14;
  532. else if(timeElapse.totalSecond-prevtime<16)
  533. ifen+=12;
  534. else
  535. ifen+=10;
  536. prevtime=timeElapse.totalSecond;
  537. if(!bContinue){
  538. ifen+=timeElapse.totalSecond*2;
  539. if(!bSpecial){
  540. if(ilevel<4){
  541. timeElapse.Pause();
  542. MessageBox(hParent,"请按确定以进入到下一关","信息",MB_OK);
  543. timeElapse.Pause();
  544. timeElapse.totalSecond =600;
  545. CGridPictureInit(hParent,horzNum,vertNum,lThumb,bSpecial);
  546. InvalidateRect(hParent,NULL,TRUE);
  547. ilevel++;
  548. return true;
  549. }
  550. }else{
  551. if(ilevel<100){
  552. timeElapse.Pause();
  553. // MessageBox(hParent,"请按确定以进入到下一关","信息",MB_OK);
  554. timeElapse.Pause();
  555. timeElapse.totalSecond =600;
  556. ilevel++;
  557. CGridPictureInit(hParent,22,11,lThumb,bSpecial);
  558. InvalidateRect(hParent,NULL,TRUE);
  559. return true;
  560. }
  561. }
  562. }
  563. if(!bContinue){
  564. bTerminate=TRUE;
  565. SendMessage(hParent,STOP_TIME,0,0);
  566. MessageBox(hParent,"你已完成此皆段的所有关卡,历害","信息",MB_OK);
  567. if(lv==0){
  568. if(reg.CompareAndSetValue(hParent,enumLow,ifen)!=-1)
  569. MessageBox(hParent,"你获得了排名,高手","信息",MB_OK|MB_ICONINFORMATION);
  570. }else if(lv==1){
  571. if(reg.CompareAndSetValue(hParent,enumNormal,ifen)!=-1)
  572. MessageBox(hParent,"你获得了排名,高手","信息",MB_OK|MB_ICONINFORMATION);
  573. }else if(lv==2){
  574. if(reg.CompareAndSetValue(hParent,enumHigh,ifen)!=-1)
  575. MessageBox(hParent,"你获得了排名,高手","信息",MB_OK|MB_ICONINFORMATION);
  576. }else if(lv==3){
  577. if(reg.CompareAndSetValue(hParent,enumSpecial,ifen)!=-1)
  578. MessageBox(hParent,"你获得了排名,高手","信息",MB_OK|MB_ICONINFORMATION);
  579. }
  580. }
  581. if(id%2==0 && !bTerminate)
  582. OutputWin("ok  ");
  583. else if(!bTerminate)
  584. OutputWin("good");
  585. if(timeElapse.totalSecond+8<600) //打掉一个加两秒时间
  586. timeElapse.totalSecond +=8;
  587. if(id==preid){ //一等奖
  588. OutputWin("得了一等奖,送你1000分....:");
  589. ifen+=1000;
  590. }else if(preid==0 && id==(horzNum*vertNum-1)){ //二等奖
  591. OutputWin("得了二等奖,送你500分....:");
  592. ifen+=500;
  593. }else if(preid==(horzNum*vertNum-1)-id){ //三等奖
  594. OutputWin("得了三等奖,送你250分....:");
  595. ifen+=250;
  596. }else if(preid==horzNum && id==horzNum+1){ //时间一等奖
  597. OutputWin("得了时间一等奖,时间加满....:");
  598. timeElapse.totalSecond=600;
  599. }else if(abs(preid-id)<1){ //时间二等奖
  600. OutputWin("得了时间二等奖,时间加10秒....:");
  601. if(timeElapse.totalSecond+100<600)
  602. timeElapse.totalSecond +=50; //将二十秒种
  603. else
  604. timeElapse.totalSecond =600;
  605. }else if(abs(preid-id)<2){ //时间三等将
  606. OutputWin("得了时间三等奖,时间加5秒....:");
  607. if(timeElapse.totalSecond+25<600)
  608. timeElapse.totalSecond +=25; //将十秒种
  609. else
  610. timeElapse.totalSecond =600;
  611. }
  612. preid=id;
  613. if(!bTerminate){
  614. OrderPicture(id1,id2);
  615. }
  616. return true;
  617. }
  618. if(v!=focusid){
  619. // if(arrayPic[v].resourceid!=-1 && focusid!=-1)
  620. if(arrayPic[v].resourceid!=-1&& focusid!=-1){ //把原来的焦点去掉
  621. OutputWin("嗨,点错了");
  622. tid=focusid;
  623. focusid=-1;
  624. ParsePosAndInvalidate(tid,TRUE);
  625. }
  626. if(arrayPic[v].resourceid !=-1){
  627. Play((LPCTSTR)IDR_CLICK);
  628. focusid=v; //设置新焦点
  629. ParsePosAndInvalidate(focusid);
  630. }
  631. UpdateWindow(hParent);
  632. }
  633. return true;
  634. }
  635. return false;
  636. }
  637. void CGridPicture::OutputWin(char *pszInfo){
  638. HDC hDC;
  639. RECT rc;
  640. static int prelen=-1;
  641. HFONT hfont,oldfont;
  642. hDC=GetDC(hParent);
  643. hfont=CreateFont(25,0,0,0,0,0,0,0,0,0,0,0,0,"宋体");
  644. oldfont=(HFONT)SelectObject(hDC,hfont);
  645. SetTextColor(hDC,RGB(0,0,255));
  646. if(prelen>6){
  647. rc.left =rcPicture_region.left;
  648. rc.top =rcPicture_region.top -30;
  649. rc.right=rc.left +500;
  650. rc.bottom =rc.top +30;
  651. InvalidateRect(hParent,&rc,TRUE);
  652. UpdateWindow(hParent);
  653. }
  654. prelen=strlen(pszInfo);
  655. TextOut(hDC,rcPicture_region.left,rcPicture_region.top-30,pszInfo,strlen(pszInfo));
  656. SelectObject(hDC,oldfont);
  657. DeleteObject(hfont);
  658. ReleaseDC(hParent,hDC);
  659. }
  660. #define OUTOFUP(IDQ)  IDQ<0
  661. #define OUTOFLEFT(IDQ)  (IDQ+1)%horzNum==0
  662. #define OUTOFRIGHT(IDQ) (IDQ)%horzNum==0
  663. #define OUTOFBOTTOM(IDQ) IDQ>(max-1)
  664. #define IDXPOS(idpos) arrayPic[idpos].rc.left+((PICTURE_WIDTH+PICTURE_SPACE)/2)
  665. #define IDYPOS(idpos) arrayPic[idpos].rc.top+((picture_height+PICTURE_SPACE)/2)
  666. bool CGridPicture::CanDirectToTop(int idq){
  667. int max;
  668. max=horzNum*vertNum;
  669. while(true){
  670. idq-=horzNum;
  671. if(OUTOFUP(idq))
  672. return true;
  673. if( arrayPic[idq].resourceid!=-1)
  674. break;
  675. }
  676. return false;
  677. }
  678. bool CGridPicture::CanDirectToLeft(int idq){
  679. int max;
  680. max=horzNum*vertNum;
  681. while(true){
  682. idq--;
  683. if(OUTOFLEFT(idq))
  684. return true;
  685. if( arrayPic[idq].resourceid!=-1)
  686. break;
  687. }
  688. return false;
  689. }
  690. bool CGridPicture::CanDirectToRight(int idq){
  691. int max;
  692. max=horzNum*vertNum;
  693. while(true){
  694. idq++;
  695. if(OUTOFRIGHT(idq))
  696. return true;
  697. if( arrayPic[idq].resourceid!=-1)
  698. break;
  699. }
  700. return false;
  701. }
  702. bool CGridPicture::CanDirectToBottom(int idq){
  703. int max;
  704. max=horzNum*vertNum;
  705. while(true){
  706. idq+=horzNum;
  707. if(OUTOFBOTTOM(idq))
  708. return true;
  709. if( arrayPic[idq].resourceid!=-1)
  710. break;
  711. }
  712. return false;
  713. }
  714. void CGridPicture::DrawLinkLine(int id1,int id2){
  715. HDC hDC;
  716. int temp;
  717. int ifor;
  718. HPEN oldpen,newpen;
  719. POINT ptStart,ptEnd,ptOne,ptTwo;
  720. if(!(pt1.x && pt1.y && pt2.x && pt2.y))
  721. return;
  722. memcpy((void*)&ptOne,(const void*)&pt1,sizeof(POINT));
  723. memcpy((void*)&ptTwo,(const void*)&pt2,sizeof(POINT));
  724. if(id1>id2){ //使小的数字在id1上面
  725. temp=id1;
  726. id1=id2;
  727. id2=temp;
  728. }
  729. ptStart.x=IDXPOS(id1);
  730. ptStart.y=IDYPOS(id1);
  731. ptEnd.x=IDXPOS(id2);
  732. ptEnd.y=IDYPOS(id2);
  733. hDC=GetDC(hParent);
  734. newpen=CreatePen(PS_INSIDEFRAME,3,RGB(0,255,255));
  735. oldpen=(HPEN)SelectObject(hDC,newpen);
  736. SetROP2(hDC,R2_XORPEN);
  737. for(ifor=0;ifor<2;ifor++){
  738. MoveToEx(hDC,ptStart.x,ptStart.y,NULL);
  739. LineTo(hDC,ptOne.x,ptOne.y);
  740. LineTo(hDC,ptTwo.x,ptTwo.y);
  741. LineTo(hDC,ptEnd.x,ptEnd.y);
  742. Sleep(100);
  743. }
  744. SelectObject(hDC,oldpen);
  745. DeleteObject(newpen);
  746. ReleaseDC(hParent,hDC);
  747. }
  748. bool CGridPicture::isCanLink(int id1,int id2,SEARCH_OPERATOR se,bool bfirst,int recur){
  749. int temp;
  750. int max;
  751. max=horzNum*vertNum;
  752. if(recur==0)
  753. return false;
  754. recur--;
  755. if(bfirst){
  756. if(id1>id2){ //使小的数字在id1上面
  757. temp=id1;
  758. id1=id2;
  759. id2=temp;
  760. }
  761. }
  762. //在一起并排的
  763. if(recur==2){
  764. pt1.x=IDXPOS(id1);
  765. pt1.y=IDYPOS(id1);
  766. pt2.x=IDXPOS(id2);
  767. pt2.y=IDYPOS(id2);
  768. }
  769. if(id1+1==id2){ //防止一行结束后托到另一行
  770. if(id2%horzNum!=0){
  771. return true;
  772. }
  773. }
  774. if(id1-1==id2){
  775. if(id1%horzNum!=0){
  776. return true;
  777. }
  778. }
  779. if(id1+horzNum==id2){
  780. return true;
  781. }
  782. if(id1-horzNum==id2){
  783. return true;
  784. }
  785. /*
  786. if(bfirst){ //都可以直接析出来
  787. if(CanDirectToTop(id1)){
  788. if(CanDirectToTop(id2)){
  789. pt1.x=IDXPOS(id1);
  790. pt1.y=topEdge;
  791. pt2.x=IDXPOS(id2);
  792. pt2.y=topEdge;
  793. return true;
  794. }
  795. }
  796. if(CanDirectToLeft(id1)){
  797. if(CanDirectToLeft(id2)){
  798. pt1.x=leftEdge;
  799. pt1.y=IDYPOS(id1);
  800. pt2.x=leftEdge;
  801. pt2.y=IDYPOS(id2);
  802. return true;
  803. }
  804. }
  805. if(CanDirectToRight(id1)){
  806. if(CanDirectToRight(id2)){
  807. pt1.x=rightEdge;
  808. pt1.y=IDYPOS(id1);
  809. pt2.x=rightEdge;
  810. pt2.y=IDYPOS(id2);
  811. return true;
  812. }
  813. }
  814. if(CanDirectToBottom(id1)){
  815. if(CanDirectToBottom(id2)){
  816. pt1.x=IDXPOS(id1);
  817. pt1.y=bottomEdge;
  818. pt2.x=IDXPOS(id2);
  819. pt2.y=bottomEdge;
  820. return true;
  821. }
  822. }
  823. }
  824. */
  825. //向上找
  826. if(se!=enumUP){
  827. temp=id1;
  828. while(true){
  829. temp=temp-horzNum;
  830. if(OUTOFUP(temp)){
  831. break;
  832. }else{
  833. if(recur==2){
  834. pt1.x=IDXPOS(temp);
  835. pt1.y=IDYPOS(temp);
  836. pt2.x=pt1.x;
  837. pt2.y=pt1.y;
  838. }else if(recur==1){
  839. pt2.x=IDXPOS(temp);
  840. pt2.y=IDYPOS(temp);
  841. }
  842. if(temp==id2){
  843. return true;
  844. }
  845. if(arrayPic[temp].resourceid !=-1)
  846. break;
  847. if(isCanLink(temp,id2,enumUP,false,recur))
  848. return true;
  849. }
  850. }
  851. }
  852. //向下找
  853. if(se!=enumDown){
  854. temp=id1;
  855. while(true){
  856. temp=temp+horzNum;
  857. if(OUTOFBOTTOM(temp)){
  858. break;
  859. }else{
  860. if(recur==2){
  861. pt1.x=IDXPOS(temp);
  862. pt1.y=IDYPOS(temp);
  863. pt2.x=pt1.x;
  864. pt2.y=pt1.y;
  865. }else if(recur==1){
  866. pt2.x=IDXPOS(temp);
  867. pt2.y=IDYPOS(temp);
  868. }
  869. if(temp==id2){
  870. return true;
  871. }
  872. if(arrayPic[temp].resourceid !=-1)
  873. break;
  874. if(isCanLink(temp,id2,enumDown,false,recur))
  875. return true;
  876. }
  877. }
  878. }
  879. //向左找
  880. if(se!=enumLeft){
  881. temp=id1;
  882. while(true){
  883. temp--;
  884. if(OUTOFLEFT(temp)){
  885. break;
  886. }else{
  887. if(recur==2){
  888. pt1.x=IDXPOS(temp);
  889. pt1.y=IDYPOS(temp);
  890. pt2.x=pt1.x;
  891. pt2.y=pt1.y;
  892. }else if(recur==1){
  893. pt2.x=IDXPOS(temp);
  894. pt2.y=IDYPOS(temp);
  895. }
  896. if(temp==id2){
  897. return true;
  898. }
  899. if(arrayPic[temp].resourceid !=-1)
  900. break;
  901. if(isCanLink(temp,id2,enumLeft,false,recur))
  902. return true;
  903. }
  904. }
  905. }
  906. //向右找
  907. if(se!=enumRight){
  908. temp=id1;
  909. while(true){
  910. temp++;
  911. if(OUTOFRIGHT(temp)){
  912. break;
  913. }else{
  914. if(recur==2){
  915. pt1.x=IDXPOS(temp);
  916. pt1.y=IDYPOS(temp);
  917. pt2.x=pt1.x;
  918. pt2.y=pt1.y;
  919. }else if(recur==1){
  920. pt2.x=IDXPOS(temp);
  921. pt2.y=IDYPOS(temp);
  922. }
  923. if(temp==id2){
  924. return true;
  925. }
  926. if(arrayPic[temp].resourceid !=-1)
  927. break;
  928. if(isCanLink(temp,id2,enumRight,false,recur))
  929. return true;
  930. }
  931. }
  932. }
  933. if(bfirst){ //都可以直接析出来
  934. if(CanDirectToTop(id1)){
  935. if(CanDirectToTop(id2)){
  936. pt1.x=IDXPOS(id1);
  937. pt1.y=topEdge;
  938. pt2.x=IDXPOS(id2);
  939. pt2.y=topEdge;
  940. return true;
  941. }
  942. }
  943. if(CanDirectToLeft(id1)){
  944. if(CanDirectToLeft(id2)){
  945. pt1.x=leftEdge;
  946. pt1.y=IDYPOS(id1);
  947. pt2.x=leftEdge;
  948. pt2.y=IDYPOS(id2);
  949. return true;
  950. }
  951. }
  952. if(CanDirectToRight(id1)){
  953. if(CanDirectToRight(id2)){
  954. pt1.x=rightEdge;
  955. pt1.y=IDYPOS(id1);
  956. pt2.x=rightEdge;
  957. pt2.y=IDYPOS(id2);
  958. return true;
  959. }
  960. }
  961. if(CanDirectToBottom(id1)){
  962. if(CanDirectToBottom(id2)){
  963. pt1.x=IDXPOS(id1);
  964. pt1.y=bottomEdge;
  965. pt2.x=IDXPOS(id2);
  966. pt2.y=bottomEdge;
  967. return true;
  968. }
  969. }
  970. }
  971. return false;
  972. }
  973. void CGridPicture::ParsePosAndInvalidate(int id,BOOL bClear){
  974. // InvalidateRect(hParent,&arrayPic[id].rc,TRUE);
  975. int vPos;
  976. int hPos;
  977. BOOL bHaveNext;
  978. BOOL bHavePNext;
  979. HDC hDC;
  980. HBRUSH hbr;
  981. HPEN hpen,oldpen;
  982. RECT rcfill;
  983. hPos=arrayPic[id].rc.left +3;
  984. vPos=arrayPic[id].rc.top +3;
  985. hDC=GetDC(hParent);
  986. if(!bClear){
  987. SetRect(&rcfill,hPos,vPos,PICTURE_WIDTH+hPos,picture_height+vPos);
  988. hbr=CreateSolidBrush(RGB(200,200,200));
  989. FillRect(hDC,&rcfill,hbr);
  990. DeleteObject(hbr);
  991. }else{
  992. SetRect(&rcfill,hPos,vPos,PICTURE_WIDTH+hPos,picture_height+vPos);
  993. hbr=CreateSolidBrush(RGB(249,254,214));
  994. FillRect(hDC,&rcfill,hbr);
  995. DeleteObject(hbr);
  996. }
  997. DRAW_EDGE(RGB(209,182,161),2,hPos,vPos,hPos,vPos+picture_height);
  998. DRAW_EDGE(RGB(209,182,161),2,hPos,vPos+picture_height,hPos+PICTURE_WIDTH,vPos+picture_height);
  999. DRAW_EDGE(RGB(255,255,255),1,hPos+PICTURE_WIDTH-2,vPos,hPos+PICTURE_WIDTH-2,vPos+picture_height);
  1000. bHaveNext=bHavePNext=TRUE;
  1001. if(id+1>horzNum*vertNum||(arrayPic[id+1].resourceid==-1)){
  1002. bHaveNext=FALSE;
  1003. }
  1004. if((id+horzNum)<(horzNum*vertNum) && arrayPic[id+horzNum].resourceid ==-1){
  1005. bHavePNext=FALSE;
  1006. }
  1007. if(!bHaveNext){
  1008. DRAW_EDGE(RGB(248,182,94),1,hPos+PICTURE_WIDTH,vPos,hPos+PICTURE_WIDTH+4,vPos+4);
  1009. if(!bHavePNext){
  1010. DRAW_EDGE(RGB(248,182,94),1,hPos+PICTURE_WIDTH,vPos+picture_height,hPos+PICTURE_WIDTH+4,vPos+picture_height+4);
  1011. }
  1012. //fill
  1013. if(!bHavePNext){
  1014. DRAW_EDGE(RGB(242,203,66),1,hPos+PICTURE_WIDTH,vPos+1,hPos+PICTURE_WIDTH,vPos+picture_height+1);
  1015. DRAW_EDGE(RGB(242,203,66),1,hPos+PICTURE_WIDTH+1,vPos+2,hPos+PICTURE_WIDTH+1,vPos+picture_height+2);
  1016. DRAW_EDGE(RGB(242,203,66),1,hPos+PICTURE_WIDTH+2,vPos+3,hPos+PICTURE_WIDTH+2,vPos+picture_height+3);
  1017. DRAW_EDGE(RGB(242,203,66),1,hPos+PICTURE_WIDTH+3,vPos+4,hPos+PICTURE_WIDTH+3,vPos+picture_height+4);
  1018. DRAW_EDGE(RGB(242,203,66),1,hPos+PICTURE_WIDTH+4,vPos+5,hPos+PICTURE_WIDTH+4,vPos+picture_height+5);
  1019. }else{
  1020. DRAW_EDGE(RGB(242,203,66),1,hPos+PICTURE_WIDTH,vPos+1,hPos+PICTURE_WIDTH,vPos+picture_height);
  1021. DRAW_EDGE(RGB(242,203,66),1,hPos+PICTURE_WIDTH+1,vPos+2,hPos+PICTURE_WIDTH+1,vPos+picture_height);
  1022. DRAW_EDGE(RGB(242,203,66),1,hPos+PICTURE_WIDTH+2,vPos+3,hPos+PICTURE_WIDTH+2,vPos+picture_height);
  1023. DRAW_EDGE(RGB(242,203,66),1,hPos+PICTURE_WIDTH+3,vPos+4,hPos+PICTURE_WIDTH+3,vPos+picture_height);
  1024. DRAW_EDGE(RGB(242,203,66),1,hPos+PICTURE_WIDTH+4,vPos+5,hPos+PICTURE_WIDTH+4,vPos+picture_height);
  1025. }
  1026. }
  1027. //////////////
  1028. if(!bHavePNext){
  1029. DRAW_EDGE(RGB(248,182,94),1,hPos,vPos+picture_height,hPos+4,vPos+picture_height+4);
  1030. //fill
  1031. if(!bHaveNext){
  1032. DRAW_EDGE(RGB(238,162,64),1,hPos+1,vPos+picture_height,hPos+PICTURE_WIDTH+1,vPos+picture_height);
  1033. DRAW_EDGE(RGB(238,162,64),1,hPos+2,vPos+picture_height+1,hPos+PICTURE_WIDTH+2,vPos+picture_height+1);
  1034. DRAW_EDGE(RGB(238,162,64),1,hPos+3,vPos+picture_height+2,hPos+PICTURE_WIDTH+3,vPos+picture_height+2);
  1035. DRAW_EDGE(RGB(238,162,64),1,hPos+4,vPos+picture_height+3,hPos+PICTURE_WIDTH+4,vPos+picture_height+3);
  1036. DRAW_EDGE(RGB(238,162,64),1,hPos+5,vPos+picture_height+4,hPos+PICTURE_WIDTH+5,vPos+picture_height+4);
  1037. }else{
  1038. DRAW_EDGE(RGB(238,162,64),1,hPos+1,vPos+picture_height,hPos+PICTURE_WIDTH,vPos+picture_height);
  1039. DRAW_EDGE(RGB(238,162,64),1,hPos+2,vPos+picture_height+1,hPos+PICTURE_WIDTH,vPos+picture_height+1);
  1040. DRAW_EDGE(RGB(238,162,64),1,hPos+3,vPos+picture_height+2,hPos+PICTURE_WIDTH,vPos+picture_height+2);
  1041. DRAW_EDGE(RGB(238,162,64),1,hPos+4,vPos+picture_height+3,hPos+PICTURE_WIDTH,vPos+picture_height+3);
  1042. DRAW_EDGE(RGB(238,162,64),1,hPos+5,vPos+picture_height+4,hPos+PICTURE_WIDTH,vPos+picture_height+4);
  1043. }
  1044. }
  1045. ///////////////////
  1046. BitBlt(hDC,hPos,vPos,PICTURE_WIDTH,picture_height,tempDC,arrayPic[id].resourceid*PICTURE_WIDTH,0,SRCAND);
  1047. ReleaseDC(hParent,hDC);
  1048. }
  1049. int CGridPicture::QueryResourceID(int ids,int idq){
  1050. int ifor;
  1051. for(ifor=ids;ifor<vertNum*horzNum;ifor++){
  1052. if(arrayPic){
  1053. if(arrayPic[ifor].resourceid==idq)
  1054. return ifor;
  1055. }
  1056. }
  1057. return -1;
  1058. }
  1059. void CGridPicture::FoundLink(CGridPicture *pgrid,int *idOne,int *idTwo,BOOL &bFound){
  1060. int id1,id2,id3,id4;
  1061. int ifor;
  1062. #define SETID(iid1,iid2) idOne?*idOne=iid1,*idTwo=iid2:bFound=TRUE;
  1063. for(ifor=0;ifor<picNum;ifor++){
  1064. id1=QueryResourceID(0,ifor);
  1065. id2=QueryResourceID(id1+1,ifor);
  1066. id3=QueryResourceID(id2+1,ifor);
  1067. id4=QueryResourceID(id3+1,ifor);
  1068. if(id3==-1){ //还有一对
  1069. if(id1==-1){ //一对都没有
  1070. continue;
  1071. }else{ //一对
  1072. if(pgrid->isCanLink(id1,id2,enumAny)){
  1073. bFound=TRUE;
  1074. SETID(id1,id2);
  1075. break;
  1076. }
  1077. }
  1078. }else{//两对
  1079. if(pgrid->isCanLink(id1,id2,enumAny)){
  1080. bFound=TRUE;
  1081. SETID(id1,id2);
  1082. break;
  1083. }
  1084. if(pgrid->isCanLink(id1,id3,enumAny)){
  1085. bFound=TRUE;
  1086. SETID(id1,id3);
  1087. break;
  1088. }
  1089. if(pgrid->isCanLink(id1,id4,enumAny)){
  1090. bFound=TRUE;
  1091. SETID(id1,id4);
  1092. break;
  1093. }
  1094. if(pgrid->isCanLink(id2,id3,enumAny)){
  1095. bFound=TRUE;
  1096. SETID(id2,id3);
  1097. break;
  1098. }
  1099. if(pgrid->isCanLink(id2,id4,enumAny)){
  1100. bFound=TRUE;
  1101. SETID(id2,id4);
  1102. break;
  1103. }
  1104. if(pgrid->isCanLink(id3,id4,enumAny)){
  1105. bFound=TRUE;
  1106. SETID(id3,id4);
  1107. break;
  1108. }
  1109. }
  1110. }
  1111. }
  1112. LRESULT CALLBACK CGridPicture::ThreadWatch(LPARAM lParam){
  1113. CGridPicture *pgrid;
  1114. BOOL bFound;
  1115. pgrid=(CGridPicture*)lParam;
  1116. while(true){
  1117. bFound=FALSE;
  1118. FoundLink(pgrid,NULL,NULL,bFound);
  1119. if(bTerminate)
  1120. break;
  1121. if(bFound==FALSE && timeElapse.bPause ==FALSE){
  1122. pgrid->Shuffle();
  1123. InvalidateRect(hParent,NULL,TRUE);
  1124. }
  1125. Sleep(2000);
  1126. }
  1127. return 0;
  1128. }
  1129. LRESULT CALLBACK CGridPicture::ThreadExplore(LPARAM lParam){
  1130. HDC hTempDC;
  1131. HDC hDesktop;
  1132. HBITMAP hExplore;
  1133. BITMAP bm;
  1134. PEXPLORE_STRUCT pe;
  1135. RECT rcInvalid;
  1136. int ifor;
  1137. int pic_height,pic_width;
  1138. pe=(PEXPLORE_STRUCT)lParam;
  1139. hExplore=LoadBitmap((HINSTANCE)GetModuleHandle(NULL),(LPCTSTR)IDB_EXPLORE);
  1140. if(hExplore){
  1141. GetObject(hExplore,sizeof(bm),(LPVOID)&bm);
  1142. pic_width=bm.bmWidth;
  1143. pic_height=bm.bmHeight;
  1144. pic_width/=5;
  1145. hDesktop=GetDC(pe->hParent);
  1146. hTempDC=CreateCompatibleDC(hDesktop);
  1147. SelectObject(hTempDC,hExplore);
  1148. for(ifor=0;ifor<5;ifor++){
  1149. BitBlt(hDesktop,pe->rc.left ,pe->rc.top,pe->rc.right-pe->rc.left,pe->rc.bottom-pe->rc.top,hTempDC,pic_width*ifor,0,SRCCOPY);
  1150. Sleep(100);
  1151. }
  1152. ReleaseDC(pe->hParent,hDesktop);
  1153. memcpy((void*)&rcInvalid,(const void*)&pe->rc,sizeof(RECT));
  1154. rcInvalid.left -=2;
  1155. rcInvalid.top -=2;
  1156. rcInvalid.bottom +=2;
  1157. rcInvalid.right +=2;
  1158. InvalidateRect(pe->hParent,&rcInvalid,TRUE);
  1159. }
  1160. delete pe;
  1161. return 0;
  1162. }
  1163. void CGridPicture::Explore(int id1,int id2){
  1164. POINT ptPos;
  1165. SetSelect(id1);
  1166. ptPos.x=(arrayPic[id2].rc.right-arrayPic[id2].rc.left)/2+arrayPic[id2].rc.left;
  1167. ptPos.y=(arrayPic[id2].rc.bottom -arrayPic[id2].rc.top)/2+arrayPic[id2].rc.top;
  1168. Picture_Click(ptPos);
  1169. }
  1170. void CGridPicture::SetSelect(int id){
  1171. int invalidid;
  1172. if(focusid!=-1){
  1173. invalidid=focusid;
  1174. focusid=-1;
  1175. InvalidateRect(hParent,(CONST RECT*)&arrayPic[invalidid].rc,TRUE);
  1176. }
  1177. focusid=id;
  1178. InvalidateRect(hParent,(const RECT*)&arrayPic[id].rc,TRUE);
  1179. }
  1180. void CGridPicture::Discard(){
  1181. bTerminate=TRUE;
  1182. }
  1183. void CGridPicture::Play(LPCTSTR pszRes){
  1184. HRSRC hsrc;
  1185. HGLOBAL hGlobal;
  1186. LPVOID pData;
  1187. if(bSound){
  1188. hsrc=FindResource(GetModuleHandle(NULL),(LPCTSTR)pszRes,(LPCTSTR)"RT_JPGDATA");
  1189. if(hsrc){
  1190. hGlobal=LoadResource(GetModuleHandle(NULL),hsrc);
  1191. if(hGlobal){
  1192. pData=GlobalLock(hGlobal);
  1193. PlaySound((LPCTSTR)pData,GetModuleHandle(NULL),SND_ASYNC|SND_NOWAIT|SND_MEMORY);
  1194. GlobalUnlock(hGlobal);
  1195. // GlobalFree(hGlobal);
  1196. }
  1197. FreeResource(hsrc);
  1198. }
  1199. }
  1200. }
  1201. int CGridPicture::vertNum =0;
  1202. int CGridPicture::horzNum =0;
  1203. int CGridPicture::picNum =0;
  1204. HWND CGridPicture::hParent =NULL;
  1205. PSINGLE_BLOCK CGridPicture::arrayPic =NULL;
  1206. BOOL CGridPicture::bTerminate =FALSE;