WINCE中微调按键和编辑框的绑定问题

来源:互联网 发布:2016年nba总决赛数据 编辑:程序博客网 时间:2024/05/22 13:57

   设计一个wince应用程序,要求有三个微调按钮和编辑框,用来调整颜色搭配。

首先我们放置三对微调按钮和编辑框,并在初始化中绑定

BOOL CSpinUseDlg::OnInitDialog(){CDialog::OnInitDialog();// Set the icon for this dialog.  The framework does this automatically//  when the application's main window is not a dialogSetIcon(m_hIcon, TRUE);// Set big iconSetIcon(m_hIcon, FALSE);// Set small icon// TODO: Add extra initialization hereCSpinButtonCtrl *pSpinRed = (CSpinButtonCtrl*)GetDlgItem(IDC_SPIN_RED);ASSERT(pSpinRed!=NULL);pSpinRed->SetBuddy(GetDlgItem(IDC_EDT_RED));pSpinRed->SetRange(0,255);pSpinRed->SetPos(128);CSpinButtonCtrl *pSpinGreen = (CSpinButtonCtrl*)GetDlgItem(IDC_SPIN_GREEN);ASSERT(pSpinGreen!=NULL);pSpinGreen->SetBuddy(GetDlgItem(IDC_EDT_GREEN));pSpinGreen->SetRange(0,255);pSpinGreen->SetPos(128);CSpinButtonCtrl *pSpinBlue = (CSpinButtonCtrl*)GetDlgItem(IDC_SPIN_BLUE);ASSERT(pSpinBlue!=NULL);pSpinBlue->SetBuddy(GetDlgItem(IDC_EDT_BLUE));pSpinBlue->SetRange(0,255);pSpinBlue->SetPos(128);return TRUE;  // return TRUE  unless you set the focus to a control}

消息处理函数:

void CSpinUseDlg::RGBColorChange() {UpdateData(TRUE);CBrush colorBrush;COLORREF clRGB;    clRGB = RGB(m_red,m_green,m_blue);CClientDC * pClientDC;pClientDC = new CClientDC(this);colorBrush.CreateSolidBrush(clRGB);CRect rect(80,120,160,200);pClientDC->FillRect(rect,&colorBrush);delete pClientDC;}void CSpinUseDlg::OnEnChangeEdtRed(){RGBColorChange();// send this notification unless you override the CDialog::OnInitDialog()// function and call CRichEditCtrl().SetEventMask()// with the ENM_CHANGE flag ORed into the mask.// TODO:  Add your control notification handler code here}void CSpinUseDlg::OnEnChangeEdtGreen(){RGBColorChange();// send this notification unless you override the CDialog::OnInitDialog()// function and call CRichEditCtrl().SetEventMask()// with the ENM_CHANGE flag ORed into the mask.// TODO:  Add your control notification handler code here}void CSpinUseDlg::OnEnChangeEdtBlue(){RGBColorChange();// send this notification unless you override the CDialog::OnInitDialog()// function and call CRichEditCtrl().SetEventMask()// with the ENM_CHANGE flag ORed into the mask.// TODO:  Add your control notification handler code here}
设置三个变量,分别关联三个颜色值,范围是0-255,整数。

public:BYTE m_red;  //BYTE m_green; //BYTE m_blue; //


变量和编辑框的值绑定

void CSpinUseDlg::DoDataExchange(CDataExchange* pDX){CDialog::DoDataExchange(pDX);DDX_Text(pDX, IDC_EDT_RED, m_red);DDV_MinMaxByte(pDX, m_red, 0, 255);DDX_Text(pDX, IDC_EDT_GREEN, m_green);DDV_MinMaxByte(pDX, m_green, 0, 255);DDX_Text(pDX, IDC_EDT_BLUE, m_blue);DDV_MinMaxByte(pDX, m_blue, 0, 25

运行程序,发现微调按键并不能调整编辑框的值,先前的绑定语句没有起作用。

一番查找后,问题解决了,在微调按钮的属性里面需要设置Set buddy integer为ture,程序正常运行,绑定成功。


原创粉丝点击