⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queendlg.cpp

📁 八皇后演示程序,VC6.0开发环境 初学c++ 望指正
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// QueenDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Queen.h"
#include "QueenDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

/*CRect getpointRect(int x, int y)
{
	//用于得到一个子的矩形区域
	CRect rect;
	rect.top = 24*y-5;
	rect.bottom = 24*y+15;
	rect.left = 24*x-5;
	rect.right = 24*x+15;	
	return rect;
}

void Delay()
{
	for (int i=0;i<10000;i++)
	{

	}
}*/

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CQueenDlg dialog

CQueenDlg::CQueenDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CQueenDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CQueenDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	total=0;
	one=two=three=four=five=six=seven=1;
	flag=0;
	m_Judge=m_Judge1=m_Judge2=TRUE;
	m_pause=0;
	m_pauseTime1=0;
	m_chose=3;
	m_num1=0;
}

void CQueenDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CQueenDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CQueenDlg, CDialog)
	//{{AFX_MSG_MAP(CQueenDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_START, OnStart)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_PAUSE, OnPause)
	ON_CBN_EDITCHANGE(IDC_COMBO2, OnEditchangeCombo2)
	ON_CBN_SELCHANGE(IDC_COMBO2, OnSelchangeCombo2)
	ON_COMMAND(IDM_BACKDATE, OnBackdate)
	ON_COMMAND(IDM_RANSACK, OnRansack)
	ON_COMMAND(IDM_DIRECT, OnDirect)
	ON_COMMAND(IDM_AUTO, OnAuto)
	ON_COMMAND(IDM_ONESTEP, OnOnestep)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CQueenDlg message handlers

BOOL CQueenDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	
	CBitmap bmp;
	bmp.LoadBitmap(IDB_QIPAN2);
	m_brush=CreatePatternBrush((HBITMAP)bmp);
	bmp.DeleteObject();/**/
	
	// TODO: Add extra initialization here
	
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("10");
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("50");
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("100");
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("200");
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("300");
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("400");
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("500");
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("600");
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("700");
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("800");
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("900");
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("1000");
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("2000");
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("3000");
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("4000");
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("5000");

	((CComboBox *)GetDlgItem(IDC_COMBO2))->SetCurSel(6);

	m_timer=GetDlgItemInt(IDC_COMBO2);

	GetDlgItem(IDC_PAUSE)->ShowWindow(SW_HIDE);
	SetDlgItemInt(IDC_EDIT2,0);
	GetMenu()->GetSubMenu(0)->CheckMenuItem(2,MF_BYPOSITION|MF_CHECKED);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CQueenDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CQueenDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CPaintDC dc(this);
		CDC dcmem;BITMAP bm;
		dcmem.CreateCompatibleDC(&dc);
		int tempx,tempy;
		CBitmap bmp;
		bmp.LoadBitmap(IDB_DARK);
		GetObject(bmp,sizeof(BITMAP),(LPVOID)&bm);
		

		if (m_chose!=3)
		{
			for(int m=0;m<=6;m++)
			{
					for(int n=1;n<=7;n++)
					{
						if(n==A[m])
						{
							tempx = 24*(n)-bm.bmWidth/2-9;
							tempy = 24*(m+1)-bm.bmHeight/2-9;												
							dcmem.SelectObject(&bmp);
							dc.BitBlt(tempx+10,tempy+10,bm.bmWidth,bm.bmHeight,&dcmem,0,0,SRCCOPY);
						}
					}
			}
		}
		
		else if (!m_Judge1&&m_chose==3)
		{
			static int num;
			while(m_num1<m_num&&m_LineNum1.GetAt(m_num1)!='#')
			{
					if (m_LineNum1.GetAt(m_num1)!='$')
					{
						num=atoi(m_LineNum1.GetAt(m_num1));
						tempy = 24*(num)-bm.bmWidth/2-9;
						num=atoi(m_LineNum.GetAt(m_num1));
						m_num1++;
						tempx = 24*(num)-bm.bmHeight/2-9;											
						dcmem.SelectObject(&bmp);
						dc.BitBlt(tempx+10,tempy+10,bm.bmWidth,bm.bmHeight,&dcmem,0,0,SRCCOPY);
					}
					else
					{
						total++;
						SetDlgItemInt(IDC_EDIT2,total);
						m_num1++;
					}
			}
			m_num1++;
			if(m_num1>=m_num)
			{
				if (m_Judge2)
				{
					KillTimer(1);
				}
				else
				{
					SetDlgItemText(IDC_START,"结束了");
					((CButton*)GetDlgItem(IDC_START))->EnableWindow(FALSE);
				}
			}
		}
		CString str;
		if (m_Judge2)
		{
			if (GetDlgItemText(IDC_PAUSE,str),str=="结束了")
			{
				SetDlgItemText(IDC_START,"重新开始");
				GetDlgItem(IDC_PAUSE)->EnableWindow(FALSE);
				one=two=three=four=five=six=seven=1;
				total=0;
				KillTimer(1);
				m_Judge=TRUE;
			}
		}
		else
		{
			if (GetDlgItemText(IDC_PAUSE,str),str=="结束了")
			{
				SetDlgItemText(IDC_START,"结束了");
				((CButton*)GetDlgItem(IDC_START))->EnableWindow(FALSE);
			}
		}
		CDialog::OnPaint();
		
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CQueenDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

HBRUSH CQueenDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	
	if (nCtlColor==CTLCOLOR_DLG)
		return m_brush;	
	if (nCtlColor==CTLCOLOR_STATIC) 
	{	
		if (!pWnd->IsKindOf( RUNTIME_CLASS( CEdit )))
		{
			pDC->SetBkMode(TRANSPARENT);
			return m_brush;
		}
	}
	// TODO: Return a different brush if the default is not desired
	return hbr;
}



void CQueenDlg::OnStart() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	CString str,str1;
	CTime time=CTime::GetCurrentTime();
	str=time.Format("%H:%M:%S");
	str1=str;
	if(m_Judge)
	{
		m_tStart=time;
		SetDlgItemText(IDC_STARTTIME,str);
		SetDlgItemText(IDC_ENDTIME,"0:0:0");
		SetDlgItemText(IDC_TOTALTIME,"0:0:0");
	}
	GetDlgItemText(IDC_START,str);
	if (str=="开始"||str=="重新开始")
	{
		SetDlgItemText(IDC_PAUSETIME,"0:0:0");
		SetDlgItemInt(IDC_MANY,0);
		SetDlgItemText(IDC_TOTALTIME,"0:0:0");
		SetDlgItemText(IDC_WHOLEPAUSETIME,"0:0:0");
		SetDlgItemText(IDC_START,"停止");
		SetDlgItemText(IDC_PAUSE,"暂停");
		GetDlgItem(IDC_PAUSE)->ShowWindow(SW_SHOW);
		SetTimer(1,m_timer,NULL);
		m_Judge=FALSE;
		m_pause=0;
		m_pauseTime1=0;
		m_num1=0;
	}
	else if(str=="停止")
	{
		m_tEnd=time;
		SetDlgItemText(IDC_ENDTIME,str1);
		CTimeSpan wholeTime=m_tEnd-m_tStart;
		str1=wholeTime.Format("%H:%M:%S");
		SetDlgItemText(IDC_TOTALTIME,str1);
		SetDlgItemText(IDC_START,"重新开始");
		one=two=three=four=five=six=seven=1;
		total=0;
		SetDlgItemInt(IDC_EDIT2,0);
		memset(A,1,7);
		KillTimer(1);
		m_Judge=TRUE;
		GetDlgItem(IDC_PAUSE)->ShowWindow(SW_HIDE);
	}
	else
	{
		m_Judge=FALSE;
		switch(m_chose) {
		case 1:
			if(one<=7) 
			{
				if(two<=7) 
				{
		/*			{
						SetDlgItemText(IDC_PAUSE,"结束了");
						Invalidate();
						CTime time=CTime::GetCurrentTime();
						m_tEnd=time;
							CTimeSpan wholeTime=m_tEnd-m_tStart;
							
							CString str;
							str=time.Format("%H:%M:%S");
							SetDlgItemText(IDC_ENDTIME,str);
							str=wholeTime.Format("%H:%M:%S");
							SetDlgItemText(IDC_TOTALTIME,str);
							KillTimer(1);
							return;
						}*/
					if(three<=7) 
					{
						if(four<=7) 
						{
							if(five<=7) 
							{
								if(six<=7) 
								{
									if(seven<=7) 
									{
											// 为了便于运算数组里 
											A[0]=one;
											A[1]=two;
											A[2]=three;
											A[3]=four;
											A[4]=five;
											A[5]=six;
											A[6]=seven;
											//比较是否在同一列 
											flag=0; 
											for(int i=6;i>0;i--) 
											{ 
												for(int j=0;j<i;j++) 
												if(A[i]==A[j]) 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -