别人的一个问题,大家来讨论讨论!

sxbyl 2001-01-14 02:57:00
最近脑子里一团浆糊,这个问题在浆糊里搅了几圈每搅出个好的解决方法,大家帮忙看看,好的解决方案大分送上。(因为结果不可预知,所以加分在结账的时候进行),问题如下:


主要是CTabCtrl控件的使用问题,可能很傻?
下面这一段摘自msdn:
A "tab control" is analogous to the dividers in a notebook or the label is a file cabinet ,
by using a tab control, an application can define multiple pages for the saem area o a window
or dialog box, Each page consist of a set of information of a group of controls that the application
displays when the user selects the corresponding tab, A special type of Tab control idsplay tabs
that look like buttons, clicking a button should immediately perorm a command instead of displaying
a page.
the CTabCtrl class provides the functionity of the windows common tab control.
总的来说,就是实现很多windows程序中的属性对话框的问题,属性对话框在vc中编程时,用到CPropertyPage
& CPropertySheet,并提供“确认”,“取消”,“应用”按纽。
我现在在CFormView中使用CTabCtrl控件,由于我的客户区被分成左右部分(右边用来绘制矢量图 CView)
CFormView被放在客户区左边。
可怕的是在CFormView中要放置>120个以上的控件,如果分成6页来实现将是比较可以的(还有别的办法吗?)
遇到这样的问题想到CTabCtrl控件是可以理解的,VC++中的Project--setting 就是这样的应用。
在dephi中,可以在设计阶段选择CTabCtrl(是这个名字吗?)的不同页面来设计各自的界面,但vc中不行,
好象vb中也不行,而很多vc的资料中讲CTabCtrl控件的用法时,提供了如下方法:
1:映射CTabCtrl控件的TCN_SELCHANGE(TCN_SELCHANGING?)消息事件,
2:在其中调用GetCurSel()函数确定控件的哪一页获的焦点。
如下:
void CXXXView::OnSelchangeXXX(NMHDR* pNMHDR,LRESULT* pResult)
{
Switch(GetCurSel())
{
case 页面一:
页面一的处理代码;
case 页面二:
....
}
}


下面是页面一处理代码的示例:
#define SIZEOF_ARRAY(a) (sizeof(a)/sizeof(a[0]))
{
static UINT aGroup1[]={DLG_CHBOX1,DLG_CHBOX2,DLG_CHBOX3,....}
static UINT aGroup2[]={DLG_LABEL2,DLG_LABLE7,...}
ShowControls(aGroup1,SIZEOF_ARRAY(aGroup1),TRUE);
ShowControls(aGroup2,SIZEOF_ARRAY(aGroup2),FALSE);
}

void CXXXView::ShowControls(UINT* pControls,UINT cControls,BOOL fVisible)
{
for(UINT nIndex=0;nIndex<cControls,nIndex++)
{
CWnd* pwnd=GetDlgItem(pControls[nIndex]);
if(pwnd)
{
pwnd->ShowWindow(fVisible?SW_SHOW:SW_HIDE);
pwnd->EnableWindow(fvisible);
}
}
}

在处理其他事件。
这样做导致的结果是,在CFormView中我必须放6组以上的控件(每组>20个),并且得堆着放?
天哪?如果我要修改,我该怎么办?
有更好的办法吗?
...全文
299 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
leemuxiang 2001-01-20
  • 打赏
  • 举报
回复
thank you masterz.
i will try & write to you .
请高手们参与讨论!
masterz 2001-01-18
  • 打赏
  • 举报
回复
codeguru 上的资料,我按照这个用成功过tab control
To handle a tab control try this code:
You must derived a class from CTabCtrl, then in this class add a member variable like this one

CDialog *m_pages[n]//Where n is the number of pages you need


Then in resource editor insert n dialogs, generate the classes for them (e.g. CPage1, CPage2, etc). Attention the base class must be CDialog.
Obs: In the properties of dialog you must set at styles:Child, Border-none, and uncheck Title Bar
In the class CMyTabCtrl insert this function:



CMyTabCtrl::CMyTabCtrl()
{
m_dial[0] = new CPage1;
m_dial[1] = new CPage2;
m_dial[2] = new CPage3;
m_dial[3] = new CPage4;
m_dial[4] = new CPage5;
m_dial[5] = new CPage6;
}
void CMyTabCtrl::Init()
{
m_curent = 0; //curent page
/////////////////////////////////////
//modeless dialog
////////////////////////////////////
m_dial[0]->Create(IDD_DIALOG1, this);
m_dial[1]->Create(IDD_DIALOG2, this);
m_dial[2]->Create(IDD_DIALOG3, this);
m_dial[3]->Create(IDD_DIALOG4, this);
m_dial[4]->Create(IDD_DIALOG5, this);
m_dial[5]->Create(IDD_DIALOG6, this);
m_dial[0]->ShowWindow( SW_SHOW );
m_dial[1]->ShowWindow( SW_HIDE );
m_dial[2]->ShowWindow( SW_HIDE );
m_dial[3]->ShowWindow( SW_HIDE );
m_dial[4]->ShowWindow( SW_HIDE );
m_dial[5]->ShowWindow( SW_HIDE );
SetRectangle();//set rectangle for dialogs to tab rectangle
}

