<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="author" content="zafir anjum">
<title>mfc programmer's sourcebook : advanced ui</title>
<meta name="description" content="source code for implementing advanced ui features">
<meta name="keywords" content>
</head>
<body background="../di2001.jpg"
tppabs="http://www.codeguru.com/fancyhome/back.gif" bgcolor="#ffffff">
<h3 align="center"><font color="#aoao99">outlook style ui </font></h3>
<hr>
<!-- author and contact details -->
<p>this article was contributed by <a href="mailto:kstowell@codejockeys.com">kirk stowell</a>.</p>
<!-- start of article -->
<h2>outlook style ui</h2>
<p><!-- the 'p' starts a paragraph of normal text --> this project uses the cj60 mfc extension library. for more information about this
library see <a href="demo_ui_mfcxlib.shtml.htm"
tppabs="http://www.codeguru.com/advancedui/demo_ui_mfcxlib.shtml">mfc extension library -
cj60lib ( updated for visual c++ 6.0 )</a>.</p>
<p><img src="demo_outlook.gif"
tppabs="http://www.codeguru.com/advancedui/demo_outlook.gif" width="768" height="329"> </p>
<p>first, create a sdi project with the class wizard. next, use class wizard to add three
classes to your project, <b>cleftview</b> (derived from <b>ctreeview</b>), <b>crightview</b>
(derived from <b>clistview</b>) and <b>clistmenuview</b> (derived from <b>cview</b>). in
cmainframe, add these two members to the attributes portion of the header file,
ccjcombobox is the flat combo box control, for a detailed implementation of this class,
see the article <a href="../combobox/flat_combobox.shtml.htm"
tppabs="http://www.codeguru.com/combobox/flat_combobox.shtml">flat combo box example</a>.</p>
<!-- start a block of source code -->
<pre><font color="#990000"><tt>
// attributes
public:
ccjcombobox* m_combo;
csplitterwnd m_wndsplitter;
<!-- end the block of source code -->
</pre>
</tt></font>
<p>your <b>oncreate</b> method in the main frame cpp file should look something like this,
make sure you derive <b>cmainframe</b> from <b>ccjframewnd</b>, change <b>ctoolbar</b> to <b>ccjtoolbar</b>
in the header file, call <b>installcoolmenus()</b> to use the flat toolbars and cool
menus:</p>
<!-- start a block of source code -->
<pre><font color="#990000"><tt>
int cmainframe::oncreate(lpcreatestruct lpcreatestruct)
{
if (cframewnd::oncreate(lpcreatestruct) == -1)
return -1;
if (!m_wndtoolbar.create(this) ||
!m_wndtoolbar.loadtoolbar(idr_mainframe))
{
trace0("failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndstatusbar.create(this) ||
!m_wndstatusbar.setindicators(indicators,
sizeof(indicators)/sizeof(uint)))
{
trace0("failed to create status bar\n");
return -1; // fail to create
}
// todo: remove this if you don't want tool tips or a resizeable toolbar
m_wndtoolbar.setbarstyle(m_wndtoolbar.getbarstyle() |
cbrs_tooltips | cbrs_flyby | cbrs_size_dynamic);
// todo: delete these three lines if you don't want the toolbar to
// be dockable
m_wndtoolbar.enabledocking(cbrs_align_any);
enabledocking(cbrs_align_any);
dockcontrolbar(&m_wndtoolbar);
// add a drop down to button
m_wndtoolbar.setbuttondropdown( idc_static_drop );
// insert the ccjcombobox control
m_combo = (ccjcombobox*)m_wndtoolbar.insertcontrol(
runtime_class(ccjcombobox), _t(""), crect(-165,-200,0,0), idc_combo,
ws_child | cbs_dropdownlist | cbs_autohscroll | ws_vscroll | cbs_hasstrings );
m_combo->addstring("messages with autopreview");
m_combo->setcursel(0);
// install cool menus.
installcoolmenus((cframewnd*)this, idr_mainframe);
return 0;
}
<!-- end the block of source code -->
</pre>
</tt></font>
<p>use visual studio to insert the splitter bar component, and change the <b>oncreate()</b>
method in your <b>cmainframe</b> that was added, to look something like this, the second
pane that is inserted will contain the left and right views:</p>
<!-- start a block of source code -->
<pre><font color="#990000"><tt>
bool cmainframe::oncreateclient(lpcreatestruct lpcs, ccreatecontext* pcontext)
{
// create the splitter window with two columns
if (!m_wndsplitter.createstatic(this, 1, 2))
{
trace0("failed to create splitter window\n");
return false;
}
// "outlook" view first
if (!m_wndsplitter.createview(0, 0, runtime_class(clistmenuview),
csize(100, 0), pcontext))
{
trace0("failed to create clistmenuview\n");
return false;
}
// "flexible pane": the second pane may present its own
// splitter windows.
if (!m_wndsplitter.createview(0, 1, runtime_class(cdemo_outlookview),
csize(0, 0), pcontext))
{
trace0("failed to create cdemo_outlookview\n");
return false;
}
// set the active view
setactiveview((cview*) m_wndsplitter.getpane(0, 0));
return true;
}
<!-- end the block of source code -->
</pre>
</tt></font>
<p>in the <b>cdemo_outlookview</b> class, use class wizard to add <b>oncreate</b> and <b>onsize</b>,
and add the following code to these two methods, this will create the two right panes that
contain the tree and list control views. include the header file for <b>crightview</b> and
<b>cleftview</b>, and add a member variable to the header file for the splitter <b>csplitterwnd
m_wndsplitter;</b></p>
<!-- start a block of source code -->
<pre><font color="#990000"><tt>
int cdemo_outlookview::oncreate(lpcreatestruct lpcreatestruct)
{
if (cview::oncreate(lpcreatestruct) == -1)
return -1;
// cpanecontainerview is used to control the right pane that cmainframe
// sets up. in this case we create a second splitter window.
m_wndsplitter.createstatic(this, 1,2);
// the context information is passed on from the framework
ccreatecontext *pcontext = (ccreatecontext*)lpcreatestruct->lpcreateparams;
// create two views
if (!m_wndsplitter.createview(0,0,runtime_class(cleftview),
csize(175,0), pcontext))
{
trace0("failed to create cleftview\n");
return -1;
}
if (!m_wndsplitter.createview(0,1,runtime_class(crightview),
csize(0,0), pcontext))
{
trace0("failed to create crightview\n");
return -1;
}
return 0;
}
void cdemo_outlookview::onsize(uint ntype, int cx, int cy)
{
cview::onsize(ntype, cx, cy);
m_wndsplitter.movewindow(-2,-2,cx+4,cy+4);
}
<!-- end the block of source code -->
</pre>
</tt></font>
<p>in the <b>clistmenuview</b> class, use class wizard to add <b>oncreate()</b> and <b>onsize</b>.
you will also need to add <b>onoutbarnotify()</b> by hand, to handle messages from the <b>ccjoutlookbar</b>
control. in the header file, you will need to define an object for the outlook bar
control, and one for the pager control. the pager will contain the outlook bar control,
and give us the up/down pager arrows to scroll the outlook bar control. for a detailed
implementation of the ccjpagerctrl class, see the article <a
href="../controls/pagerdemo.shtml.htm"
tppabs="http://www.codeguru.com/controls/pagerdemo.shtml">pager control example</a>.</p>
<!-- start a block of source code -->
<pre><font color="#990000"><tt>
// attributes
public:
ccjoutlookbar m_outbar;
ccjpagerctrl m_pager;
cfont m_font;
crect m_prect;
<!-- end the block of source code -->
</pre>
</tt></font>
<p>you will need to add <b>ccontentitems</b> class array that contains the index value and
text for the menu buttons to the cpp file. your <b>clistmenu
- 1
- 2
前往页