如何设置CListCtrl的Focus

QJW 2000-03-01 10:14:00
我想在Dialog开始时将光标放在CListCtrl中的第某项,使用GetItem可以得到光标当前的位置,但用SetItem似乎不起作用,请教各位应当怎样做?
...全文
227 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
QJW 2000-03-03
  • 打赏
  • 举报
回复
LVITEM lvitem;
ZeroMemory(&lvitem, sizeof(lvitem));
lvitem.stateMask = LVIS_FOCUSED;
lvitem.mask = LVIF_STATE;
for (int i = 0; i < GetItemCount(); i++)
{
lvitem.iItem = i;
GetItem(&lvitem);
if (lvitem.state)
break;
}
int j = i;
for (;i < GetItemCount(); i++)
{
if (!strnicmp(str, GetItemText(i, 0), strlen(str)))
{
SetItemState(j, 0, LVIF_STATE);
SetItemState(i, LVIS_FOCUSED and LVIS_SELECTED, LVIF_STATE);
break;
}
}

Jackzhu 2000-03-03
  • 打赏
  • 举报
回复
你怎么用的SetItem()
QJW 2000-03-03
  • 打赏
  • 举报
回复
用SetItemState()光标总是回到第一项,似乎还是不行。
michel 2000-03-03
  • 打赏
  • 举报
回复
使用SetItemState()函数, 第一个参数(whichitem) 就是你所想光标放在CListCtrl中的第几项
SetItemState(whichitem, LVIS_SELECTED and LVIS_FOCUSED, LVIS_SELECTED and LVIS_FOCUSED );
Jackzhu 2000-03-03
  • 打赏
  • 举报
回复

CListCtrl::SetItem(1, 0, LVIF_STATE, 0, 0,
LVIS_FOCUSED and LVIS_SELECTED, LVIS_FOCUSED and LVIS_SELECTED, 0)
设置状态可以
Jackzhu 2000-03-01
  • 打赏
  • 举报
回复
用CListCtrl::SetItemState()设置项目状态
1,01.zip
Toolbar - Custom status messages and tooltips
用户状态信息与工具提示(3KB)
2,02.zip
Remove system menu from floating toolbar
从浮动工具条中去除系统菜单(2KB)
3,03.zip
Remove close button from floating toolbar
从浮动工具条中去掉关闭按钮(2KB)
4,customizable1.zip
Customizable toolbar
可自定义的工具条(25KB)
5,detoolbar.zip
Adding a drop arrow to a toolbar button
带下拉框的工具条(28KB)
6,detoolbare.zip
Using Hot Toolbar Buttons
类似IE4的工具条(30KB)
7,BCGControlBar.zip
Customizable Toolbar and Menus
可自定义的工具条 (2)(318KB)
8,FixMiniFrame.zip
System menu fix for floating toolbar
更改浮动工具条中的系统菜单(24KB)
9,09.zip
DevStudio like Flat Toolbar
平面工具条 (需 IE3+)(5KB)
10,enh_flatbar.zip
Another Flat ToolBar (does not require MSIE)
另外一种平面工具条 (不需 IE)(81KB)
11,VSOMenu.zip
Visual Studio/Office 97 style Flat Toolbar and Dockable Menu bar
类似Visual Studio/Office 97 的平面工具条与可停靠菜单条(2)(200KB)
12,RebarMenu.zip
IE4 Style Menu (Rebar Menu)
类似IE4 的菜单条(72KB)
13,ToolbarHi.zip
Toolbar with 16M colour images
使用16M色图象的工具条(66KB)
14,multi12.zip
Extended Multi Size Multi Color Toolbar!
扩展型多尺寸多色彩工具条(226KB)
15,15.zip
How to display tooltips for a toolbar in a dialog
在对话框如何为工具条显示工具提示(3KB)
16,16.zip
Displaying text on a Toolbar
在对话框如何为工具条显示工具提示(2KB)
17,toolbar_d.zip
Docking Toolbars Side-By-Side
工具条的停靠(29KB)
18,toolbars.zip
Toolbars with Tooltips in a CFormView derived class
在CFormView派生类中使用带工具提示的工具条(29KB)
19,SwitchTB.zip
Switching Toolbars in MDI
MDI中具有开关显示功能的工具条(47KB)
20,Place Controls on ToolBars
在工具条中放置其他控件(10KB)
21,DialogBarEx1.zip
CDialogBarEx : A Dialog bar with initialization
CDialogBarEx :带初始化的对话条(42KB)

1,01.zip
Setting selected text to read-only
设置选择的文本为只读(2KB)
2,02.zip
Changing word wrap mode
改变换行模式(2KB)
3,03.zip
Changing tab stops
改变tab的行数(2KB)
4,04.zip
Inserting an RTF string using StreamIn
用RTF插入一个RTF字符串(3KB)
5,05.zip
Providing a Format toolbar
提供一个格式的工具框(8KB)
6,06.zip
convert RTF String RTF tags
变换字符串为RTF格式(7KB)
7,07.zip
CRichEditCtrlEx - Advanced Rich Edit Control
CRichEdit的继承类(21KB)
8,08.zip
The Richedit Ctrl used in chatting
在聊天程序中用Richedit(37KB)
9,09.zip
CRichEditCtrlEx : Replacing "RICHEDIT" control with "RichEdit20A"
替代RichEdit的类CRichEditCtrlEx(16KB)
10,10.zip
Controlling the RichTextCtrl Insert State
控制RichTextCtrl中Insert键状态(80KB)
11,11.zip
CAutoRichEditCtrl - automate rich edit formatting and RTF handling.
自动格式化RTF的继承类CAutoRichEditCtrl(62KB)

1,02.zip
Adding a Control to the Property Sheet
在属性页中添加控件(2KB)
2,06.zip
Using Shortcut Keys for Property Pages
在属性页中使用快捷键(2KB)
3,07.zip
Creating a Property Sheet Inside a Form View - Asaf Levy
在Form View中创建属性页(4KB)
4,08.zip
Creating a Property Sheet Inside a Dialog
在对话框中创建属性页(3KB)
12,18.zip
A resizable property sheet within a view
在视中改变property sheet的大小(4KB)
13,19.zip
overriding the default buttons on CPropertySheets
在CPropertySheets中覆盖默认按钮(2KB)
14,20.zip
Display only One Row of Tabs
只显示一行Tab选择(2KB)
15,21.zip
Add a Font Property Page
添加字体属性页(16KB)
16,22.zip
Resizing the Property Sheet
改变属性页的大小(2KB)
17,23.zip
Resizing the Tab Control
改变Tab控制的大小(2KB)
18,24.zip
Moving and Resizing the Property Pages
移动并改变属性页大小(3KB)
20,27.zip
Using ON_UPDATE_COMMAND_UI in Property Pages
在属性页中使用ON_UPDATE_COMMAND_UI(2KB)
22,29.zip
Inserting a CFormView into a CPropertySheet
将CFormView插入到属性页中(2KB)
23,30.zip
Using Upper- and Lowercase shortcut Keys for Property Pages
在属性页中使用大写和小写快捷键(2KB)
25,32.zip
Automaticaly arange visible controls below the tab control
TAB控制中使控件自动可见(2KB)
27,34.zip
Creating a wizard
创建一个向导(4KB)
21,propsheet1.zip
Propertysheets embedded in Dialogs
在对话框中嵌入Propertysheets(20KB)
24,propinprop.zip
Using shortcut keys in property pages containg property pages
在属性页中使用快捷键(74KB)
26,newprop.zip
Adding a Button to CPropertySheet
在属性页中添加按钮(19KB)
28,PropSheet.zip
Property Sheet Wizard
属性页Wizard(96KB)<96KB>
5,wizprop.zip
Wizard Property Sheets and Pages
Wizard方式的属性表与属性页(3KB)
6,creatingl.zip
Creating a full application using the CPropertySheet.
用CPropertySheet创建完整的应用程序(91KB)
7,updcreate.zip
Creating a full application using the CPropertySheet
更新: 用CPropertySheet创建完整的应用程序(12KB)
8,addbitmap.zip
Placing A Bitmap In The PropertySheet Button Area
将一个位图放到PropertySheet的按纽区域(2KB)
9,add3dtext.zip
Placing a 3D Logo Text In the PropertySheet Button Area
附加功能是控制PropertySheet区域特别是按纽部分的颜色(37KB)
10,proppage.zip
Modifying Property Sheet Templates on Win95
在Win95中修改属性页模板(2KB)
11,propview.zip
Using a modeless property sheet as a 'view' in a Frame
使用非模式的property sheet, 就像框架中的视(53KB)

