mfc组合框问题

征天 2013-12-04 04:40:48
在mfc tab控件中使用多个组合框编程中,发现组合框只能在钱三个选项卡中正常使用,后面的选项卡则不能正常使用,只能将组合框ID改成前三个选项卡中的一个特定ID才行,下面一张图片是第四个选项卡中的ID是第三个组合框的,该问题如何解决?
...全文
170 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
schlafenhamster 2013-12-05
  • 打赏
  • 举报
回复
CProp 本身 是 对话框, 在 OnInitDialog() 中处理
征天 2013-12-05
  • 打赏
  • 举报
回复
OnButton2中的ID应该是IDC_COMBO2,不过这个不是影响因素,只是贴代码时候贴错了应该贴OnButton1的就行了。
征天 2013-12-05
  • 打赏
  • 举报
回复
BOOL CMy20Dlg::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
	
	// TODO: Add extra initialization here
	CTabCtrl* pTab=(CTabCtrl*)GetDlgItem(IDC_TAB1);

	pTab->InsertItem(0,"Tab Page1");
	pTab->InsertItem(1,"Tab Page2");
	pTab->InsertItem(2,"Tab Page3");
	pTab->InsertItem(3,"Tab Page4");

	prop1.Create(IDD_PROP1,GetDlgItem(IDC_TAB1));
	prop2.Create(IDD_PROP2,GetDlgItem(IDC_TAB1));
	prop3.Create(IDD_PROP3,GetDlgItem(IDC_TAB1));
	prop4.Create(IDD_PROP4,GetDlgItem(IDC_TAB1));

	RECT rect;
	pTab->GetClientRect(&rect);
	rect.top+=30;
	rect.left+=5;
	rect.right-=5;
	rect.bottom-=5;
	prop1.MoveWindow(&rect);
	prop2.MoveWindow(&rect);
	prop3.MoveWindow(&rect);
	prop4.MoveWindow(&rect);
	prop1.ShowWindow(SW_SHOW);
	prop2.ShowWindow(SW_HIDE);
	prop3.ShowWindow(SW_HIDE);
	prop4.ShowWindow(SW_HIDE);

	pTab->SetCurSel(0);


	prop1.EnableWindow();
	prop2.EnableWindow();
	prop3.EnableWindow();
	prop4.EnableWindow();


	return TRUE;  // return TRUE  unless you set the focus to a control
}
void CMy20Dlg::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult) 
{



	// TODO: Add your control notification handler code here
	int n=((CTabCtrl*)GetDlgItem(IDC_TAB1))->GetCurSel();
	
	if (n==0)
	{
		

		prop1.ShowWindow(SW_SHOW);
		prop2.ShowWindow(SW_HIDE);
		prop3.ShowWindow(SW_HIDE);
		prop4.ShowWindow(SW_HIDE);
		
	}
	else if (n==1)
	{
		prop1.ShowWindow(SW_HIDE);
		prop2.ShowWindow(SW_SHOW);
		prop3.ShowWindow(SW_HIDE);
		prop4.ShowWindow(SW_HIDE);
	}
	else if(n==2)
	{
		prop1.ShowWindow(SW_HIDE);
		prop2.ShowWindow(SW_HIDE);
		prop3.ShowWindow(SW_SHOW);
		prop4.ShowWindow(SW_HIDE);
	}
	else
	{
		prop1.ShowWindow(SW_HIDE);
		prop2.ShowWindow(SW_HIDE);
		prop3.ShowWindow(SW_HIDE);
		prop4.ShowWindow(SW_SHOW);
	}



	*pResult = 0;
}
在下面函数中写代码则出现以上错误,不知应该在哪里添加
void CProp1::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CProp1)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP

	
	
	
	((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString("1");
	((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString("3");
	((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString("4");
	((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString("6");
	((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString("6");
	((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString("3");
	((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString("2");
	((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString("4");
	((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString("6");
	
	((CComboBox*)GetDlgItem(IDC_COMBO2))->SetCurSel(0);

}
void CProp1::OnButton2() 
{
	// TODO: Add your control notification handler code here
	CString m_strTiangan;
	int index2;
	CString x,z;
	//	CString a=+
	index2=((CComboBox*)GetDlgItem(IDC_COMBO1))->GetCurSel();
	((CComboBox*)GetDlgItem(IDC_COMBO1))->GetLBText(index2,m_strTiangan);
	x=m_strTiangan;
	//	MessageBox(x);
	z=x;
	
	if (z.Compare("2")==0)
	{
		SetDlgItemText(IDC_EDIT1,"冬月初二初三初四初五初六初七初八初九初十");
	}
}
前面3个选项卡还可以使用但是后面的选项卡就出现问题了。
yuwujian 2013-12-05
  • 打赏
  • 举报
回复
你可以贴代码看看
征天 2013-12-05
  • 打赏
  • 举报
回复
非常感谢,坑爹啊,这个竟然没注意到。
凌乱哥 2013-12-05
  • 打赏
  • 举报
回复
找到原因了,楼主的20Dlg.h中:

	CProp1 prop1;
	CProp2 prop2;
	CProp3 prop3;
	CProp3 prop4;
凌乱哥 2013-12-05
  • 打赏
  • 举报
回复
楼主的BOOL CProp4::OnInitDialog()根本没进去。。。很诡异啊
征天 2013-12-05
  • 打赏
  • 举报
回复
代码http://pan.baidu.com/s/11SmHN注:CProp10,CProp20,CProp30没用。
yuwujian 2013-12-05
  • 打赏
  • 举报
回复
把四个tab的页面用同一个试试,
prop1.Create(IDD_PROP1,GetDlgItem(IDC_TAB1));
prop2.Create(IDD_PROP1,GetDlgItem(IDC_TAB1));
prop3.Create(IDD_PROP1,GetDlgItem(IDC_TAB1));
prop4.Create(IDD_PROP1,GetDlgItem(IDC_TAB1));
凌乱哥 2013-12-05
  • 打赏
  • 举报
回复
整个工程传上来好了
征天 2013-12-05
  • 打赏
  • 举报
回复
试过在OnInitDialog() 中处理,仍然不能解决
征天 2013-12-04
  • 打赏
  • 举报
回复
这个可能是在tab控件中,在OnInitDialog中不行,控件id全部改过,删除重新添加也试了不行
zxx178239 2013-12-04
  • 打赏
  • 举报
回复
正确操作就应该在OnInitDialog里面添加那些命令,LZ看一下你的控件ID对否,不行的话删除控件重新拖个试下 至于你说的那种限制不可能有吧!可能是你其他地方操作出现错误了
征天 2013-12-04
  • 打赏
  • 举报
回复
,combobox中内容显示不出来,在OnInitDialog中处理试过了不行,不能在combobox中显示内容,在CProp4::DoDataExchange(CDataExchange* pDX)这个中可以显示,但是出现了上面的情况。
yuwujian 2013-12-04
  • 打赏
  • 举报
回复
可以放OnInitDialog中处理。
lz是combobox显示不出来,还是combobox中的内容显示不出来
征天 2013-12-04
  • 打赏
  • 举报
回复
就是因为不会,自己随便在一个函数中加的,前三个可以后面的就不行了,问一下tab控件选项卡中控件应该在哪个函数中处理。
快乐鹦鹉 2013-12-04
  • 打赏
  • 举报
回复
第一次见到在这个函数里加这种处理的......
征天 2013-12-04
  • 打赏
  • 举报
回复
可能是吧,不知道怎么更改,怎么不能把文件发到帖子上,
void CProp4::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CProp4)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP

	((CComboBox*)GetDlgItem(IDC_COMBO4))->AddString("4");
	((CComboBox*)GetDlgItem(IDC_COMBO4))->AddString("5");
	((CComboBox*)GetDlgItem(IDC_COMBO4))->AddString("6");
	((CComboBox*)GetDlgItem(IDC_COMBO4))->AddString("7");
	((CComboBox*)GetDlgItem(IDC_COMBO4))->AddString("8");
	((CComboBox*)GetDlgItem(IDC_COMBO4))->AddString("5");
	((CComboBox*)GetDlgItem(IDC_COMBO4))->AddString("7");
	((CComboBox*)GetDlgItem(IDC_COMBO4))->AddString("8");
	((CComboBox*)GetDlgItem(IDC_COMBO4))->AddString("2");
	
	((CComboBox*)GetDlgItem(IDC_COMBO4))->SetCurSel(0);
}
前面三处代码都是这样写的没有任何问题,但是只要到第四个就出现问题,已经试过几次都出现这样的问题。
快乐鹦鹉 2013-12-04
  • 打赏
  • 举报
回复
没听说过有这种限制。此种状况基本上是人为造成的

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