A Line Picker
Posted
by André Deperrois
on October 23rd, 2003
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 KbDownload source - 12 Kb

Comments
There are no comments yet. Be the first to comment!