void CMyTabCtrl::SetRectangle()
{
CRect tabrect, itemrect;
int x, y, cx, cy;
GetClientRect( &tabrect );
GetItemRect( 0, &itemrect);
x = itemrect.left;
y = itemrect.bottom + 1;
cy = tabrect.bottom - y - 1;
cx = tabrect.right - itemrect.left - 1;
m_dial[0]->SetWindowPos( &wndTop, x, y, cx, cy, SWP_SHOWWINDOW);//show first page
for(int i = 1; i < 6; i++)
{
m_dial->SetWindowPos( &wndTop, x, y, cx, cy, SWP_HIDEWINDOW);//hide the rest pages
}
}

void CMyTabCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
CTabCtrl::OnLButtonDown(nFlags, point);
if( m_curent != GetCurFocus() )
{
m_dial[m_curent]->ShowWindow( SW_HIDE );
m_curent = GetCurFocus();
m_dial[m_curent]->ShowWindow( SW_SHOW );
m_dial[m_curent]->SetFocus();
}
}



Let me know if this help u

Regards,
Ovidiu

=====================================
文章2
SubjectRe: I use modeless dialogs for each page.

I do it a bit differently, although I still use modeless dialogs:
(If anyone knows a better way, I'd love to know about it)

When the dialogs are contructed, I simply pass a pointer to the tab
control as the parent window. By fiddling with the dialog offsets in
the resource editor, you can center the child dialogs as you like.
Here's the function I use to change dialogs:


void CParentDlg::OnSelchangeMaintab(NMHDR* pNMHDR, LRESULT* pResult)
{ int nTab = m_mainTab.GetCurSel();
m_pCurTabDlg->ShowWindow(SW_HIDE);
switch(nTab)
{
case 0:
m_pIncludeDlg->ShowWindow(SW_SHOW);
m_pCurTabDlg = (CDialog*)m_pIncludeDlg;
break;
case 1:
m_pExcludeDlg->ShowWindow(SW_SHOW);
m_pCurTabDlg =(CDialog*)m_pExcludeDlg;
break;
case 2:
m_pDestDlg->ShowWindow(SW_SHOW);
m_pCurTabDlg = (CDialog*)m_pDestDlg;
break;
}
*pResult = 0;
}

The variable types should be fairly obvious. Also, I found it
necessary to override OnCommand, otherwise the user would be able to
close the modeless dialogs by pressing enter when focus was on a
control:


BOOL CIncludeDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{ if (wParam & 0xff00)
return CDialog::OnCommand(wParam, lParam);
else
return(TRUE);
}

leemuxiang 2001-01-18
  • 打赏
  • 举报
回复
望高手指点!急。
leemuxiang 2001-01-18
  • 打赏
  • 举报
回复
不知道有没有人用过CJLibrary,BCGContrlbar等容器,大致就是WorkSpace之类的东东!在其给出的示例中,用的视为CTreeView,我按照示例程序的写法,添加了一个CFormView视类结果出现泄露,另外一个问题是,示例是在CMainFrame中绑定的视,例如:m_wndTabCtrl.Adding(CFormView)...(实际程序好象不是这样的!),这令我很为难,因为我的程序分为很多子功能,并且子功能不能同时运行,因为是控制下位机(的功放)。而每一个子功能的界面都需要分页(界面控件元素太多!)?因此我不可能把所需的页面都绑定在CMainFrame中,如何是好?
我说清楚了吗?不清楚可以发问?qq:41764381。
laoyong 2001-01-17
  • 打赏
  • 举报
回复
to black_ax:
对不起!昨天网吧老板突然下线关门,未能say bye!
jiujiejushi 2001-01-17
  • 打赏
  • 举报
回复
强烈关注。

还好我的tab中一页只有一个控件,我是先分开放置,然后在程序中移动tab到指定位置,然后取得tab客户区,再把控件移动过去,很费劲呀。
ax_7 2001-01-16
  • 打赏
  • 举报
回复
界面問題:在變成高手錢都遇到過這個問題,關注。
leemuxiang 2001-01-16
  • 打赏
  • 举报
回复
大家好!我是这个问题的提出者。
to:sxbyl。谢谢你。
to:masterz()。
我也想过把每一页做成无模式对话框,然后在CTabCtrl中的页面切换时,动态处理对话框,但不知如何处理。望指点。
后来仔细一想,在vc++6中WorkSpace(主界面中左边的部分)一样,可以管理类,资源,以及文件,但我如何做了,看过这方面的例子,但用到自己的程序中无把握。还望高手指点。
先谢了。
patient 2001-01-15
  • 打赏
  • 举报
回复
你是不是要做个autocad那样的东西?如果是可以参考它的做法,
或更好的是参考photoshp的。
masterz 2001-01-14
  • 打赏
  • 举报
回复
为CTabCtrl设计几个modelless dialog,加到tab control 上。不是把所有control加在同一个form上。
sxbyl 2001-01-14
  • 打赏
  • 举报
回复
但我想他的意思是如何简单有效的管理一大堆控件,因为他也提到CPropertySheet和CPropertyPage了,应该知道这两个东西的使用。
bugn 2001-01-14
  • 打赏
  • 举报
回复
用Property Sheets,参看CPropertySheet, CPropertyPage;每个页面设计单独的对话框,很方便的。

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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