问题:
在哪儿设置SetRange(),我在Onbutton()中失败!有没有其他什么方法.
9 个解决方案
#1
难道真的没有人解答么
#2
各位老大,帮帮忙啊
#3
能把代码贴一下吗?谢谢,要不然怎么帮你?
#4
其实我就是对话框上的控件影射成变量,但是debug assert failed,我没有办法才用其他方法的
void CGameDlg::OnPost()
{
CDialog2 dlg;
dlg.m_Spin.SetRange32(0,100000);//m_Spin是CDilog2中的变量
//CSpinButtonCtrl m_Spin;
}
void CGameDlg::OnPost()
{
CDialog2 dlg;
dlg.m_Spin.SetRange32(0,100000);//m_Spin是CDilog2中的变量
//CSpinButtonCtrl m_Spin;
}
#5
给你个例子,这是一个dialog,里面有两个edit框,焦点如果在edit1里那么spin控制edit1,如果焦点在edit2里那么spin控制edit2。
/////////////////////////////////////////////////////////////////////////////
// CMyDialog dialog
CMyDialog::CMyDialog(CWnd* pParent /*=NULL*/)
: CDialog(CMyDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDialog)
m_hour = 0;
m_minu = 0;
m_pWnd = NULL;
m_someint = 0;
m_isSpin = FALSE;
//}}AFX_DATA_INIT
}
void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDialog)
DDX_Control(pDX, IDC_SPIN2, m_mySpinCtrl2);
DDX_Control(pDX, IDC_SPIN1, m_mySpinCtrl);
DDX_Text(pDX, IDC_EDIT1, m_hour);
DDX_Text(pDX, IDC_EDIT2, m_minu);
DDX_Text(pDX, IDC_EDIT3, m_someint);
DDV_MinMaxInt(pDX, m_someint, 0, 10);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
//{{AFX_MSG_MAP(CMyDialog)
ON_EN_SETFOCUS(IDC_EDIT1, OnSetfocusEdit1)
ON_EN_SETFOCUS(IDC_EDIT2, OnSetfocusEdit2)
ON_EN_KILLFOCUS(IDC_EDIT1, OnKillfocusEdit1)
ON_EN_KILLFOCUS(IDC_EDIT2, OnKillfocusEdit2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDialog message handlers
void CMyDialog::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
((CSpinButtonCtrl*)GetDlgItem(IDC_SPIN2))->SetRange(0,100);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CMyDialog::OnSetfocusEdit1()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_SPIN1)->EnableWindow(TRUE);
m_pWnd = GetFocus();
m_mySpinCtrl.SetBuddy(m_pWnd);
m_mySpinCtrl.SetRange(0,23);
// GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
}
void CMyDialog::OnSetfocusEdit2()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_SPIN1)->EnableWindow(TRUE);
m_pWnd = GetFocus();
m_mySpinCtrl.SetBuddy(m_pWnd);
m_mySpinCtrl.SetRange(0,59);
// GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
}
void CMyDialog::OnKillfocusEdit1()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
}
void CMyDialog::OnKillfocusEdit2()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
}
/////////////////////////////////////////////////////////////////////////////
// CMyDialog dialog
CMyDialog::CMyDialog(CWnd* pParent /*=NULL*/)
: CDialog(CMyDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDialog)
m_hour = 0;
m_minu = 0;
m_pWnd = NULL;
m_someint = 0;
m_isSpin = FALSE;
//}}AFX_DATA_INIT
}
void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDialog)
DDX_Control(pDX, IDC_SPIN2, m_mySpinCtrl2);
DDX_Control(pDX, IDC_SPIN1, m_mySpinCtrl);
DDX_Text(pDX, IDC_EDIT1, m_hour);
DDX_Text(pDX, IDC_EDIT2, m_minu);
DDX_Text(pDX, IDC_EDIT3, m_someint);
DDV_MinMaxInt(pDX, m_someint, 0, 10);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
//{{AFX_MSG_MAP(CMyDialog)
ON_EN_SETFOCUS(IDC_EDIT1, OnSetfocusEdit1)
ON_EN_SETFOCUS(IDC_EDIT2, OnSetfocusEdit2)
ON_EN_KILLFOCUS(IDC_EDIT1, OnKillfocusEdit1)
ON_EN_KILLFOCUS(IDC_EDIT2, OnKillfocusEdit2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDialog message handlers
void CMyDialog::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
((CSpinButtonCtrl*)GetDlgItem(IDC_SPIN2))->SetRange(0,100);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CMyDialog::OnSetfocusEdit1()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_SPIN1)->EnableWindow(TRUE);
m_pWnd = GetFocus();
m_mySpinCtrl.SetBuddy(m_pWnd);
m_mySpinCtrl.SetRange(0,23);
// GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
}
void CMyDialog::OnSetfocusEdit2()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_SPIN1)->EnableWindow(TRUE);
m_pWnd = GetFocus();
m_mySpinCtrl.SetBuddy(m_pWnd);
m_mySpinCtrl.SetRange(0,59);
// GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
}
void CMyDialog::OnKillfocusEdit1()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
}
void CMyDialog::OnKillfocusEdit2()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
}
#6
楼上说的不是我所要求的
#7
你应该在Dialog1::OinitDialog()中写入代码。
m_Spin.SetRange32(0,100000);
m_Spin.SetRange32(0,100000);
#8
因为你创建了Dialog2的实例的时候:CDialog2 dlg;其成员控件CDialog2.m_Spin并未创建,所以这样的调用是无效的。
应该在CDialog2添加两个成员变量:int m_low, m_up;然后在OnPost()中:
CDialog2 dlg;
dlg.m_low = 0;
dlg.m_up = 100000;
在CDialog2::OnInitDialgo()中:(此时其成员控件变量m_Spin是有效的了,并且m_low和m_up由调用的程序赋值)
m_Spin.SetRange32(m_low, m_up);
应该在CDialog2添加两个成员变量:int m_low, m_up;然后在OnPost()中:
CDialog2 dlg;
dlg.m_low = 0;
dlg.m_up = 100000;
在CDialog2::OnInitDialgo()中:(此时其成员控件变量m_Spin是有效的了,并且m_low和m_up由调用的程序赋值)
m_Spin.SetRange32(m_low, m_up);
#9
static成员设一下吧,不过要保证IsWindow
#1
难道真的没有人解答么
#2
各位老大,帮帮忙啊
#3
能把代码贴一下吗?谢谢,要不然怎么帮你?
#4
其实我就是对话框上的控件影射成变量,但是debug assert failed,我没有办法才用其他方法的
void CGameDlg::OnPost()
{
CDialog2 dlg;
dlg.m_Spin.SetRange32(0,100000);//m_Spin是CDilog2中的变量
//CSpinButtonCtrl m_Spin;
}
void CGameDlg::OnPost()
{
CDialog2 dlg;
dlg.m_Spin.SetRange32(0,100000);//m_Spin是CDilog2中的变量
//CSpinButtonCtrl m_Spin;
}
#5
给你个例子,这是一个dialog,里面有两个edit框,焦点如果在edit1里那么spin控制edit1,如果焦点在edit2里那么spin控制edit2。
/////////////////////////////////////////////////////////////////////////////
// CMyDialog dialog
CMyDialog::CMyDialog(CWnd* pParent /*=NULL*/)
: CDialog(CMyDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDialog)
m_hour = 0;
m_minu = 0;
m_pWnd = NULL;
m_someint = 0;
m_isSpin = FALSE;
//}}AFX_DATA_INIT
}
void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDialog)
DDX_Control(pDX, IDC_SPIN2, m_mySpinCtrl2);
DDX_Control(pDX, IDC_SPIN1, m_mySpinCtrl);
DDX_Text(pDX, IDC_EDIT1, m_hour);
DDX_Text(pDX, IDC_EDIT2, m_minu);
DDX_Text(pDX, IDC_EDIT3, m_someint);
DDV_MinMaxInt(pDX, m_someint, 0, 10);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
//{{AFX_MSG_MAP(CMyDialog)
ON_EN_SETFOCUS(IDC_EDIT1, OnSetfocusEdit1)
ON_EN_SETFOCUS(IDC_EDIT2, OnSetfocusEdit2)
ON_EN_KILLFOCUS(IDC_EDIT1, OnKillfocusEdit1)
ON_EN_KILLFOCUS(IDC_EDIT2, OnKillfocusEdit2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDialog message handlers
void CMyDialog::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
((CSpinButtonCtrl*)GetDlgItem(IDC_SPIN2))->SetRange(0,100);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CMyDialog::OnSetfocusEdit1()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_SPIN1)->EnableWindow(TRUE);
m_pWnd = GetFocus();
m_mySpinCtrl.SetBuddy(m_pWnd);
m_mySpinCtrl.SetRange(0,23);
// GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
}
void CMyDialog::OnSetfocusEdit2()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_SPIN1)->EnableWindow(TRUE);
m_pWnd = GetFocus();
m_mySpinCtrl.SetBuddy(m_pWnd);
m_mySpinCtrl.SetRange(0,59);
// GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
}
void CMyDialog::OnKillfocusEdit1()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
}
void CMyDialog::OnKillfocusEdit2()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
}
/////////////////////////////////////////////////////////////////////////////
// CMyDialog dialog
CMyDialog::CMyDialog(CWnd* pParent /*=NULL*/)
: CDialog(CMyDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDialog)
m_hour = 0;
m_minu = 0;
m_pWnd = NULL;
m_someint = 0;
m_isSpin = FALSE;
//}}AFX_DATA_INIT
}
void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDialog)
DDX_Control(pDX, IDC_SPIN2, m_mySpinCtrl2);
DDX_Control(pDX, IDC_SPIN1, m_mySpinCtrl);
DDX_Text(pDX, IDC_EDIT1, m_hour);
DDX_Text(pDX, IDC_EDIT2, m_minu);
DDX_Text(pDX, IDC_EDIT3, m_someint);
DDV_MinMaxInt(pDX, m_someint, 0, 10);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
//{{AFX_MSG_MAP(CMyDialog)
ON_EN_SETFOCUS(IDC_EDIT1, OnSetfocusEdit1)
ON_EN_SETFOCUS(IDC_EDIT2, OnSetfocusEdit2)
ON_EN_KILLFOCUS(IDC_EDIT1, OnKillfocusEdit1)
ON_EN_KILLFOCUS(IDC_EDIT2, OnKillfocusEdit2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDialog message handlers
void CMyDialog::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
((CSpinButtonCtrl*)GetDlgItem(IDC_SPIN2))->SetRange(0,100);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CMyDialog::OnSetfocusEdit1()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_SPIN1)->EnableWindow(TRUE);
m_pWnd = GetFocus();
m_mySpinCtrl.SetBuddy(m_pWnd);
m_mySpinCtrl.SetRange(0,23);
// GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
}
void CMyDialog::OnSetfocusEdit2()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_SPIN1)->EnableWindow(TRUE);
m_pWnd = GetFocus();
m_mySpinCtrl.SetBuddy(m_pWnd);
m_mySpinCtrl.SetRange(0,59);
// GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
}
void CMyDialog::OnKillfocusEdit1()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
}
void CMyDialog::OnKillfocusEdit2()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
}
#6
楼上说的不是我所要求的
#7
你应该在Dialog1::OinitDialog()中写入代码。
m_Spin.SetRange32(0,100000);
m_Spin.SetRange32(0,100000);
#8
因为你创建了Dialog2的实例的时候:CDialog2 dlg;其成员控件CDialog2.m_Spin并未创建,所以这样的调用是无效的。
应该在CDialog2添加两个成员变量:int m_low, m_up;然后在OnPost()中:
CDialog2 dlg;
dlg.m_low = 0;
dlg.m_up = 100000;
在CDialog2::OnInitDialgo()中:(此时其成员控件变量m_Spin是有效的了,并且m_low和m_up由调用的程序赋值)
m_Spin.SetRange32(m_low, m_up);
应该在CDialog2添加两个成员变量:int m_low, m_up;然后在OnPost()中:
CDialog2 dlg;
dlg.m_low = 0;
dlg.m_up = 100000;
在CDialog2::OnInitDialgo()中:(此时其成员控件变量m_Spin是有效的了,并且m_low和m_up由调用的程序赋值)
m_Spin.SetRange32(m_low, m_up);
#9
static成员设一下吧,不过要保证IsWindow