📄 wndmain3.h
字号:
/****************************************************************************/
//
// ~~~~~~~~~~~~~~~~ Window Main's Functions III ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// WndMain3.h
//
//***************************************************************************/
////////////////////////////////////////////////////////////////////////////
// Draw Time Play
void DrawTimePlay(bool fIncrease)
{
HDC hDC;
TCHAR szBuffer[10];
hDC = GetDC(WndMain.hWnd);
SetBkMode(hDC, TRANSPARENT);
if( ec.iTab == ID_PLAY && !play.fWin && !ec.fChooseFile )
{
SetTextColor(hDC, CR_WNDMAIN );
wsprintf(szBuffer,"%02d : %02d",(play.iTimePlay/ CTIME / 60), (play.iTimePlay/ CTIME %60) );
TextOut(hDC, 5 , YHEADER - 15, szBuffer, strlen(szBuffer) );
if( fIncrease) play.iTimePlay = play.iTimePlay > 3600 * CTIME ? 0 : play.iTimePlay + 1;
SetTextColor(hDC, RGB(200,200,200));
wsprintf(szBuffer,"%02d : %02d",(play.iTimePlay/ CTIME / 60), (play.iTimePlay / CTIME %60));
TextOut(hDC, 5 , YHEADER - 15, szBuffer, strlen(szBuffer) );
}
else
{
SetTextColor(hDC, CR_WNDMAIN - RGB(20,20,20) );
wsprintf(szBuffer,"%02d : %02d",(play.iTimePlay/ CTIME / 60), (play.iTimePlay/ CTIME %60) );
TextOut(hDC, 5 , YHEADER - 15, szBuffer, strlen(szBuffer));
}
ReleaseDC(WndMain.hWnd, hDC);
}
////////////////////////////////////////////////////////////////////////////
// Draw Player Bar ( Circle )
void DrawPlayerBar()
{
int i;
POINT pCircle, pCenter;
HDC hDC;
COLORREF crColor;
pCenter.x = WndMain.xClient - 50;
pCenter.y = 30;
hDC = GetDC(WndMain.hWnd);
for ( i = play.iPBar; i < play.iPBar + 10; i++ )
{
if ( i >= play.iPBar + 9 )
crColor = CR_WNDMAIN;
else
crColor = RGB ( min( 255, max ( 0, GetRValue(skin.crPColor[play.iTurn]) + (i- play.iPBar )*10 )),
min( 255, max ( 0,GetGValue(skin.crPColor[play.iTurn])+ (i- play.iPBar )*10 )),
min( 255, max ( 0,GetBValue(skin.crPColor[play.iTurn]) + (i- play.iPBar )*10 ))
);
pCircle = RotatePoint(pCenter, 18, - i * (360/10));
MyEllipse(hDC, pCircle.x - 5, pCircle.y -5, pCircle.x + 5, pCircle.y + 5, crColor, crColor );
}
ReleaseDC(WndMain.hWnd, hDC);
}
////////////////////////////////////////////////////////////////////////////
// Draw Light Bar
void DrawLightBar(bool fIncrease)
{
int i;
static int iLight=0;
HDC hDC;
hDC = GetDC(WndMain.hWnd);
if( fIncrease ) iLight == 0 ? iLight = 8 : iLight-- ;
for(i = 0; i < 4 ; i ++ )
{
if(i == iLight)
MyRectangleEx(hDC, WndMain.xClient - 10 - i*20, WndMain.yClient -15, WndMain.xClient - 10 - (i+1)*20, WndMain.yClient - 5, PS_SOLID, 2, RGB(0,180,0), RGB(100,230,100));
else
MyRectangleEx(hDC, WndMain.xClient - 10 - i*20, WndMain.yClient -15, WndMain.xClient - 10 - (i+1)*20, WndMain.yClient - 5, PS_SOLID, 2, RGB(0,160,0), RGB(0,180,0));
}
ReleaseDC(WndMain.hWnd, hDC);
}
////////////////////////////////////////////////////////////////////////////
// Draw Time Limit
void DrawTimeLimit(bool fTimePlus)
{
HDC hDC;
TCHAR szBuffer[50];
if(setting.fTime && !play.fWin && !ec.fChooseFile )
{
hDC = GetDC(WndMain.hWnd);
SetBkMode(hDC, TRANSPARENT);
SetTextAlign(hDC, TA_CENTER | TA_CENTER );
if( ec.iTab == ID_PLAY )
{
// Eraser Old Time
wsprintf(szBuffer,"%d", min( setting.iTime , play.iTimeLimit/CTIME + 1 ) );
SetTextColor(hDC,CR_WNDMAIN);
TextOut(hDC, WndMain.xClient - 50, 22, szBuffer, strlen(szBuffer));
// Set new Time
if(fTimePlus)
{
if(play.iTimeLimit < 0)
{
play.iTimeLimit = setting.iTime * CTIME - 1;
play.iTurn = play.iTurn + 1 >= ( MAX_PLAYER ) ? 0 : play.iTurn + 1;
ReDrawPlayerBar();
}
else
{
play.iTimeLimit--;
}
}
// Show New time
wsprintf(szBuffer,"%d", play.iTimeLimit/CTIME + 1 );
SetTextColor(hDC,RGB(255,255,255));
TextOut(hDC, WndMain.xClient - 50, 22, szBuffer, strlen(szBuffer));
}
else
{
wsprintf(szBuffer,"%d", play.iTimeLimit/CTIME + 1 );
SetTextColor(hDC,CR_WNDMAIN - RGB(20,20,20) );
TextOut(hDC, WndMain.xClient - 50, 22, szBuffer, strlen(szBuffer));
}
ReleaseDC(WndMain.hWnd, hDC );
} // endif ( setting.fWarning... )
}
/**********************************************************************************************/
// Main Button Command
void Button_Command(WPARAM wParam)
{
RECT rect;
HMENU hMenu;
int i, iLength;
static int iOldBlock, iOldRule, iOldRulePoint, iOldRuleBlock;
TCHAR *szIEDir;
TCHAR szFileName[MAX_PATH]="";
TCHAR szFilter[] = TEXT ("Anitsoft Caro Chess Save Files (*.sav)\0*.sav\0") \
TEXT ("All Files (*.*)\0*.*\0\0") ;
hMenu = GetMenu(WndMain.hWnd );
if(ec.iTab==ID_PLAY && wParam!=ID_PLAY && (int)wParam - MAX_BUTTON <0)
{
ShowWindow(WndPlay.hWnd, SW_HIDE );
iOldBlock = setting.iBlock;
iOldRule = setting.iRule;
iOldRulePoint = rule[MAX_RULE-1].iMinPoint;
iOldRuleBlock = rule[MAX_RULE-1].iMinBlock;
}
if(ec.iTab==ID_SETTING && wParam!=ID_SETTING && (int)wParam - MAX_BUTTON <0)
{
/************************************/
// Reset Memory for cMatrix
if( iOldBlock != setting.iBlock || iOldRule != setting.iRule
|| iOldRulePoint != rule[MAX_RULE-1].iMinPoint || iOldRuleBlock != rule[MAX_RULE-1].iMinBlock)
{
pMatrix = (char*) realloc( pMatrix, setting.iBlock * setting.iBlock * sizeof(char));
if ( pMatrix == NULL )
MessageBox(NULL,"Init fail. Not enough menory","Anitsoft Caro Chess",MB_OK | MB_ICONERROR );
NewGame();
iOldBlock = setting.iBlock;
iOldRule = setting.iRule;
iOldRulePoint = rule[MAX_RULE-1].iMinPoint;
iOldRuleBlock = rule[MAX_RULE-1].iMinBlock;
}
ShowWindow( DlgSetting.hWnd, SW_HIDE);
}
if( ec.iTab == ID_CREDIT && wParam!=ID_CREDIT && (int)wParam - MAX_BUTTON <0)
{
ShowWindow(WndCredit.hWnd, SW_HIDE );
}
rect.left = 0;
rect.top = YHEADER + 10;
rect.right = XLEFT;
rect.bottom = YHEADER + 10 + MAX_BUTTON * 30;
switch(wParam)
{
// Press Playing Button
case ID_PLAY:
if(ec.iTab!=ID_PLAY)
{
CheckMenuItem(hMenu, IDM_EC_PLAYING + ec.iTab -1, MF_UNCHECKED);
MoveWindow(WndBtn[ec.iTab].hWnd , 5 ,YHEADER+ (ec.iTab - 1)*30 + 10,XLEFT-10,25, FALSE);
ec.iTab=ID_PLAY;
MoveWindow(WndBtn[ec.iTab].hWnd , 10 ,YHEADER+ (ec.iTab - 1)*30 + 10,XLEFT-10,25, FALSE);
InvalidateRect(WndMain.hWnd ,&rect,FALSE);
InvalidateRect(WndChild.hWnd ,NULL,FALSE);
/***********************************************************/
// Set Scroll Setting
SendMessage(WndChild.hWnd , WM_SIZE, 0,0);
ShowScrollBar(WndChild.hWnd ,SB_HORZ,(siH.nMax +1) <= (int)siH.nPage ? FALSE : TRUE );
ShowScrollBar(WndChild.hWnd ,SB_VERT,(siV.nMax +1) <= (int)siV.nPage ? FALSE : TRUE );
// Show Button Context
for( i=0 ; i< CBTN_PLAYING ; i++ )
{
ShowWindow(GetDlgItem(WndMain.hWnd , MAX_BUTTON+i),SW_SHOW);
InvalidateRect(GetDlgItem(WndMain.hWnd , MAX_BUTTON+i),NULL,FALSE);
}
for( i=CBTN_PLAYING ; i<MAX_CBUTTON ; i++ )
{
ShowWindow(GetDlgItem(WndMain.hWnd , MAX_BUTTON+i),SW_HIDE);
}
/****************************************/
// Show WndPlay
ShowWindow(WndPlay.hWnd, SW_SHOW);
SendMessage(WndChild.hWnd, WM_SIZE, 0, 0);
ShowStatus("Playing Mode");
CheckComFirst();
SetFocus(WndMain.hWnd);
}
break;
// Press Setting Button
case ID_SETTING:
if(ec.iTab!=ID_SETTING)
{
CheckMenuItem(hMenu, IDM_EC_PLAYING + ec.iTab -1, MF_UNCHECKED);
MoveWindow(WndBtn[ec.iTab ].hWnd , 5 ,YHEADER+ (ec.iTab - 1)*30 + 10,XLEFT-10,25, FALSE);
ec.iTab=ID_SETTING;
InvalidateRect(WndMain.hWnd ,&rect,FALSE);
MoveWindow(WndBtn[ec.iTab].hWnd , 10 ,YHEADER+ (ec.iTab - 1)*30 + 10,XLEFT-10,25, FALSE);
InvalidateRect(WndChild.hWnd ,NULL,FALSE);
ShowWindow( DlgSetting.hWnd, SW_SHOW);
SetFocus(DlgSetting.hWnd);
/***********************************************************/
// Set Scroll Setting
SendMessage(WndChild.hWnd, WM_SIZE, 0, 0 );
ShowScrollBar(WndChild.hWnd ,SB_VERT,(siV.nMax +1) <= (int)siV.nPage ? FALSE : TRUE );
ShowScrollBar(WndChild.hWnd ,SB_HORZ,FALSE); // Hide horz scroll bar
// Show Button Context
for( i=0 ; i< CBTN_SETTING ; i++ )
{
ShowWindow(GetDlgItem(WndMain.hWnd , MAX_BUTTON+i),SW_SHOW);
InvalidateRect(GetDlgItem(WndMain.hWnd , MAX_BUTTON+i),NULL,FALSE);
}
for( i=CBTN_SETTING ; i<MAX_CBUTTON ; i++ )
{
ShowWindow(GetDlgItem(WndMain.hWnd , MAX_BUTTON+i),SW_HIDE);
}
ShowStatus("Settings Mode");
}
break;
// Press Credit Button
case ID_CREDIT:
if(ec.iTab!=ID_CREDIT)
{
ec.iCreditPos = 0;
CheckMenuItem(hMenu, IDM_EC_PLAYING + ec.iTab -1, MF_UNCHECKED);
MoveWindow(WndBtn[ec.iTab ].hWnd , 5 ,YHEADER+ (ec.iTab - 1)*30 + 10,XLEFT-10,25, FALSE);
ec.iTab=ID_CREDIT;
MoveWindow(WndBtn[ec.iTab ].hWnd , 10 ,YHEADER+ (ec.iTab - 1)*30 + 10,XLEFT-10,25, FALSE);
InvalidateRect(WndMain.hWnd ,&rect,FALSE);
InvalidateRect(WndChild.hWnd ,NULL,FALSE);
ShowScrollBar(WndChild.hWnd ,SB_BOTH,FALSE); // Hide 2 scroll bar
// Show Button Context
for( i=0 ; i< CBTN_CREDIT ; i++ )
{
ShowWindow(GetDlgItem(WndMain.hWnd , MAX_BUTTON+i),SW_SHOW);
InvalidateRect(GetDlgItem(WndMain.hWnd , MAX_BUTTON+i),NULL,FALSE);
}
for( i=CBTN_CREDIT ; i<MAX_CBUTTON ; i++ )
{
ShowWindow(GetDlgItem(WndMain.hWnd , MAX_BUTTON+i),SW_HIDE);
}
MoveWindow(WndCredit.hWnd, 0, 0, 0, 0, FALSE );
ShowWindow(WndCredit.hWnd, SW_SHOW);
ShowStatus("Credit Mode");
}
break;
} // end switch(wParam)
/**********************************************************************************************/
// Button Context
i= (int)wParam - MAX_BUTTON;
if(i>=0)
{
////////////////////////////////////////////////////////////////////////
// Playing Context Button
if(ec.iTab == ID_PLAY)
{
if(i==0) // New Game
{
NewGame();
} //endif(i==0)
if(i==1) // Load Game Button Message
{
ec.fChooseFile = TRUE;
if(OpenFileDlg(WndMain.hWnd, szFilter, szFileName))
LoadGame(szFileName);
ec.fChooseFile = FALSE;
} // endif(i==1)
if(i==2) // Save Game Button Message
{
ec.fChooseFile = TRUE;
if(SaveFileDlg(WndMain.hWnd, szFilter, szFileName))
SaveGame(szFileName);
ec.fChooseFile = FALSE;
} // endif(i==2)
if(i==3) // Undo Button Message
{
Undo();
} // endif(i==3)
if(i==4) // Redo Button Message
{
Redo();
} // endif(i==4)
SetFocus(WndMain.hWnd);
}
////////////////////////////////////////////////////////////////////////
// Setting Context Button
if(ec.iTab == ID_SETTING)
{
if(i==0) // Game Setting Button Message
{
DefaultSetting();
SetSetting();
ReDrawBanner();
InvalidateRect(DlgSetting.hWnd, NULL, FALSE);
SetWindowLong(WndMain.hWnd, GWL_EXSTYLE , 0);
PlaySoundFile(WndMain.hWnd, setting.szSoundFile);
} //endif(i==0)
}
////////////////////////////////////////////////////////////////////////
// Credit Context Button
if(ec.iTab == ID_CREDIT)
{
if(i==0) // Homepage Button Message
{
iLength = GetEnvironmentVariable ("ProgramFiles", NULL, 0) ;
szIEDir = (TCHAR*) calloc ( iLength, sizeof(TCHAR));
GetEnvironmentVariable ("ProgramFiles", szIEDir, iLength) ;
ShellExecute (NULL, "open", "iexplore.exe", "http://anitsoft.googlepages.com",szIEDir, SW_SHOWDEFAULT);
} //endif(i==0)
if(i==1) // About Button Message
{
DialogBox(ec.hInst ,"IDD_ABOUT",WndMain.hWnd ,DlgAboutProc);
} // endif(i==1)
}
}
/***************************************************/
// Redraw all button
InvalidateRect(WndBtn[ID_PLAY].hWnd ,NULL,FALSE);
InvalidateRect(WndBtn[ID_SETTING].hWnd ,NULL,FALSE);
InvalidateRect(WndBtn[ID_CREDIT].hWnd ,NULL,FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -