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

📄 setup.cpp

📁 用几种规则控制倒立摆的模糊运动的程序
💻 CPP
字号:
// SETUP.cpp : implementation file
//

#include "stdafx.h"
#include "DAOLI2.h"
#include "SETUP.h"
#include "DAOLI2View.h"
#include "MainFrm.h"

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

extern  bool DeListRules[RulesCounter];
extern  int polespeed;
extern  int poleangle;
/////////////////////////////////////////////////////////////////////////////
// SETUP dialog
static UINT rules[] =
{
	IDS_STRRULES1,           // 
	IDS_STRRULES2,
	IDS_STRRULES3,
	IDS_STRRULES4,
	IDS_STRRULES5,           //
	IDS_STRRULES6,
	IDS_STRRULES7,
	IDS_STRRULES8,
	IDS_STRRULES9,           // 
	IDS_STRRULES10,
	IDS_STRRULES11,	
};


SETUP::SETUP(CWnd* pParent /*=NULL*/)
	: CDialog(SETUP::IDD, pParent)
{
	//{{AFX_DATA_INIT(SETUP)
	m_nspeed = 0;
	//}}AFX_DATA_INIT
}


void SETUP::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(SETUP)
	DDX_Text(pDX, IDC_ANGLEEDIT, m_nangle);
	DDV_MinMaxInt(pDX, m_nangle, -90, 90);
	DDX_Text(pDX, IDC_SPEEDEDIT, m_nspeed);
	DDV_MinMaxInt(pDX, m_nspeed, -180, 180);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(SETUP, CDialog)
	//{{AFX_MSG_MAP(SETUP)
	ON_WM_PAINT()
	ON_WM_VSCROLL()
	ON_LBN_DBLCLK(IDC_RULESLIST, OnDblclkRuleslist)
	ON_BN_CLICKED(IDC_ALLSELECT, OnAllselect)
	ON_BN_CLICKED(IDC_ALLDESELECT, OnAlldeselect)
	ON_LBN_DBLCLK(IDC_LIST2, OnDblclkList2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// SETUP message handlers

BOOL SETUP::OnInitDialog() 
{
	
	// TODO: Add extra initialization here
    m_nspeed=polespeed;
	m_nangle=poleangle;

    // Be careful to call CDialog::OnInitDialog
    //  only once in this function
    CListBox* pLB1 = (CListBox*) GetDlgItem(IDC_RULESLIST);
	CListBox* pLB2 = (CListBox*) GetDlgItem(IDC_LIST2);
	CString s;
	for(int i=0;i<RulesCounter;i++)
	{
		bDlgRulesSel[i]=DeListRules[i];
		s.Format(rules[i]);
		pLB1->InsertString(-1, s);
		if(bDlgRulesSel[i])
			pLB2->InsertString(-1,s);
	}
    
  
	CSpinButtonCtrl* pSpin1 =
		(CSpinButtonCtrl*) GetDlgItem(IDC_ANGLESPIN);
	pSpin1->SetRange(0, 180);
	pSpin1->SetPos(m_nangle+90); 

	CSpinButtonCtrl* pSpin2 =
		(CSpinButtonCtrl*) GetDlgItem(IDC_SPEEDSPIN);
	pSpin2->SetRange(0, 360);
	pSpin2->SetPos(m_nspeed+180); 

   	
	return CDialog::OnInitDialog();  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void SETUP::OnPaint() 
{
	CPaintDC dc(this); // device context for painting

	
	// TODO: Add your message handler code here

	
	// Do not call CDialog::OnPaint() for painting messages
}

void SETUP::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	
    if (nSBCode == SB_ENDSCROLL) {
        return; // Reject spurious messages
    }
    // Process scroll messages from IDC_SPIN1 only
    if (pScrollBar->GetDlgCtrlID() == IDC_ANGLESPIN)
	{
        CString strValue;
        strValue.Format("%d", nPos-90);
        ((CSpinButtonCtrl*) pScrollBar)->GetBuddy()
                                       ->SetWindowText(strValue);
    } 
	else if (pScrollBar->GetDlgCtrlID() == IDC_SPEEDSPIN)
	{
        CString strValue;
        strValue.Format("%d",nPos-180);
        ((CSpinButtonCtrl*) pScrollBar)->GetBuddy()
                                       ->SetWindowText(strValue);
    } 

//	CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}

void SETUP::OnDblclkRuleslist() 
{
	// TODO: Add your control notification handler code here

	CListBox* pLB1 = (CListBox*) GetDlgItem(IDC_RULESLIST);
	CListBox* pLB2 = (CListBox*) GetDlgItem(IDC_LIST2);
	int nSelect=pLB1->GetCurSel();
    if(!bDlgRulesSel[nSelect])
	{
		CString s;
		s.Format(rules[nSelect]);
		pLB2->InsertString(-1,s);
		bDlgRulesSel[nSelect]=true;
	}

}

void SETUP::OnAllselect() 
{

	// TODO: Add your control notification handler code here
	CListBox* pLB2 = (CListBox*) GetDlgItem(IDC_LIST2);
	CString s;
	for(int i=0;i<RulesCounter;i++)
	{
		if(!bDlgRulesSel[i])
		{
			s.Format(rules[i]);
			pLB2->InsertString(-1,s);
			bDlgRulesSel[i]=true;
		}
	}
}

void SETUP::OnAlldeselect() 
{
	for(int i=0;i<RulesCounter;i++)
	{
		bDlgRulesSel[i]=false;
	}
	// TODO: Add your control notification handler code here
	CListBox* pLB = (CListBox*) GetDlgItem(IDC_LIST2);
    int ruleCtr=pLB->GetCount();
	for(i=ruleCtr-1;i>=0;i--)
	{
		pLB->DeleteString(i);
	}
	
	
}

void SETUP::OnDblclkList2() 
{
	CString s1,s2;
	// TODO: Add your control notification handler code here
    //CListBox* pLB1 = (CListBox*) GetDlgItem(IDC_RULESLIST);
	CListBox* pLB2= (CListBox*) GetDlgItem(IDC_LIST2);
	int ncurSelect=pLB2->GetCurSel();
	pLB2->GetText(ncurSelect,s2);
	for(int i=0;i<RulesCounter;i++)
	{
		s1.Format(rules[i]);
		if(!s1.Compare(s2))
		{
			pLB2->DeleteString(ncurSelect);
			bDlgRulesSel[i]=false;
		}
	}	
}

void SETUP::OnOK() 
{
	// TODO: Add extra validation here
	for(int i=0;i<RulesCounter;i++)
	{
		DeListRules[i]=bDlgRulesSel[i];
	}
	CDialog::OnOK();
	polespeed=m_nspeed;
	poleangle=m_nangle;
	CWnd *pparentWnd=SETUP::GetParent();
	pparentWnd->Invalidate();	
}

⌨️ 快捷键说明

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