1,VCMenu.zip
Visual Studio/Office 97 style Flat Toolbar and Dockable Menu bar
类似Visual Studio/Office 97的平面工具条与可停靠菜单条(350KB)
2,contentmenu.zip
A Cool Looking Menu For Easier Navigation
一个很COOL的菜单条(39KB)
3,freemenu.zip
Owner Drawn Menu With Free Color & Font
可使用任意字体与颜色的自画式菜单(35KB)
4,04.zip
Owner Drawn Menu with Icons
带图标的自画式菜单(5KB)
5,05.zip
Owner Drawn Menu with Icons (2)
带图标的自画式菜单(2)(8KB)
6,owner_menu4.zip
Owner Drawn Menu with Icons (4) (automatically uses toolbar res)
带图标的自画式菜单(4) (自动使用工具条对应资源)(109KB)
7,bitmapmenu.zip
Yet another owner draw menu
更新"带图标的自画式菜单"(2)(6KB)
8,bcmenu24.zip
Owner Drawn Menu with Icons (3)
带图标的自画式菜单(3) (使用工具条资源)(62KB)
9,09.zip
Inserting submenus in an existing SDI menu
在SDI菜单中插入子菜单(2KB)
10,10.zip
TrackPopupMenu as an Immediate Function
使用 CMenu::TrackPopupMenu 跟踪弹出菜单的菜单项(2KB)
11,Creating Popup Menus with Titles
Creating Popup Menus with Titles
带提示的弹出式菜单(5KB)
12,12.zip
Finding a menu item position from command id
从Command ID中寻找菜单项(3KB)
13,13.zip
The simplest way to put the MRU list in a submenu
将MRU列表加入子菜单的简单途径(2KB)
14,14.zip
Using MRU on a submenu
在子菜单中使用MRU(3KB)
15,15.zip
MRU list in a submenu: the MFC bug and how to correct it.
子菜单中的MRU列表: 更正MFC bug(3KB)
16,16.zip
Merging Two Menus
合并两个菜单(3KB)

1,03.zip
Serializable CListCtrl with check sum verify(4KB)
连续的列表项的校验和
2,11.zip
Getting the number of columns in report view
获得列表视图的列数(2KB)
3,12.zip
添加一列
Adding a column(2KB)
4,13.zip
Detecting column index of the item clicked
监测单击项的索引(13KB)
5,14.zip
Prevent CListCtrl column resizing
禁止调整列表控制的大小(2KB)
6,16.zip
How to force a minimum column width
限定一个最小列宽(16KB)
7,17.zip
Autosize a column to fit its content
自动调整列的大小(3KB)
8,18.zip
Stationary Columns
固定的列数(4KB)
9,19.zip
Disable clicking on selected report view columns
禁止鼠标在列表视图单击(2KB)
10,21.zip
Dragging columns to rearrange column sequence
重新排列次序(6KB)
11,22.zip
Dragging Items to Rearrange Rows
重新排列行数(5KB)
12,24.zip
Allowing items to be edited
允许列表项编辑(2KB)
13,27.zip
Using a drop down list to change a subitem
用托放改变子项(10KB)
14,GridList.zip
Multiline Editable Subitems
多列可编辑的子项(95KB)
15,subitems2.zip
Editing listview subitems using LVM_GETEDITCONTROL
用LVM_GETEDITCONTROL事件来编辑列表视图(46KB)
16,32.zip
Drawing horizontal and vertical gridlines
画水平和竖直的网格线(9KB)
17,33.zip
List control with single / double separator lines
带有一个/两个分割线的列表控制(10KB)
18,34.zip
Subclassing the List View Control using MFC
用MFC写的列表视图子类(3KB)
19,35.zip
Catching header messages in a CListView
捕捉CListView的头消息(2KB)
20,36.zip
How do I use a derived CListCtrl with a CListView?
怎样使用来源于CListCtrl的列表视图(2KB)
21,40.zip
Using sub-strings in non report view
获得报表视图的子串(2KB)
22,Treelist.zip
TreeList : Multi column tree control
多列的树性列表控制(79KB)
23,43.zip
Connect a list container to a tree/list control
连接一个列表容器到列表控制(4KB)
24,listclass1.zip
Class with full row highlighting
高亮文本的列表框(8KB)
25,46.zip
IE4 Extended Styles in a list control
和IE4类似的列表控制(4KB)
26,sorted_Class.zip
CSortedListCtrl reusable base class
可以再度使用的排序列表基类(61KB)
27,48.zip
Measure Item for dynamic font changing in a list control
动态的改变列表控制的字体(2KB)
28,supergrid.zip
SuperGrid - Yet Another listview control(84KB)
用Listview写的网格控制
29,clistie4.zip
Class for using new features in listview control
列表视图的子类(5KB)
30,51.zip
Plug-in class to support printing from a listview
列表视图的插件类 (6KB)
31,52.zip
Print the contents of the list control
打印列表视图的内容(7KB)
32,property12.zip
Creating an Object Property List using the CListCtrl
ClistCtrl类创建一个属性列表(57KB)
33,56.zip
Retrieving selected items
找回选择的项的内容(2KB)
34,57.zip
Selecting and deselecting a range of rows
选择和反选择一定范围的行(2KB)
35,58.zip
Selection Highlighting of Entire Row
选择高亮整行(12KB)
36,59.zip
Set focus on a cell
设置一个单元获得焦点(2KB)
37,60.zip
Sorting the list based on text in any column
按列表的文本排序(3KB)
38,61.zip
Sorting list on Numeric Column
按列表的数值排序(2KB)
39,62.zip
Sort list based on text/numeric/date-time in any column
按列表的文本\数值\时间排序(3KB)
40,63.zip
Sort list (numeric/text) using callback
用回调函数按数值/文本排序 (3KB)
41,64.zip
Sort columns by the image index of the column
通过图像索引排序(3KB)
42,66.zip
Sorting the list when user clicks on column header
当用户单击列标题时排序(3KB)
43,67.zip
Indicating sort order in header control
指示列标题的排序(5KB)
44,68.zip
Simple list Sorting on Integer Colum
按列表的数值排序(2KB)
45,69.zip
A Multi Column Sort listview
一个多列排序的列表视图(37KB)
46,70.zip
Determining row indices in SortItems() Comparison function
用SortItems函数监测行复数(3KB)
47,75.zip
Handling Title Tips With Drag/Drop Headers Using The Visual C++ 6.0 CListCtrl
处理标题的提示(3KB)
48,76.zip
Attaching System ImageList to ListControl
附带系统图像的列表控制(3KB)
49,77.zip
Initializing the image list
初始化图像列表(2KB)
50,78.zip
Setting or removing an image for an item
设置和删除项中的图像(78KB)
51,79.zip
Setting a non-standard size image
设置一个非标准的图像(4KB)
52,83.zip
List Control displaying image thumbnails
在列表控制中显示小图像(23KB)
VC之美化界面篇 作者:白乔 链接:http://vcer.net/1046595482643.html 本文专题讨论VC中的界面美化,适用于具有中等VC水平的读者。读者最好具有以下VC基础: 1. 大致了解MFC框架的基本运作原理; 2. 熟悉Windows消息机制,熟悉MFC的消息映射和反射机制; 3. 熟悉OOP理论和技术; 本文根据笔者多年的开发经验,并结合简单的例子一一展开,希望对读者有所帮助。 1 美化界面之开题篇 相信使用过《金山毒霸》、《瑞星杀毒》软件的读者应该还记得它们的精美界面: 图1 瑞星杀毒软件的精美界面 程序的功能如何如何强大是一回事,它的用户界面则是另一回事。千万不要忽视程序的用户界面,因为它是给用户最初最直接的印象,丑陋的界面、不友好的风格肯定会影响用户对软件程序的使用。 “受之以鱼,不若授之以渔”,本教程并不会向你推荐《瑞星杀毒软件》精美界面的具体实现,而只是向你推荐一些常用的美化方法。 2 美化界面之基础篇 美化界面需要先熟悉Windows下的绘图操作,并明白Windows的幕后绘图操作,才能有的放矢,知道哪些可以使用,知道哪些可以避免…… 2.1 Windows下的绘图操作 熟悉DOS的读者可能就知道:DOS下面的图形操作很方便,进入图形模式,整个屏幕就是你的了,你希望在哪画个点,那个地方就会出现一个点,红的、或者黄的,随你的便。你也可以花点时间画个按钮,画个你自己的菜单,等等…… Windows本身就是图形界面,所以Windows下面的绘图操作功能更丰富、简单。要了解Windows下的绘图操作,要实现Windows界面的美化,就必须了解MFC封装的设备环境类和图形对象类。 2.1.1 设备环境类 Windows下的绘图操作说到底就是DC操作。DC(Device Context设备环境)对象是一个抽象的作图环境,可能是对应屏幕,也可能是对应打印机或其它。这个环境是设备无关的,所以你在对不同的设备输出时只需要使用不同的设备环境就行了,而作图方式可以完全不变。这也就是Windows的设备无关性。 MFC的CDC类封装了Windows API 中大部分的画图函数。CDC的常见操作函数包括: Drawing-Attribute Functions:绘图属性操作,如:设置透明模式 Mapping Functions:映射操作 Coordinate Functions:坐标操作 Clipping Functions:剪切操作 Line-Output Functions:画线操作 Simple Drawing Functions:简单绘图操作,如:绘制矩形框 Ellipse and Polygon Functions:椭圆/多边形操作 Text Functions:文字输出操作 Printer Escape Functions:打印操作 Scrolling Functions:滚动操作 *Bitmap Functions:位图操作 *Region Functions:区域操作 *Font Functions:字体操作 *Color and Color Palette Functions:颜色/调色板操作 其中,标注*项会用到相应的图形对象类,参见2.1.2内容。 2.1.2 图形对象类 设备环境不足以包含绘图功能所需的所有绘图特征,除了设备环境外, Windows还有其他一些图形对象用来储存绘图特征。这些附加的功能包括从画线的宽度和颜色到画文本时所用的字体。图形对象类封装了所有六个图形对象。 下面的表格列出了MFC的图形对象类: MFC类 图形对象句柄 图形对象目的 CBitmap HBITMAP 内存中的位图 CBrush HBRUSH 画刷特性—填充某个图形时所使用的颜色和模式 CFont HFONT 字体特性—写文本时所使用的字体 CPalette HPALETTE 调色板颜色 CPen HPEN 画笔特性—画轮廓时所使用的线的粗细 CRgn HRGN 区域特性—包括定义它的点 表1 图形对象类和它们封装的句柄 使用CDC和图形对象类,在Windows里绘图还算是很简单的。观察以下的画面: 图2 使用CDC绘制出的按钮 该画面通过以下代码自行绘制的假按钮: BOOL CUi1View::PreCreateWindow(CREATESTRUCT& cs) { //设置背景色 //CBrush CUi1View::m_Back m_Back.CreateSolidBrush(::GetSysColor(COLOR_3DFACE)); cs.lpszClass = AfxRegisterWndClass(0, 0, m_Back, NULL); return CView::PreCreateWindow(cs); } int CUi1View::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; //创建字体 //CFont CUi1View::m_Font m_Font.CreatePointFont(120, "Impact"); return 0; } void CUi1View::OnDraw(CDC* pDC) { //绘制按钮框架 pDC->DrawFrameControl(CRect(100, 100, 220, 160), DFC_BUTTON, DFCS_BUTTONPUSH); //输出文字 pDC->SetBkMode(TRANSPARENT); pDC->TextOut(120, 120, "Hello, CFan!"); } 呵呵,不好意思,这并不是真的Windows按钮,它只是一个假的空框子,当用户在按钮上点击鼠标时,放心,什么事情都不会发生。 2.2 Windows的幕后绘图操作 在Window中,如果所有的界面操作都由用户代码来实现,那将是一个很浩大的工程。笔者曾经在DOS设计过窗口图形界面,代码上千行,但实现的界面还是很古板、难看,除了我那个对编程一窍不通的女友,没有一个人欣赏它L;而且,更要命的是,操作系统,包括别的应用程序并不认识你的界面元素,这才是真正悲哀的。认识这些界面的只有你的程序,图2中的按钮永远只是一个无用的框子。 有了Windows,一切都好办了,Windows将诸如按钮、菜单、工具栏等等这些通用界面的绘制及动作都交给了系统,程序员就不用花心思再画那些按钮了,可以将更多的精力放在程序的功能实现方面。 所有的标准界面元素都被Windows封装好了。Windows知道怎么画你的菜单以及你的标注着“Hello, Cfan!”的按钮。当CFan某个快乐的小编(譬如:小飞)点击这个按钮的时候,Windows也明白按钮按下去的时候该有的模样,甚至,当这个友好的按钮获取焦点时,Windows也会不失时机地为它准备一个虚框…… 有利必有弊。你的不满这时候产生了:你既想使用Windows的True Button,可也嫌它的界面不够好看,譬如,你喜欢用蓝色的粗体表达你对CFan的无限情怀(正如图2那样)——人心不足,有办法吗?有的。 3 美化界面之实现篇 Windows还是给程序员留下了很多后门,通过一些途径还是可以美化界面的。本章节我们系统学习一下Windows界面美化的实现。 3.1 美化界面的途径 如何以合法的手段来达到美化界面的效果?一般美化界面的方法包括: 1. 使用MFC类的既有函数,设定界面属性; 2. 利用Windows的消息机制,截获有用的Windows的消息。通过MFC的消息映射(Message Mapping)和反射(Message Reflecting)机制,在Windows准备或者正在绘制该元素时,偷偷修改它的状态和行为,譬如:让按钮的边框为红色; 3. 利用MFC类的虚函数机制,重载有用的虚函数。在MFC框架调用该函数的时候,重新定义它的状态和行为; 一般来说,应用程序可以通过以下两种途径来实现以上的方法: 1. 在父窗口里,截获自身的或者由子元素(包括控件和菜单等元素)传递的关于界面绘制的消息; 2. 子类化子元素,或者为子元素准备一个新的类(一般来说该类必须继承于MFC封装的某个标准类,如:CButton)。在该子元素里,截获自身的或者从父窗口反射过来的关于界面绘制的消息。譬如:用户可以创建一个CXPButton类来实现具有XP风格的按钮,CXPButton继承于CButton。 对于应用程序,使用CXPButton类的途径相对于对话框窗口和普通窗口分成两种: ① 对话框窗口中,直接将原先绑定按钮的CButton类替换成CXPButton类,或者在绑定变量时直接指定Control类型为CXPButton,如图3所示: 图3 为按钮指定CXPButton类型 ②在普通窗口中,直接创建一个CXPButton类对象,然后在OnCreate()中调用CXPButton的Create方法; 以下的章节将综合地使用以上的方法,请读者朋友留心观察。 3.2 使用MFC类的既有函数 在界面美化的专题中,MFC也并非一无是处。MFC类对于界面美化也做了部分的努力,以下是一些可以使用的,参数说明略去。 CWinApp::SetDialogBkColor void SetDialogBkColor( COLORREF clrCtlBk = RGB(192, 192, 192), COLORREF clrCtlText = RGB(0, 0, 0) ); 指定对话框的背景色和文本颜色。 CListCtrl::SetBkColor CReBarCtrl::SetBkColor CStatusBarCtrl::SetBkColor CTreeCtrl::SetBkColor COLORREF SetBkColor( COLORREF clr ); 设定背景色。 CListCtrl::SetTextColor CReBarCtrl::SetTextColor CTreeCtrl::SetTextColor COLORREF SetTextColor( COLORREF clr ); 设定文本颜色。 CListCtrl::SetBkImage BOOL SetBkImage( LVBKIMAGE* plvbkImage ); BOOL SetBkImage( HBITMAP hbm, BOOL fTile = TRUE, int xOffsetPercent = 0, int yOffsetPercent = 0); BOOL SetBkImage( LPTSTR pszUrl, BOOL fTile = TRUE, int xOffsetPercent = 0, int yOffsetPercent = 0 ); 设定列表控件的背景图片。 CComboBoxEx::SetExtendedStyle CListCtrl::SetExtendedStyle CTabCtrl::SetExtendedStyle CToolBarCtrl::SetExtendedStyle DWORD SetExtendedStyle( DWORD dwExMask, DWORD dwExStyles ); 设置控件的扩展属性,例如:设置列表控件属性带有表格线。 图4是个简单应用MFC类的既有函数来改善Windows界面的例子: 图4 使用MFC类的既有函数美化界面 相关实现代码如下: BOOL CUi2App::InitInstance() { //… //设置对话框背景色和字体颜色 SetDialogBkColor(RGB(128, 192, 255), RGB(0, 0, 255)); //… } BOOL CUi2Dlg::OnInitDialog() { //… //设置列表控件属性带有表格线 DWORD NewStyle = m_List.GetExtendedStyle(); NewStyle |= LVS_EX_GRIDLINES; m_List.SetExtendedStyle(NewStyle); //设置列表控件字体颜色为红色 m_List.SetTextColor(RGB(255, 0, 0)); //填充数据 m_List.InsertColumn(0, "QQ", LVCFMT_LEFT, 100); m_List.InsertColumn(1, "昵称", LVCFMT_LEFT, 100); m_List.InsertItem(0, "5854165"); m_List.SetItemText(0, 1, "白乔"); m_List.InsertItem(1, "6823864"); m_List.SetItemText(1, 1, "Satan"); //… } 嗯,这样的界面还算不错吧? 3.3 使用Windows的消息机制 使用MFC类的既有函数来美化界面,其功能是有限的。既然Windows是通过消息机制进行通讯的,那么我们就可以通过截获一些有用的消息来美化我们的界面,以下是一些有用的Windows消息: WM_PAINT WM_ERASEBKGND WM_CTLCOLOR* WM_DRAWITEM* WM_MEASUREITEM* NM_CUSTOMDRAW* 注意,标注*的消息是子元素发送给父窗口的通知消息,其它的为窗口或者子元素自身的消息。 3.3.1 WM_PAINT WM_PAINT消息相信大家都很熟悉,一个窗口要重绘了,就会有一个WM_PAINT消息发送给窗口。 可以响应窗口的WM_PAINT,以更改它们的模样。WM_PAINT的映射函数原型如下: afx_msg void OnPaint(); 控件也是窗口,所以控件也有WM_PAINT消息,通过消息映射我们完全可以定义控件的界面。如图5所示: 图5 利用WM_ PAINT消息美化界面 实现代码也很简单: void CLazyStatic::OnPaint() { CPaintDC dc(this); // device context for painting //什么都不输出,仅仅画一个矩形框 CRect rc; GetClientRect(&rc); dc.Rectangle(rc); } 哈哈,简单吧?不过WM_PAINT确实绝了点,它要求应用程序完成元素界面的所有绘制过程,想象一下如何画出一个完整的列表控件?太烦了吧。一般来说,很少有人喜欢使用WM_PAINT,还有其它更细致的消息。 3.3.2 WM_ERASEBKGND Windows在向窗口发送WM_PAINT消息之前,总会发送一个WM_ERASEBKGND消息通知该窗口擦除背景,默认情况下,Windows将以窗口的背景色清除该窗口。 可以响应窗口(包括子元素)的WM_ERASEBKGND,以更改它们的背景。WM_ERASEBKGND的映射函数原型如下: afx_msg BOOL OnEraseBkgnd( CDC* pDC ); 返回值: 指定背景是否已清除,如果为FALSE,系统将自动清除 参数: pDC指定了绘制操作所使用的设备环境。 图6是个简单的例子,通过OnEraseBkgnd为对话框加载了一副位图背景: 图6 利用WM_ ERASEBKGND消息美化界面 实现代码也很简单: BOOL CUi4Dlg::OnInitDialog() { //… //加载位图 //CBitmap m_Back; m_Back.LoadBitmap(IDB_BACK); //… } BOOL CUi4Dlg::OnEraseBkgnd(CDC* pDC) { CDC dc; dc.CreateCompatibleDC(pDC); dc.SelectObject(&m_Back); //获取BITMAP对象 BITMAP hb; m_Back.GetBitmap(&hb); //获取窗口大小 CRect rt; GetClientRect(&rt); //显示位图 pDC->StretchBlt(0, 0, rt.Width(), rt.Height(), &dc, 0, 0, hb.bmWidth, hb.bmHeight, SRCCOPY); return TRUE; } HBRUSH CUi4Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { //设置透明背景模式 pDC->SetBkMode(TRANSPARENT); //设置背景刷子为空 return (HBRUSH)::GetStockObject(HOLLOW_BRUSH); } 同时别忘了响应OnCtlColor,否则窗口里面的控件就不透明了。OnCtlColor的内容。 3.3.3 WM_CTLCOLOR 在控件显示之前,每一个控件都会向父对话框发送一个WM_CTLCOLOR消息要求获取绘制所需要的颜色。WM_CTLCOLOR消息缺省处理函数CWnd::OnCtlColor返回一个HBRUSH类型的句柄,这样,就可以设置前景和背景文本颜色,并为控件或者对话框的非文本区域选定一个刷子。 WM_CTLCOLOR的映射函数原型如下: afx_msg HBRUSH OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor ); 返回值: 用以指定背景的刷子 参数: pDC指定了绘制操作所使用的设备环境。 pWnd 控件指针 nCtlColor 指定控件类型,其取值如表2所示: 类型值 含义 CTLCOLOR_BTN 按钮控件 CTLCOLOR_DLG 对话框 CTLCOLOR_EDIT 编辑控件 CTLCOLOR_LISTBOX 列表框 CTLCOLOR_MSGBOX 消息框 CTLCOLOR_SCROLLBAR 滚动条 CTLCOLOR_STATIC 静态控件 表2 nCtlColor的类型值与含义 作为一个简单的例子,观察以下的代码: BOOL CUi5Dlg::OnInitDialog() { //… //创建字体 //CFont CUi1View::m_Font1, CUi1View::m_Font2 m_Font1.CreatePointFont(120, "Impact"); m_Font3.CreatePointFont(120, "Arial"); return TRUE; // return TRUE unless you set the focus to a control } HBRUSH CUi5Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if(nCtlColor == CTLCOLOR_STATIC) { //区分静态控件 switch(pWnd->GetDlgCtrlID()) { case IDC_STATIC1: { pDC->SelectObject(&m_Font1); pDC->SetTextColor(RGB(0, 0, 255)); break; } case IDC_STATIC2: { pDC->SelectObject(&m_Font2); pDC->SetTextColor(RGB(255, 0, 0)); break; } } } return hbr; } 生成的界面如下: 图7 利用WM_CTLCOLOR消息美化界面 3.3.4 WM_DRAWITEM OnCtlColor只能修改元素的颜色,但不能修改元素的界面框架,WM_DRAWITEM则可以。 当一个具有Owner draw风格的元素(包括按钮、组合框、列表框和菜单等)需要显示外观时,该元素会发送一条WM_DRAWITEM消息至它的隶属窗口(Owner)。 WM_DRAWITEM的映射函数原型如下: afx_msg void OnDrawItem( int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct ); 参数: nIDCtl 该控件的ID,如果该元素为菜单,则nIDCtl为0 lpDrawItemStruct 指向DRAWITEMSTRUCT结构对象的指针,DRAWITEMSTRUCT的结构定义如下: typedef struct tagDRAWITEMSTRUCT { UINT CtlType; UINT CtlID; UINT itemID; UINT itemAction; UINT itemState; HWND hwndItem; HDC hDC; RECT rcItem; DWORD itemData; }DRAWITEMSTRUCT; CtlType指定了控件的类型,其取值如表3所示: 类型值 含义 ODT_BUTTON 按钮控件 ODT_COMBOBOX 组合框控件 ODT_LISTBOX 列表框控件 ODT_LISTVIEW 列表视图 ODT_MENU 菜单项 ODT_STATIC 静态文本控件 ODT_TAB Tab控件 表3 CtlType的类型值与含义 CtlID 指定自绘控件的ID值,该成员不适用于菜单项 itemID表示菜单项ID,也可以表示列表框或者组合框中某项的索引值。对于一个空的列表框或组合框,该成员的值为?C1。这时应用程序只绘制焦点矩形(该矩形的坐标由rcItem 成员给出)虽然此时控件中没有需要显示的项,但是绘制焦点矩形还是很有必要的,因为这样做能够提示用户该控件是否具有输入焦点。当然也可以设置itemAction 成员为合适值,使得无需绘制焦点。 itemAction 指定绘制行为,其取值为表4中所示值的一个或者多个的联合: 类型值 含义 ODA_DRAWENTIRE 当整个控件都需要被绘制时,设置该值。 ODA_FOCUS 如果控件需要在获得或失去焦点时被绘制,则设置该值。此时应该检查itemState成员,以确定控件是否具有输入焦点。 ODA_SELECT 如果控件需要在选中状态改变时被绘制,则设置该值。此时应该检查itemState 成员,以确定控件是否处于选中状态。 表4 itemAction的类型值与含义 itemState 指定了当前绘制项的状态。例如,如果菜单项应该被灰色显示,则可以指定ODS_GRAYED状态标志。其取值为表5中所示值的一个或者多个的联合: 类型值 含义 ODS_CHECKED 标记状态,仅适用于菜单项。 ODS_DEFAULT 默认状态。 ODS_DISABLED 禁止状态。 ODS_FOCUS 焦点状态。 ODS_GRAYED 灰化状态,仅适用于菜单项。 ODS_SELECTED 选中状态。 ODS_HOTLIGHT 仅适用于Windows 98/Me/Windows 2000/XP,热点状态:如果鼠标指针位于控件之上,则设置该值,这时控件会显示高亮颜色。 ODS_INACTIVE 仅适用于Windows 98/Me/Windows 2000/XP,非激活状态。 ODS_NOACCEL 仅适用于Windows 2000/XP,控件是否有快速键。 ODS_COMBOBOXEDIT 在自绘组合框控件中只绘制选择区域。 ODS_NOFOCUSRECT 仅适用于Windows 2000/XP,不绘制捕获焦点的效果。 表5 itemState的类型值与含义 hwndItem 指定了组合框、列表框和按钮等自绘控件的窗口句柄;如果自绘的对象为菜单项,则表示包含该菜单项的菜单句柄。 hDC 指定了绘制操作所使用的设备环境。 rcItem 指定了将被绘制的矩形区域。这个矩形区域就是上面hDC的作用范围。系统会自动裁剪组合框、列表框或按钮等控件的自绘制区域以外的部分。也就是说rcItem中的坐标点(0,0)指的就是控件的左上角。但是系统不裁剪菜单项,所以在绘制菜单项的时候,必须先通过一定的换算得到该菜单项的位置,以保证绘制操作在我们希望的区域中进行。 itemData 对于菜单项,该成员的取值为由CMenu::AppendMenu、CMenu::InsertMenu、CMenu::ModifyMenu等函数传递给菜单的值。 对于列表框或这组合框,该成员的取值为由ComboBox::AddString、CComboBox::InsertString、CListBox::AddString或者CListBox::InsertString等函数传递给控件的值。 如果ctlType 的取值是ODT_BUTTON或者ODT_STATIC,itemData的取值为0。 图5是个相应的例子,它修改了按钮的界面: 图8 利用WM_DRAWITEM消息美化界面 实现代码如下: BOOL CUi6Dlg::OnInitDialog() { //… //创建字体 //CFont CUi1View::m_Font m_Font.CreatePointFont(120, "Impact"); //… } void CUi6Dlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) { if(nIDCtl == IDC_HELLO_CFAN) { //绘制按钮框架 UINT uStyle = DFCS_BUTTONPUSH; //是否按下去了? if (lpDrawItemStruct->itemState & ODS_SELECTED) uStyle |= DFCS_PUSHED; CDC dc; dc.Attach(lpDrawItemStruct->hDC); dc.DrawFrameControl(&lpDrawItemStruct->rcItem, DFC_BUTTON, uStyle); //输出文字 dc.SelectObject(&m_Font); dc.SetTextColor(RGB(0, 0, 255)); dc.SetBkMode(TRANSPARENT); CString sText; m_HelloCFan.GetWindowText(sText); dc.TextOut(lpDrawItemStruct->rcItem.left + 20, lpDrawItemStruct->rcItem.top + 20, sText); //是否得到焦点 if(lpDrawItemStruct->itemState & ODS_FOCUS) { //画虚框 CRect rtFocus = lpDrawItemStruct->rcItem; rtFocus.DeflateRect(3, 3); dc.DrawFocusRect(&rtFocus); } return; } CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct); } 别忘了标记Owner draw属性: 图9 指定按钮的Owner draw属性 值得一提的是,CWnd内部截获了WM_DRAWITEM、WM_MEASUREITEM等消息,并映射成子元素的相应虚函数的调用,如CButton::DrawItem()。所以,以上例子也可以通过派生出一个CButton的派生类,并重载该类的DrawItem()函数来实现。使用虚函数机制实现界面美化参见3.4章节。 3.3.5 WM_MEASUREITEM 仅仅WM_DRAWITEM还是不够的,对于一些特殊的控件,如ListBox,系统在发送WM_DRAWITEM消息前,还发送WM_MEASUREITEM消息,需要你设置ListBox中每个项目的高度。 WM_DRAWITEM的映射函数原型如下: afx_msg void OnMeasureItem( int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct ); nIDCtl 该控件的ID,如果该元素为菜单,则nIDCtl为0 lpMeasureItemStruct指向MEASUREITEMSTRUCT结构对象的指针,MEASUREITEMSTRUCT的结构定义如下: typedef struct tagMEASUREITEMSTRUCT { UINT CtlType; UINT CtlID; UINT itemID; UINT itemWidth; UINT itemHeight; DWORD itemData } MEASUREITEMSTRUCT; CtlType指定了控件的类型,其取值如表6所示: 类型值 含义 ODT_COMBOBOX 组合框控件 ODT_LISTBOX 列表框控件 ODT_MENU 菜单项 表6 CtlType的类型值与含义 CtlID 指定自绘控件的ID值,该成员不适用于菜单项 itemID表示菜单项ID,也可以表示可变高度的列表框或组合框中某项的索引值。该成员不适用于固定高度的列表框或组合框。 itemWidth 指定菜单项的宽度 itemHeight指定菜单项或者列表框中某项的的高度,最大值为255 itemData 对于菜单项,该成员的取值为由CMenu::AppendMenu、CMenu::InsertMenu、CMenu::ModifyMenu等函数传递给菜单的值。 对于列表框或这组合框,该成员的取值为由ComboBox::AddString、CComboBox::InsertString、CListBox::AddString或者CListBox::InsertString等函数传递给控件的值。 图示出了OnMeasureItem的效果: 图10 利用WM_MEASUREITEM消息美化界面 相应的OnMeasureItem()实现如下: void CUi7Dlg::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) { if(nIDCtl == IDC_COLOR_PICKER) { //设定高度为 lpMeasureItemStruct->itemHeight = 30; return; } CDialog::OnMeasureItem(nIDCtl, lpMeasureItemStruct); } 同样别忘了指定列表框的Owner draw属性: 图11 指定下拉框的Owner draw属性 3.3.6 NM_CUSTOMDRAW 大家也许熟悉WM_NOTIFY,控件通过WM_NOTIFY向父窗口发送消息。在WM_NOTIFY消息体中,部分控件会发送NM_CUSTOMDRAW告诉父窗口自己需要绘图。 可以反射NM_CUSTOMDRAW消息,如: ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw) afx_msg void OnCustomDraw(NMHDR *pNMHDR, LRESULT *pResult); 参数: pNMHDR 说到底只是一个指针,大多数情况下它指向一个NMHDR结构对象,NMHDR结构如下: typedef struct tagNMHDR { HWND hwndFrom; UINT idFrom; UINT code; } NMHDR; 其中: hwndFrom 发送方控件的窗口句柄 idFrom 发送方控件的ID code 通知代码 对于某些控件来说,pNMHDR则会解释成其它内容更丰富的结构对象的指针,如:对于列表控件来说,pNMHDR常常指向一个NMCUSTOMDRAW对象,NMCUSTOMDRAW结构如下: typedef struct tagNMCUSTOMDRAWINFO { NMHDR hdr; DWORD dwDrawStage; HDC hdc; RECT rc; DWORD dwItemSpec; UINT uItemState; LPARAM lItemlParam; } NMCUSTOMDRAW, FAR * LPNMCUSTOMDRAW; hdr NMHDR对象 dwDrawStage 当前绘制状态,其取值如表7所示: 类型值 含义 CDDS_POSTERASE 擦除循环结束 CDDS_POSTPAINT 绘制循环结束 CDDS_PREERASE 准备开始擦除循环 CDDS_PREPAINT 准备开始绘制循环 CDDS_ITEM 指定dwItemSpec, uItemState, lItemlParam参数有效 CDDS_ITEMPOSTERASE 列表项擦除结束 CDDS_ITEMPOSTPAINT 列表项绘制结束 CDDS_ITEMPREERASE 准备开始列表项擦除 CDDS_ITEMPREPAINT 准备开始列表项绘制 CDDS_SUBITEM 指定列表子项 表7 dwDrawStage的类型值与含义 hdc指定了绘制操作所使用的设备环境。 rc指定了将被绘制的矩形区域。 dwItemSpec 列表项的索引 uItemState 当前列表项的状态,其取值如表8所示: 类型值 含义 CDIS_CHECKED 标记状态。 CDIS_DEFAULT 默认状态。 CDIS_DISABLED 禁止状态。 CDIS_FOCUS 焦点状态。 CDIS_GRAYED 灰化状态。 CDIS_SELECTED 选中状态。 CDIS_HOTLIGHT 热点状态。 CDIS_INDETERMINATE 不定状态。 CDIS_MARKED 标注状态。 表8 uItemState的类型值与含义 lItemlParam 当前列表项的绑定数据 pResult 指向状态值的指针,指定系统后续操作,依赖于dwDrawStage: 当dwDrawStage为CDDS_PREPAINT,pResult含义如表9所示: 类型值 含义 CDRF_DODEFAULT 默认操作,即系统在列表项绘制循环过程不再发送NM_CUSTOMDRAW。 CDRF_NOTIFYITEMDRAW 指定列表项绘制前后发送消息。 CDRF_NOTIFYPOSTERASE 列表项擦除结束时发送消息。 CDRF_NOTIFYPOSTPAINT 列表项绘制结束时发送消息。 表9 pResult的类型值与含义(一) 当dwDrawStage为CDDS_ITEMPREPAINT,pResult含义如表10所示: 类型值 含义 CDRF_NEWFONT 指定后续操作采用应用中指定的新字体。 CDRF_NOTIFYSUBITEMDRAW 列表子项绘制时发送消息。 CDRF_SKIPDEFAULT 系统不必再绘制该子项。 表10 pResult的类型值与含义(二) 以下是一个利用NM_CUSTOMDRAW消息绘制出的多色列表框的例子: 图12 利用NM_CUSTOMDRAW消息美化界面 对应代码如下: void CCoolList::OnCustomDraw(NMHDR *pNMHDR, LRESULT *pResult) { //类型安全转换 NMLVCUSTOMDRAW* pLVCD = reinterpret_cast(pNMHDR); *pResult = 0; //指定列表项绘制前后发送消息 if(CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage) { *pResult = CDRF_NOTIFYITEMDRAW; } else if(CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage) { //奇数行 if(pLVCD->nmcd.dwItemSpec % 2) pLVCD->clrTextBk = RGB(255, 255, 128); //偶数行 else pLVCD->clrTextBk = RGB(128, 255, 255); //继续 *pResult = CDRF_DODEFAULT; } } 注意到上例采取了3.1所推荐的第2种实现方法,派生了一个新类CCoolList。 3.4 使用MFC类的虚函数机制 修改Windows界面,除了从Windows消息机制下功夫,也可以从MFC类下功夫,这应该得益于类的虚函数机制。为了防止诸如“面向对象技术”等术语在此泛滥,以下仅举一段代码作为例子: void CView::OnPaint() { // standard paint routine CPaintDC dc(this); OnPrepareDC(&dc); OnDraw(&dc); } 这是MFC中viewcore.cpp中的源代码,很多读者总不明白OnDraw()和OnPaint()之间的关系,从以上的代码中很容易看出,CView的WM_PAINT消息响应函数OnPaint()会自动调用CView::OnDraw()。而作为开发者的用户,可以通过简单的OnDraw()的重载实现对WM_PAINT的处理。所以说,对MFC类的虚函数的重载是对消息机制的扩展。 以下列出了与界面美化相关的虚函数,参数说明略去: CButton::DrawItem CCheckListBox::DrawItem CComboBox::DrawItem CHeaderCtrl::DrawItem CListBox::DrawItem CMenu::DrawItem CStatusBar::DrawItem CStatusBarCtrl::DrawItem CTabCtrl::DrawItem virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct ); Owner draw元素自绘函数 很显然,位图菜单都是通过这个DrawItem画出来的。限于篇幅,在此不再附以例程。
1,01.zip
3D Text
显示3D文字(6KB)
2,02.zip
A button within a button
按纽中的按纽(13KB)
3,03.zip
Flat Owner Drawn Buttons
浮动的自画按纽(13KB)
4,04.zip
Flat-look Buttons
浮动的工具条按纽(6KB)
5,05.zip
Showing disabled combo text in black
ComboBox的只读属性(5KB)
6,06.zip
Combobox Color Picker
选择颜色的ComboBox(6KB)
7,07.zip
Switch between drop down & drop list mode
处理drop down和drop list方式之间的转换(32KB)
8,08.zip
Drop down a popdown window instead of a dropdown list from a combobox 在ComboBox中用Drop down方式代替dropdown list方式(32KB)
9,09.zip
Change listbox width of combo boxes
在ComboBox中改变列表框的宽度(2KB)
10,10.zip
Owner Drawn Font Selection ComboBox
自画的字体选择ComboBox(5KB)
11,add.zip
This sample was developed on stage at the Washington Software Association's WinSIG meeting on the ninth of September, 1996 using Visual C++ 4.2. (13KB)
12,apibrow.zip
The project demonstrates the use of common control callback items in an MFC applicationthat manages a CListCtrl control in a CListView. (16KB)
13,colorlb.zip
The COLORLB sample shows how to implement an owner-draw list box. (53KB)
14,comper.zip
COMPER is an example of the ATL Composite Control. (123KB)
15,custfile.zip
This sample shows how to add a couple of extra buttons to a CFileDialog. (23KB)
16,custlist.zip
CUSTLIST shows how to use custom draw in a list view control. (23KB)
17,div.zip
This sample shows how floating-point exceptions may be captured and handled in an MFC application. (14KB)
18,doodads.zip
The project demonstrates many Windows common controls, including the extensive use of image lists. (83KB)
19,doubleedit.zip
DOULBEEDIT shows how to sublcass an edit control inside a form view and react to double-clicks on the edit control by handling the WM_LBTNDOUBLECLICK message. (18KB)
20,dumpsome.zip
DUMPSOME is a project for Visual C++ 4.x that shows how to write a CGI server extension which uses MFC and DAO. (8KB)
21,edpos.zip
EDPOS is a MDI-based MFC application that shows an edit control in its primary view. (35KB)
22,edstream.zip
this sample shows how to use the StreamIn() and StreamOut() members of the CRichEditCtrl class in MFC. (36KB)
23,findrich.zip
RICHFIND is a dialog-based MFC application for Visual C++ 6.0. (24KB)
24,floatlist.zip
The FloatList sample is an MFC-based SDI application with an edit view as its main window. (49KB)
25,fully.zip
FULLY shows how to make an MFC application make one of its views go full-screen active. (43KB)
26,holder.zip
HOLDER contains the Internet Explorer web browser control using CHtmlView in an MFC application. (67KB)
27,langload.zip
LANGLOAD shows how to use the LANGUAGE keyword in a resource file to mark language-specific resources. (2KB)
28,listfind.zip
This sample shows how to use the CList<> template. (9KB)
29,ndbrow.zip
This Visual C++ 6 project shows how to create an MDI application that hosts CHtmlView (20KB)
30,mfctalk.zip
MFCTALK was originally published with Mike's article on ISPAI programming with MFC in the May (23KB)
31,mfctlist.zip
MCTTLIST is a dialog-based application that provides the same functionality as the TLIST sample in the SDK. (28KB)
32,mruless.zip
MRULESS shows a way to strip the empty "Recent Files" item off the "File" menu when there are no entries in the MRU. (32KB)
33,mtprint.zip
MTPRINT demonstrates the use of a secondary thread to perform printing in an application that uses MFC's document/view architecture. (21KB)
34,multitop.zip
MULTITOP shows how to write an SDI application which has multiple top level windows and uses the MFC doc/view architecture.(30KB)
35,njfind16.zip
This 16-bit DOS tool traverses all directories on all drives on your machine and finds files which match the template you specify. (33KB)
36,noform.zip
This sample shows how to make an application that doesn't have the doc/view architecture but still offers a form in the client area of the application's main window. (33KB)
37,odcombo.zip
ODCOMBO.ZIP is a VC++ 6.0 dialog-based project that contians an onwer-drawn combo box. (23KB)
38,picknew.zip
It demonstrates calling CDocTemplate::OpenDocumentFile(). (49KB)
39,primecon.zip
PrimeCon is a VC++ 6.0 sample which uses MFC in a console application.(60KB)
40,q1.zip
Q1 is a VC++ 6.0 project that creates two threads. (79KB)
41,scrl.zip
This dialog-based application shows how to use the CListCtrl::Scroll() member. (14KB)
42,spinrange.zip
SpinRange is a VC++ 6.0 project that shows how to subclass a CSpinButtonControl to dramatically extend the range of the control. (24KB)
43,splits.zip
This VC++ 5.0 project shows how to manage views within a splitter window. (36KB)
44,stealth.zip
This SDI application shows how to create an application that doesn't show up in the task bar in Windows 95 or Windows NT 4.0. (29KB)
45,tenhook.zip
Because the Windows dialog manager eats all keystrokes, you'll need to install a Windows keyboard hook if you want to get keyboard input to your dialog without other controls getting in the way. (19KB)
46,treestore.zip
Tree views are capable of storing hierarchical data, which isn't intuitively serialized. (41KB)
47,writeres.zip
This console application shows how to bake resources into console applications. (566KB)
48,xctrl.zip
The XCTRL sample is an ATL "full control" ATL Control. (100KB)
49,Button_Tute.zip
How to get a button control wired-in and working(34KB)
50,BetterBmpButton_src.zip
An improvement on the CBitmapButton class.(22KB)
51,hoverbutton.zip
A simple drop-in class that provides a 'hot' look button using the _TrackMouseEvent function(17KB)
52,CLedButton_src.zip
A button that looks like a LED.(24KB)
53,EllipticalButtons.zip
A class that turns rectangular buttons into elliptic buttons.(29KB)
54,RoundButtons.zip
A class that turns rectangular buttons into round buttons.(17KB)
55,AniButton.zip
A class that show AVIs inside a button.(49KB)
56,CButtonST26.zip
A fully featured owner-draw button class - it's got the lot!(225KB)
57,coolbtn.zip
This article shows the use of a Push button with a drop down menu, similar to the one found in the Office 2000 suite.(31KB)
58,CustomButtons.zip
A class to make working with radio buttons easier, and another for custom drawing buttons(45KB)
59,CWBButton.zip
CWBButton is a resizable bitmap button like GTK+ or Window Blinds.(44KB)
60,ComboDropWidth.zip
A simple tutorial explaining how to set the width of a combo dropdown list so that all items are fully visible(18KB)
61,ComboBox_Tut_demo.zip
An entry level tutorial on using the CComboBox control(65KB)
62,ListBox_Tut_src.zip
An entry level tutorial on using the CListBox control(62KB)
63,BitmapPickerCombo.zip
A combo box that can be used to display bitmaps(26KB)
64,mccombobox.zip
A multicolumn, customizable, editable combobox(27KB)
65,disableditemscombobox_src.zip
combobox with disabled items(3KB)
66,checkcombo.zip
A combo box with check boxes(21KB)
67,ColourPickerCB.zip
A combobox derived class that provides a simple color picker(36KB)
68,ComboBoxInit_src.zip
Learn how to programmatically initialize a combo box.(3KB)
69,IconComboBox_src.zip
2 Freeware MFC icon selection combo box classes(19KB)
70,ComboCompletion_demo.zip
A combobox that autocompletes as you type(17KB)
71,IDComboDemo.zip
An extremely simple but useful CComboBox entension(12KB)
72,MRUCombo.zip
A combobox that encapsulates the functionality of CRecentFileList(29KB)
73,combobox_flatcombo.zip
A drop-in replacement combobox that gives your apps the flat Office-style look(53KB)
74,readonlycombo_src.zip
Show a disabled dropdown style combobox like a read only edit box.(2KB)
75,VBLikeCombo.zip
Creates a combo box similar to those in Visual Basic.(27KB)
76,ComboTree.zip
ComboBox with a tree control drop down(36KB)
77,multichecklistbox.zip
Extends the CCheckListBox class to have multiple check box columns(19KB)
78,disableditemslistbox_src.zip
Listbox with disabled items.(2KB)
79,ImageLB.zip
A list box for viewing images(25KB)
80,LVCustomDraw.zip
Using the custom-draw features in version 4.70 of the common controls to customise the look and feel of list controls(28KB)
81,ListCtrlDemo.zip
Everything you need to know about using the standard list control in your applications(68KB)
82,filedroplistctrl.zip
This article explains how to support file drag and drop in your CWnd-derived object(40KB)
83,DrivePickerList.zip
A control that shows drive names and icons like Explorer(23KB)
84,ListEditor.zip
This article shows you how you can navigate through a multi-column, editable list view(42KB)
85,LogControl_src.zip
Learn how to use printf-like functionality to debug your GUI applications.(46KB)
86,PropertyListCtrl.zip
An object properties list control than can change based on the objects state.(64KB)
87,supergrid.zip
A combination list control and tree control with checkbox capability(87KB)
88,Listview_callback.zip
Shows how to use text callbacks in list controls(16KB)
89,HeaderCtrlEx.zip
How to make the CListCtrl's header Multiline(29KB)
90,listPrint_demo.zip
Printing the contents of a CListCtrl or CListView with multiple pages(56KB)
91,TreeListCtrlGerolf.zip
A custom-drawn tree-list hybrid, with explanations on how the control was developed.(39KB)
92,PrtTView_demo.zip
Code to add printing capabilities to a Tree View(32KB)
93,treelist.zip
A tree control / list control hybrid(81KB)
94,FileTree_src.zip
Implements a tree control similar to the left hand side of Windows Explorer.(46KB)
95,TreeOpt_src.zip
A freeware MFC class to provide a tree options control.(32KB)
96,ShTree.zip
A very simple manager for shared folders using tree control drag & drop (42KB)
97,NetworkTreeCtrl.zip
A CWaitingTreeCtrl-derived class to display network resources(40KB)
98,ProgressHourglassFX.zip
Two animation provider classes to add animation effects to any CWaitingTreeCtrl-derived class(33KB)
99,ShellTreeCtrl.zip
A CWaitingTreeCtrl-derived class to display Shell's resources(39KB)
100,WaitingTreeCtrl_src.zip
A CTreeCtrl derived class that populates the branches of a tree only when necessary, with optional visual effects.(5KB)
101,PathPicker.zip
An article on Browsing my computer and the network using a TreeCtrl(82KB)
102,Tree2Excel.zip
This article is a light sample showing how to iterate and export a tree control content to an Excel file.(44KB)
103,lbtab.zip
A better looking tab control(89KB)
104,CXTabControl_demo.zip
An easier tab control(32KB)
105,ResizableProperties.zip
Two CPropertySheet/CPropertyPage derived classes to implement resizable property sheets or wizard dialogs with MFC(96KB)
106,saprefs.zip
A base class for a prefereneces dialog, similar to that used in Netscape(39KB)
107,wizardpropertysheet_src.zip
A simply class to turn CPropertySheet into wizard mode without needing to alert the property pages within(2KB)
108,AutoRichEditCtrl.zip
CAutoRichEditCtrl - automate rich edit formatting and RTF handling(49KB)
109,AutomaticSplitter.zip
A tutorial that shows how to automatically split a view, and also how to indicate which view has the focus(31KB)
110,usefulsplitter.zip
An extension to MFCs CSplitterWnd that provides splitter locking and dynamic view replacement(25KB)
111,rulers_src.zip
Using fixed panes to add rulers to your view(5KB)
112,StaticCtrl_Tut_demo.zip
An entry level tutorial on using the CStatic control(64KB)
113,rotated_bevel.zip
A bevelline control that displays vertical and horizontal text(83KB)
114,Ticker.zip
A class that provides a news/stock ticker for your MFC applications(47KB)
115,StaticCounter.zip
A control to display time, floating point numbers or integers using an LED digital-style display(41KB)
116,CStaticTime.zip
A control to display times and numbers using an LED digital-style display(52KB)
117,alexf_histogram.zip
A simple histogram control for displaying data(23KB)
118,static_fader.zip
A CStatic class that gently fades text into view(99KB)
119,CLabel_demo.zip
A fully stocked owner drawn CStatic class(52KB)
120,DigiString.zip
A control to display text or numbers with a 14 or 7 segment display(176KB)
121,cstatic_filespec.zip
Lightweight class for displaying long filespecs that may need to be truncated(16KB)
122,tip_static.zip
A tip-of-the-day control that uses a cool sliding effect to show each tip(133KB)
123,UsingCtrlsInDialogs_Tut_demo.zip
An entry level tutorial on using one of the Windows Common Controls in a dialog(42KB)
124,CmdUIDemo.zip
A C++/MFC sample how to implement UI notifications for user-defined controls(15KB)
125,SubclassDemo.zip
An introduction to subclassing the Windows common controls using MFC(19KB)
126,CustomControl.zip
An introduction to creating custom controls using MFC(22KB)
127,graph2d.zip
A comprehensive set of classes for displaying 2 dimensional data(386KB)
128,3dMeter_demo.zip
An Analog Meter Control for displaying real-time data(42KB)
129,analog_meter.zip
A control that displays a numerical value as an analog meter(45KB)
130,oscope.zip
A control that graphically displays numerical information(31KB)
131,swing_demo.zip
A set of MFC classes the duplicate the Java Swing look and feel(76KB)
132,ReportCtrl.zip
An Outlook 98/2000 Style SuperGrid Report Control that tries to overcome some of the weaknesses of other implementations.(179KB)
133,controls_pager.zip
This article presents a wrapper class for the pager control(28KB)
134,RulerCtrl.zip
A simple ruler control to allow users to set margins or indents(21KB)
135,CSizer.zip
A class that provides the ability to move and size controls at run-time (34KB)
136,controls_avi_demo.zip
Demonstrates the use of the windows animation control(145KB)
137,CMapPin_src.zip
A Freeware MFC class to implement Map pins.(286KB)
138,CFCtrl.zip
The simplest way to change color, font or set blinking mode for any standard control(53KB)
139,CPushPin_src.zip
A Freeware MFC PushPin button class.(15KB)
140,CWndSlider.zip
An article on using an Outlook style window slider control.(98KB)
141,cxwndAnimate_demo.zip
An animation control that uses a bitmap imagelist instead of an AVI file(25KB)
142,hyperlink.zip
A simple drop-in hyperlink control(28KB)
143,ViewObjSnap.zip
How to take a snapshot of an OCX without using HWNDs.(38KB)
144,lbspin.zip
A spin button whose arrows automatically disable themselves when they are at their maximum or minimum value.(27KB)
145,SubclassWnd_demo.zip
A plug in class that allows you to intercept and handle messages for any window class(266KB)
146,resize_at_runtime_demo.zip
A method to allow the user to visually resize and position any control at run time(15KB)
147,RoundSliderCtrl.zip
A round slider control to allow users to adjust an angle or similar values(90KB)
148,EasyFavorite.zip
An application demonstrating the windows Thumbnail control(42KB)
149,TGroupBox.zip
A very simple group box replacement to enhance your user interface(3KB)
150,WndImg.zip
An easy-to-use control to display bitmaps (stretch, scale, tile)(128KB)
151,URLCell_src.zip
A new class that adds hyperlink support to the MFC Grid Control(3KB)
152,gridctrl.zip
A fully featured MFC grid control for displaying tabular data. The grid is a custom control derived from CWnd(381KB)
153,GridTreeCtrl.zip
A set of classes derived from CGridCtrl that embed a tree control, button controls, and virtual cells within the grid(221KB)
154,gridctrl_demo220.zip
Explains how to use comboboxes to edit cells in the MFC Grid Control(203KB)
155,AddHTMLy.zip
A quick and simple example of using MSHTML to modify the DOM(36KB)
156,Process_HTMLFORM.zip
A simple method to processing HTML forms From a CHtmlView(60KB)
157,ColorButton.zip
A simple modification to Chris Maunder's "Office 97 style Colour Picker" control(44KB)
158,ColorSpace_demo.zip
A replacement color picker control allowing you full visual control over RGB and HSB selections(288KB)
159,ColorDlg.zip
A simple color chooser dialog that uses slifer controls to allow the user to combine different RGB values(37KB)
160,choicelistbutton_demo.zip
A dropdown menu button with checkbox menu items(25KB)
161,HotList.zip
A control for selecting items from a list, with tool tips and mouse tracking(33KB)
162,colour_picker.zip
A simple drop in color chooser control(54KB)
163,progresswnd.zip
A popup window containing a progress control and cancel button - no resource file needed(34KB)
164,ProgressCtrlX.zip
An enhanced progress control that supports gradient shading, formatted text, 'snake' and reverse modes, and vertical modes(80KB)
165,GradientProgressCtrl.zip
Subclasses the standard CProgressCtrl to allow for gradient fills. Supports vertical progress controls as well.(52KB)
166,piectrl.zip
A progress control with a difference(149KB)
167,text_progressctrl_demo.zip
A smooth progress control with text(15KB)
168,ProgressBar.zip
An easy way to add a progress control to a status bar(33KB)
169,ProgressTimeToComplete.zip
A progress control that tells the user how long an operation has left to complete(26KB)
170,IProgressDialog_demo.zip
A wrapper class for the progress dialog provided by IE 5.(20KB)
171,rotary.zip
A rotary knob similar to that used in the Windows 2000 CD Player(67KB)
172,SizeDemo.zip
An MS-Word like drop down window for creating tables(37KB)
173,ToolTipEx.zip
A drop-in multiline extendable tooltip control(1052KB)
174,Multiline_Titletips_demo.zip
A class that allows you to display data for a control that is otherwise not large enough to display the full text(23KB)
175,CHtmlView_Search_demo.zip
Could be used to create a Visual C++ like search combo for CHtmlViews...
Update: Now you can highlight all matching words!(36KB)
176,AssociationGrid.zip
Grid control with vertical column headers.(85KB)

16,471

社区成员

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

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

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