EarthWeb

Developer.com
Achieving Maximum Reliability, Availability, Scalability and Performance
CodeGuru Sites
Visual C++/MFC
.NET (C# and more)
Visual Basic

Discussion Boards
Books on .NET
Book Reviews
Newsletters (subscribe)
Newsletters (archived)

Article Sections
C++
algorithms & formulas
c++ & mfc
date & time
string
COM-based Technologies
atl & wtl
com & activex
com+
shell programming
Controls
button control
combobox
edit control
imagelist control
listbox control
listview control
menu
other controls
property sheet
rich edit control
static control
status bar
toolbar
treeview control
Data
database
miscellaneous
Frameworks
ui & printing frameworks
Graphics & Multimedia
bitmaps & palettes
directx
gdi
multimedia
opengl
Internet & Networking
ie programming
internet protocols
isapi
network protocols
Miscellaneous
miscellaneous
Visual Studio
debugging
add-ins & macros
editor tips
Windows Programming
ce
clipboard
dll
file & folder
help systems
printing
win32
system
Windows & Dialogs
console
dialog
docking window
doc/view
splitter
Interact
Newsletters
Guestbook
Recommend Us!
About Us

[Internet Jobs]
   

Enhanced Line-Drawing Class with Text


This article was contributed by Michael Dunn

Overview

The CSeparator class is an enhancement to standard static text controls that duplicates the look of the Office 97 products' options screens, like Word (pictured).

 [Word 97 options - 13K]

This separator element is a nice alternative when you want to avoid really big or nested group boxes, or just look like you're keeping up with Microsoft's ever-changing UI designs. ;)

This class is an extension to Hans Buehler's article "Control for drawing a bevel line." One of the enhancements he mentioned was adding text to horizontal lines, so that's what I've done!

CSeparator was written with MSVC 5.0. The code will work in Unicode apps, and should compile fine with 6.0 as well.

Example

When laying out a vertical separator, make the static control as tall as you want the line to be. The line will be drawn horizontally centered in the control, so it's a good idea to make the control the minimum width of 8 DLUs so you can judge where the line will appear. Vertical separators do not display text.

When laying out horizontal separators, place your static controls as usual, but make them as wide as you want the horizontal line to be. You can also set the alignment of the text (left, center, or right), and set the No Prefix style if you want. Those are the only static control styles supported at this time. If you do not set the No Prefix style, then you can use a shortcut key (i.e., put a & before a letter) just as with normal static text controls.

A sample dialog is pictured below, first in the resource editor, and then with the separators in action.

 [Dlg in MSVC resource editor - 14K]  [Dlg with separators drawn - 17K]

Each static control that will be used as a separator should have a real unique ID (not IDC_STATIC). Using ClassWizard, create member variables of type CStatic for each separator, and then go to the ClassWizard-generated code and change the type of the variables to CSeparator. That's it!

Future Enhancements

I tried for a little while to get vertically-drawn text, but it was pretty tricky to get the text aligned correctly over the line. Drawing the text rotated is no problem (as long as you select a TrueType font into the DC!) but the horizontal position of the text depends on the length of the text. The CSeparator class has some code to draw text vertically, although it is commented out since it doesn't work exactly right. It's just there as a starting point for anyone brave enough to take on the challenge. See the OnPaint() function for the code snippet and some comments.

Download demo project - 14KB

Comments:

Add Comment

internet.commerce
 Be A Commerce Partner 
 Software Store  
 Search the Web  
 Email Marketing  
 Send a Press Release  
 Find a Web Host  
 Register Domains  
 Search the Web  



EarthWeb is a service of INT Media Group, Incorporated.
Copyright 2002 INT Media Group, Incorporated. All Rights Reserved.
Feedback,   Advertising Info,   Legal NoticesLicensing, Reprints, & Permissions,   Privacy Policy.
http://www.internet.com/