A Line Picker | CodeGuru

A Line Picker

The following application uses source code from Icon Picker Combo Box by Joel Wahlberg and A Color Picker by Luis Ortega. The LinePickerDlg class implements a dialog designed to allow the selection of Style, Width, and Color attributes for a CPen object: Environment: VC6 To use this Line Picker dialog, follow these steps: How to […]

Written By
CodeGuru Staff
CodeGuru Staff
Oct 23, 2003
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

The following application uses source code from Icon Picker Combo Box by Joel Wahlberg and A Color Picker by Luis Ortega.

The LinePickerDlg class implements a dialog designed to allow the selection of Style, Width, and Color attributes for a CPen object:

Environment: VC6

To use this Line Picker dialog, follow these steps:

How to Include Line Picker in Your Project

  • Include the following files in your project:
    • LinePickerDlg.cpp
    • LinePickerDlg.h
    • Colorbtn.cpp
    • Colorbtn.h
    • Linecbbox.cpp
    • Linecbbox.h
  • Copy “Other.rc” into your “res” directory.
  • Add this line to your rc2 file: #include “Other.rc”. Make sure to place a Carriage Return after this line, to avoid the “fatal error RC1004: unexpected end of file found” message.
  • Include the line #include “LinePickerDlg.h” in your C++ file.
  • Include the line #define IDD_LINEPICKERDLG (5110) in your class header file or in your “Resource.h” file.

How to Use Line Picker

Use the following code to modify the line attributes:

// Create Dialog
CLinePickerDlg *pdlg;
pdlg = new CLinePickerDlg();
// Initialize
// (make sure member variables themselves have been previously
//  initialized)
pdlg->SetColor(m_crColor);
pdlg->SetWidth(m_nWidth);
pdlg->SetStyle(m_nStyle);
// Run modal loop
pdlg->Create(IDD_LINEPICKERDLG);
pdlg->ShowWindow(SW_SHOW);
if(IDOK == pdlg->RunModalLoop(MLF_SHOWONIDLE)){
  // Retrieve new line attributes…
  m_crColor = pdlg->GetColor();
  m_nStyle  = pdlg->GetStyle();
  m_nWidth  = pdlg->GetWidth();
  // …and redraw Dialog
  Invalidate(true);
}
// Clean up!
pdlg->DestroyWindow();
delete pdlg;

To draw thick dotted lines—for instance, from within your OnPaint() method—you will need to use the second version of the CPen constructor:

…
LOGBRUSH lb;
lb.lbStyle = BS_SOLID;
lb.lbColor = m_crColor;
CPen CurPen(PS_GEOMETRIC | m_nStyle, m_nWidth, &lb);
CPen *pOldPen = dc.SelectObject(&CurPen);
Advertisement

Downloads


Download demo project – 46 Kb


Download source – 12 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.