A Line Picker

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

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);
...

Downloads

Download demo project - 46 Kb
Download source - 12 Kb


Comments

  • What for do you set focus on "OK" button after changing of selection in combo?

    Posted by Legacy on 10/24/2003 12:00am

    Originally posted by: Serguei

    What for do you set focus on "OK" button after changing of selection in combo? It's very hard to select anything in combo using a keyboard.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date