?? dlgaical.cpp
字號:
// DlgAICal.cpp : implementation file
//
#include "stdafx.h"
#include "JL.h"
#include "JLDoc.h"
#include "DlgAICal.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgAICal dialog
#define ID_TIMER_STEP 300
extern CJLDoc * AfxGetDocument();
extern CJLView * AfxGetView();
extern volatile bool g_bStopAICal;
UINT AICalThread(void * para);
CDlgAICal::CDlgAICal(CWnd* pParent /*=NULL*/)
: CDialog(CDlgAICal::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgAICal)
//}}AFX_DATA_INIT
}
void CDlgAICal::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgAICal)
DDX_Control(pDX, IDCHK_MAX_SPEED, m_chkMaxSpeed);
DDX_Control(pDX, IDB_STOP, m_btnStop);
DDX_Control(pDX, IDC_PROGRESS_STATUS, m_ctrlProgress);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgAICal, CDialog)
//{{AFX_MSG_MAP(CDlgAICal)
ON_BN_CLICKED(IDCHK_MAX_SPEED, OnMaxSpeed)
ON_BN_CLICKED(IDB_STOP, OnStop)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgAICal message handlers
//開啟一個線程執行自動解答
UINT AICalThread(void * para)
{
CDlgAICal* pDlg = (CDlgAICal*)para;
CJLDoc *pDoc = AfxGetDocument();
pDlg->m_bSuccess = pDoc->DoAICal();
pDlg->KillTimer(pDlg->m_nTimer);
pDlg->EndDialog(0);
return 0;
}
void CDlgAICal::OnStop()
{
// TODO: Add extra cleanup here
//點擊“停止”按扭后該按扭將變成灰色,必須等待牌局還原后對話框才會關閉
m_btnStop.EnableWindow(FALSE);
SetWindowText("正在還原牌局,請等待......");
g_bStopAICal = true;//停止解答
}
void CDlgAICal::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CJLDoc *pDoc = AfxGetDocument();
//實時顯示計算到了哪一步,通常成功的解答步數介于30-70步之間
//如果接近80步說明此局可能解不開,玩家可停止自動解答
if(!pDoc->m_pOps->IsEmpty()) {
int cnt = pDoc->m_pOps->GetCount();
m_ctrlProgress.SetPos(1+cnt%100);
}
CDialog::OnTimer(nIDEvent);
}
BOOL CDlgAICal::OnInitDialog()
{
CDialog::OnInitDialog();
//進度每秒刷新5次
m_nTimer = SetTimer(ID_TIMER_STEP,1000/5,NULL);
//通常不會超過100步
m_ctrlProgress.SetRange(1,100);
//默認打開“快速解答”選項
m_chkMaxSpeed.SetCheck(1);
OnMaxSpeed();
m_hCalThread = AfxBeginThread(AICalThread,this,THREAD_PRIORITY_LOWEST,0,0);
return TRUE;
}
//單擊“快速解答”后將執行此函數
void CDlgAICal::OnMaxSpeed()
{
CJLDoc *pDoc = AfxGetDocument();
pDoc->m_bRealTimeUpdate = m_chkMaxSpeed.GetCheck() ? false : true;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -