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

📄 optionsdialog.cpp

📁 一个人工智能的国际象棋游戏
💻 CPP
字号:
/****************************************************
Author: S. Senthil kumar
File: ColorDialog.cpp
Purpose:    For storing and displaying values in Options Dialog box

******************************************************/
#include "Global.h"

#include "OptionsDialog.h"
#include "myapp.h"
extern int autoplay;
extern int sndenable;
extern CString defdir;
extern myapp a;
extern keep_music_playing=0;
extern COLORREF WHITESQUARE;
extern COLORREF BLACKSQUARE;
OptionsDialog::OptionsDialog(int n):CDialog(n)
	{
	}


void OptionsDialog::OnOK()
	
	{
		char ret[10];
	if (IsDlgButtonChecked(IDC_CHECK2) && defdir=="")
		{
			MessageBox("You must select a Directory","Select Directory",0);
			return;
		}
		if (tempdir!="") 
		{
			defdir=tempdir;
		}
		if (!IsDlgButtonChecked(IDC_CHECK2))
		{
			keep_music_playing=0;
			mciSendString("stop aria",ret,10,NULL);
			mciSendString("close aria",ret,lstrlen(ret),NULL);
		}
		CString deflevel;
		GetDlgItemText(IDC_COMBO1,deflevel);
		CListBox *list=(CListBox *)GetDlgItem(IDC_COMBO1);
		list->GetText(list->GetCurSel(),deflevel);
		if (whitecolorchanged)
		{
			WHITESQUARE=whitesquare;
		}
		if (blackcolorchanged)
		{
			BLACKSQUARE=blacksquare;
		}
		a.StoreOptions(IsDlgButtonChecked(IDC_CHECK2),IsDlgButtonChecked(IDC_CHECK1),deflevel,defdir);
		autoplay=IsDlgButtonChecked(IDC_CHECK2);
		sndenable=IsDlgButtonChecked(IDC_CHECK1);
		CDialog::OnOK();
	}
int OptionsDialog::OnInitDialog()
	{
		//Set user selected level,options stored
		combo=(CListBox *)GetDlgItem(IDC_COMBO1);
		combo->AddString("I Dunno Chess");
		combo->AddString("Novice");
		combo->AddString("Intermediate");
		combo->AddString("Expert");
		combo->SelectString(-1,"Intermediate");
		
		if (autoplay==1)
		{
			CheckDlgButton(IDC_CHECK2,TRUE);
			CButton *select=(CButton *)GetDlgItem(IDC_BUTTON1);
			select->EnableWindow(TRUE);
			SetDlgItemText(IDC_STATIC,(CString)"Selected directory: "+defdir);
		}
		if (sndenable==1)
		{
			CheckDlgButton(IDC_CHECK1,TRUE);
		}
		whitecolorchanged=0;
		blackcolorchanged=0;
		
		return CDialog::OnInitDialog();



	}
void OptionsDialog::OnEnableSound()
	{
		
		//Disable or enable "Select Music Directory" button according to checking of ID_CHECK2
		CButton *ok=(CButton *)GetDlgItem(IDC_BUTTON1);
		
		if (IsDlgButtonChecked(IDC_CHECK2))
		{
		
			ok->EnableWindow(TRUE);
			
			
		}
		else
		{
			ok->EnableWindow(FALSE);
			
		}

	}
void OptionsDialog::ShowOpen()
	{
		
		//Show Open Dialog box and allows user to select a directory
		/*CFileDialog d(TRUE,NULL,NULL,OFN_HIDEREADONLY,NULL,this);
		d.DoModal();
	    CString path=d.GetPathName();
		*/
		LPBROWSEINFO b=new BROWSEINFO;
		b->hwndOwner=this->m_hWnd;
		b->pidlRoot=NULL;
		char buf[MAX_PATH];
		b->pszDisplayName=buf;
		b->lpszTitle="Select a Folder";
		b->ulFlags=1;
		b->lpfn=NULL;
		b->lParam=0;
		b->iImage=0;
		
		LPITEMIDLIST direct=::SHBrowseForFolder(b);
		if (direct)
		{
			::SHGetPathFromIDList(direct,buf);
			tempdir=buf;
		}
		
		CEdit *label=(CEdit *)GetDlgItem(IDC_EDIT1);
		label->SetWindowText((CString)"Selected directory: "+tempdir);
		
		
	}
	void OptionsDialog::OnCancel()
	{
		CDialog::OnCancel();
	}

	void OptionsDialog::ShowColorDialog(int id)
	{
		
		//Shows color dialog.
		CColorDialog c;
		
		c.DoModal();
		if (id==IDC_BUTTON3)
		{
			whitesquare=c.GetColor();
			whitecolorchanged=1;
		}
		else
		{
			blacksquare=c.GetColor();
			blackcolorchanged=1;
		}
	
	}
	void OptionsDialog::RestoreDefaults()
	{
		 blacksquare= RGB(100,100,115);
		 whitesquare= RGB(195,195,195);
	}




BEGIN_MESSAGE_MAP(OptionsDialog,CDialog)
ON_COMMAND(IDC_CHECK2,OnEnableSound)
ON_COMMAND(IDOK,OnOK)
ON_COMMAND(IDC_BUTTON2,OnCancel)
ON_COMMAND(IDC_BUTTON1,ShowOpen)
ON_COMMAND_RANGE(1028,1029,ShowColorDialog)
ON_COMMAND(IDC_BUTTON5,RestoreDefaults)
END_MESSAGE_MAP()


⌨️ 快捷键说明

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