📄 mainfrm.cpp
字号:
DeleteDC(hdcMem);
GetObject(hBitmap2,sizeof(BITMAP),&bitmap);
hdcMem=CreateCompatibleDC(hdc);
SelectObject(hdcMem,hBitmap2);
BitBlt(hdc,0,0,bitmap.bmWidth,bitmap.bmHeight,hdcMem,0,0,SRCCOPY);
if(ButtonHwndFlag==0){
TempHwnd1=new ButtonHwnd;
TempHwnd1->hwnd=hwnd;
TempHwnd1->next=ButtonHwndHead;
ButtonHwndHead=TempHwnd1;
/* TempHwnd1=new ButtonHwnd;
TempHwnd1->hwnd=hwnd;
if(ButtonHwndHead==NULL){
ButtonHwndHead=TempHwnd1;
ButtonHwndHead->next=NULL;
}
else{
TempHwnd1->next=ButtonHwndHead;
ButtonHwndHead=TempHwnd1;
}
SetWindowLong(hwndChildTime,0,++DigFinishMineSum);
InvalidateRect(hwndChildTime,NULL,TRUE);*/
}
ButtonHwndFlag=0;
}
SetWindowLong(hwnd,0,40);
}
if(flag==40){
if(ButtonHwndHead!=NULL){
for(TempHwnd1=ButtonHwndHead;TempHwnd1!=NULL;TempHwnd1=TempHwnd1->next){
if(TempHwnd1->hwnd==hwnd){
for(int k=0;k<8;k++){
if(hwnd==hwndChildButton[k]){
GetObject(hBitmap10,sizeof(BITMAP),&bitmap);
hdcMem=CreateCompatibleDC(hdc);
SelectObject(hdcMem,hBitmap10);
BitBlt(hdc,0,0,bitmap.bmWidth,bitmap.bmHeight,hdcMem,0,0,SRCCOPY);
DeleteDC(hdcMem);
ShowMineFlag=1;
break;
}
}
if(ShowMineFlag!=1){
GetObject(hBitmap2,sizeof(BITMAP),&bitmap);
hdcMem=CreateCompatibleDC(hdc);
SelectObject(hdcMem,hBitmap2);
BitBlt(hdc,0,0,bitmap.bmWidth,bitmap.bmHeight,hdcMem,0,0,SRCCOPY);
DeleteDC(hdcMem);
ShowMineFlag=1;
break;
}
}
}
}
if(ShowMineFlag==1) { ShowMineFlag=0; return 0;}
else if(GetSelectedButtonMineFlag(GetWindowLong(hwnd,GWL_ID))==8){
/* if(LostFlag==0){
GetObject(hBitmap2,sizeof(BITMAP),&bitmap);
hdcMem=CreateCompatibleDC(hdc);
SelectObject(hdcMem,hBitmap2);
BitBlt(hdc,0,0,bitmap.bmWidth,bitmap.bmHeight,hdcMem,0,0,SRCCOPY);
}
else{*/
GetObject(hBitmap3,sizeof(BITMAP),&bitmap);
hdcMem=CreateCompatibleDC(hdc);
SelectObject(hdcMem,hBitmap3);
BitBlt(hdc,0,0,bitmap.bmWidth,bitmap.bmHeight,hdcMem,0,0,SRCCOPY);
//}
}
else{
GetObject(hBitmap7,sizeof(BITMAP),&bitmap);
hdcMem=CreateCompatibleDC(hdc);
SelectObject(hdcMem,hBitmap7);
BitBlt(hdc,0,0,bitmap.bmWidth,bitmap.bmHeight,hdcMem,0,0,SRCCOPY);
SetBkMode(hdc,TRANSPARENT);
strTemp.Format(TEXT("%d"),GetSelectedButtonMineFlag(GetWindowLong(hwnd,GWL_ID)));
if(GetSelectedButtonMineFlag(GetWindowLong(hwnd,GWL_ID))!=0)
TextOut(hdc,5,1,strTemp,1);
}
}
}
DeleteDC(hdcMem);
EndPaint(hwnd,&ps);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
int id=0,idd=0;
int i,j;
int MineNumber=0;
hwndChildClock=CreateWindow(TEXT("Clock"),NULL,
WS_CHILDWINDOW|WS_VISIBLE,
420,10,50,30,
GetSafeHwnd(),(HMENU)idd++,
(HINSTANCE)GetWindowLong(GetSafeHwnd(),GWL_HINSTANCE),
NULL);
hwndChildTime=CreateWindow(TEXT("Time"),NULL,
WS_CHILDWINDOW|WS_VISIBLE,
16,16,28,18,
GetSafeHwnd(),(HMENU)idd++,
(HINSTANCE)GetWindowLong(GetSafeHwnd(),GWL_HINSTANCE),
NULL);
hwndChildGameStart=CreateWindow(TEXT("GameStart"),NULL,
WS_CHILDWINDOW|WS_VISIBLE,
220,10,36,33,
GetSafeHwnd(),(HMENU)idd++,
(HINSTANCE)GetWindowLong(GetSafeHwnd(),GWL_HINSTANCE),
NULL);
for(i=0;i<27;i++)
for(j=0;j<16;j++){
hwndChild[i][j]=CreateWindow(TEXT("Rect"),NULL,
WS_CHILDWINDOW|WS_VISIBLE,
i*18,j*18+50,18,18,
GetSafeHwnd(),(HMENU)id++,
(HINSTANCE)GetWindowLong(GetSafeHwnd(),GWL_HINSTANCE),
NULL);
}
hBitmap0=LoadBitmap(AfxGetApp()->m_hInstance,TEXT("IDB_BITMAP0"));
hBitmap1=LoadBitmap(AfxGetApp()->m_hInstance,TEXT("IDB_BITMAP1"));
hBitmap2=LoadBitmap(AfxGetApp()->m_hInstance,TEXT("IDB_BITMAP2"));
hBitmap3=LoadBitmap(AfxGetApp()->m_hInstance,TEXT("IDB_BITMAP3"));
hBitmap4=LoadBitmap(AfxGetApp()->m_hInstance,TEXT("IDB_BITMAP4"));
hBitmap5=LoadBitmap(AfxGetApp()->m_hInstance,TEXT("IDB_BITMAP5"));
hBitmap6=LoadBitmap(AfxGetApp()->m_hInstance,TEXT("IDB_BITMAP6"));
hBitmap7=LoadBitmap(AfxGetApp()->m_hInstance,TEXT("IDB_BITMAP7"));
hBitmap8=LoadBitmap(AfxGetApp()->m_hInstance,TEXT("IDB_BITMAP8"));
hBitmap9=LoadBitmap(AfxGetApp()->m_hInstance,TEXT("IDB_BITMAP9"));
hBitmap10=LoadBitmap(AfxGetApp()->m_hInstance,TEXT("IDB_BITMAP10"));
SetMine();
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TRACE("OnCreate\n");
return 0;
}
void CMainFrame::OnPaint()
{
CPaintDC dc(this);
CBrush brush,*pOldBrush;
brush.CreateSolidBrush(RGB(0xC0,0xC0,0xC0));
pOldBrush=dc.SelectObject(&brush);
CRect rect(0,0,484,386);
dc.Rectangle(rect);
CPen pen,*pOldPen;
pen.CreatePen(PS_SOLID,5,RGB(00,00,0xff));
pOldPen=dc.SelectObject(&pen);
rect.bottom=48;
dc.Rectangle(rect);
dc.SelectObject(pOldBrush);
dc.SelectObject(pOldPen);
BITMAP bitmap;
HDC hdc,hdcMem;
hdc=::GetDC(::GetParent(hwndChildTime));
::GetObject(hBitmap9,sizeof(BITMAP),&bitmap);
hdcMem=::CreateCompatibleDC(hdc);
::SelectObject(hdcMem,hBitmap9);
::BitBlt(hdc,10,10,bitmap.bmWidth,bitmap.bmHeight,hdcMem,0,0,SRCCOPY);
::DeleteDC(hdcMem);
::InvalidateRect(hwndChildTime,NULL,TRUE);
pen.DeleteObject();
brush.DeleteObject();
}
LRESULT CALLBACK ChildWndProcClock(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
// TRACE("ChildWndProc1\n");
HDC hdc,hdcMem;
PAINTSTRUCT ps;
CString str;
CTime t;
CRect rect;
BITMAP bitmap;
HMENU hMenu;
int CurrentTimeSum=0;
int ElapseTimeSum=0;
switch(message){
case WM_CREATE:
SetTimer(hwnd,1,400,NULL);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetObject(hBitmap4,sizeof(BITMAP),&bitmap);
hdcMem=CreateCompatibleDC(hdc);
SelectObject(hdcMem,hBitmap4);
BitBlt(hdc,0,0,bitmap.bmWidth,bitmap.bmHeight,hdcMem,0,0,SRCCOPY);
DeleteDC(hdcMem);
t=t.GetCurrentTime();
CurrentTimeSum=t.GetHour()*60*60*24+t.GetMinute()*60+t.GetSecond();
ElapseTimeSum=Time.GetHour()*60*60*24+Time.GetMinute()*60+Time.GetSecond();
if(CurrentTimeSum-ElapseTimeSum<0) ElapseTimeSum+=60*60*60*24;
SetTextColor(hdc,RGB(0XFF,0XFB,0XF0,));
SetBkMode(hdc,TRANSPARENT);
if(Timeflag==0){
CurrentTimeSum=0;
ElapseTimeSum=0;
}
str.Format(TEXT("%004d"),CurrentTimeSum-ElapseTimeSum);
TextOut(hdc,8,6,str,str.GetLength());
str.Format(TEXT("%02d:%02d:%02d"),t.GetHour(),t.GetMinute(),t.GetSecond());
hMenu=GetMenu(GetParent(hwnd));
ModifyMenu(hMenu,2,MF_BYPOSITION|MF_STRING,ID_MENUITEM32773,str);
DrawMenuBar(GetParent(hwnd));
EndPaint(hwnd,&ps);
return 0;
case WM_TIMER:
InvalidateRect(hwnd,NULL,TRUE);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
LRESULT CALLBACK ChildWndProcTime(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
// TRACE("ChildWndProc1\n");
HDC hdc;
PAINTSTRUCT ps;
CString str;
CRect rect;
long Extra=0;
switch(message){
case WM_CREATE:
SetWindowLong(hwnd,0,0);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
Extra=GetWindowLong(hwnd,0);
str.Format(TEXT("%3ld"),Extra);
SetBkMode(hdc,TRANSPARENT);
SetTextColor(hdc,RGB(0XFF,0X00,0X00,));
TextOut(hdc,2,2,str,3);
EndPaint(hwnd,&ps);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
LRESULT CALLBACK ChildWndProcGameStart(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
// TRACE("ChildWndProcGameStart\n");
HDC hdc,hdcMem;
PAINTSTRUCT ps;
CString str;
CTime t;
CRect rect;
BITMAP bitmap;
ButtonHwnd* TempHwnd1,* TempHwnd2;
int i,j;
switch(message){
case WM_LBUTTONDOWN:
SetWindowLong(hwnd,0,1);
InvalidateRect(hwnd,NULL,TRUE);
return 0;
case WM_LBUTTONUP:
SetWindowLong(hwnd,0,0);
InvalidateRect(hwnd,NULL,TRUE);
Timeflag=0;
if(ButtonHwndHead!=NULL){
for(TempHwnd1=ButtonHwndHead;TempHwnd1!=NULL;){
TempHwnd2=TempHwnd1;
TempHwnd1=TempHwnd1->next;
delete TempHwnd2;
}
}
ButtonHwndHead=0;
SetMine();
for(i=0;i<27;i++)
for(j=0;j<16;j++){
SetWindowLong(hwndChild[i][j],0,0);
InvalidateRect(hwndChild[i][j],NULL,TRUE);
}
DigFinishMineSum=0;
SetWindowLong(hwndChildTime,0,0);
InvalidateRect(hwndChildTime,NULL,TRUE);
return 0;
case WM_PAINT:
if(GetWindowLong(hwnd,0)==0){
hdc=BeginPaint(hwnd,&ps);
GetObject(hBitmap5,sizeof(BITMAP),&bitmap);
hdcMem=CreateCompatibleDC(hdc);
SelectObject(hdcMem,hBitmap5);
BitBlt(hdc,0,0,bitmap.bmWidth,bitmap.bmHeight,hdcMem,0,0,SRCCOPY);
}
if(GetWindowLong(hwnd,0)==1){
hdc=BeginPaint(hwnd,&ps);
GetObject(hBitmap6,sizeof(BITMAP),&bitmap);
hdcMem=CreateCompatibleDC(hdc);
SelectObject(hdcMem,hBitmap6);
BitBlt(hdc,0,0,bitmap.bmWidth,bitmap.bmHeight,hdcMem,0,0,SRCCOPY);
}
DeleteDC(hdcMem);
EndPaint(hwnd,&ps);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
int GetSelectedButtonMineFlag(int ButtonID)
{
return RandomNumber[ButtonID/16][ButtonID%16];
}
void SetButtonMine()
{
int MineNumber=0;
int temp[8];
for(int i=0;i<8;i++) temp[i]=0;
for(i=0;i<27;i++)
for(int j=0;j<16;j++){
if(RandomNumber[i][j]==8)continue;
temp[0]=i-1<0?0:(j-1<0?0:(RandomNumber[i-1][j-1]==8?1:0));
temp[1]=j-1<0?0:(RandomNumber[i][j-1]==8?1:0);
temp[2]=i+1>26?0:(j-1<0?0:(RandomNumber[i+1][j-1]==8?1:0));
temp[3]=i+1>26?0:(RandomNumber[i+1][j]==8?1:0);
temp[4]=i+1>26?0:(j+1>15?0:(RandomNumber[i+1][j+1]==8?1:0));
temp[5]=j+1>15?0:(RandomNumber[i][j+1]==8?1:0);
temp[6]=i-1<0?0:(j+1>15?0:(RandomNumber[i-1][j+1]==8?1:0));
temp[7]=i-1<0?0:(RandomNumber[i-1][j]==8?1:0);
RandomNumber[i][j]=temp[0]+temp[1]+temp[2]+temp[3]+temp[4]+temp[5]+temp[6]+temp[7];
}
}
void LButtonSelect2(HWND hwnd)
{
long ID=GetWindowLong(hwnd,GWL_ID);
long TempID;
node* temp;
int EmptyMineFlag=0;
int MineFlag=GetSelectedButtonMineFlag(ID);
if(ID/16-1>=0&&ID%16-1>=0){
TempID=GetWindowLong(hwndChild[ID/16-1][ID%16-1],GWL_ID);
if(EmptyMineHead!=NULL){
for(temp=EmptyMineHead;temp!=NULL;temp=temp->next)
{
if(temp->ID==TempID){
EmptyMineFlag=1;
break;
}
}
}
if(EmptyMineFlag==0)
{
if(GetSelectedButtonMineFlag(TempID)==0){
temp=new node;
temp->ID=TempID;
temp->next=EmptyMineHead;
EmptyMineHead=temp;
LButtonSelect2(hwndChild[ID/16-1][ID%16-1]);
}
SetWindowLong(hwndChild[ID/16-1][ID%16-1],0,7);
InvalidateRect(hwndChild[ID/16-1][ID%16-1],NULL,TRUE);
}
}
EmptyMineFlag=0;
if(ID%16-1>=0){
TempID=GetWindowLong(hwndChild[ID/16][ID%16-1],GWL_ID);
if(EmptyMineHead!=NULL){
for(temp=EmptyMineHead;temp!=NULL;temp=temp->next)
{
if(temp->ID==TempID){
EmptyMineFlag=1;
break;
}
}
}
if(EmptyMineFlag==0)
{
if(GetSelectedButtonMineFlag(TempID)==0){
temp=new node;
temp->ID=TempID;
temp->next=EmptyMineHead;
EmptyMineHead=temp;
LButtonSelect2(hwndChild[ID/16][ID%16-1]);
}
SetWindowLong(hwndChild[ID/16][ID%16-1],0,7);
InvalidateRect(hwndChild[ID/16][ID%16-1],NULL,TRUE);
}
}
EmptyMineFlag=0;
if(ID/16+1<=26&&ID%16-1>=0){
TempID=GetWindowLong(hwndChild[ID/16+1][ID%16-1],GWL_ID);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -