1 °³¿ä
°¡²û¾¿ ¸®½ºÆ® ¹Ú½º¿¡ ÇÑ ¶óÀÎÀÌ ¾Æ´Ï¶ó, ¿©·¯ ¶óÀÎÀÌ Ãâ·ÂµÇ¾úÀ¸¸é ÇÏ´Â ¶§°¡ ÀÖ´Ù. ¸®½ºÆ® ºä¸¦ ÀÌ¿ëÇϱ⿡´Â Ä÷³ÀÌ º°·Î ÇÊ¿ä ¾ø°Å³ª/³Ê¹« ¸¹°Å³ª, °Ô´Ù°¡ ±ÍÂúÀ» ¶§ÀÌ´Ù.
À§ÀÇ ±×¸² ÇÏ´Ü ºÎºÐ¿¡ º¸¸é ¿©·¯ ¶óÀÎÀÌ Ãâ·ÂµÇ´Â ¸®½ºÆ® ¹Ú½º°¡ ÀÖ´Â °É º¼ ¼ö ÀÖ´Ù. À§¿Í °°Àº ·Î±× ºä¾îÀÇ °æ¿ì, ¸®½ºÆ® ºä¸¦ ÀÌ¿ëÇÏ°Ô µÇ¸é, Ä÷³ÀÌ ³Ê¹« ¸¹¾ÆÁ®, °¡·Î½ºÅ©·Ñ ¶§¹®¿¡ ¾ÆÀÌÅÛµéÀ» ÁÖ¿í »ìÆìº¸´Â ÀÏÀÌ °íÅ뽺·¯¿öÁø´Ù. (ÀüüâÀº ½È´Ù, ÀüüâÀº...)
CppBuilder¸¦ ÀÌ¿ëÇØ ¿©·¯ ÇàÀÇ ¹®ÀÚ¿ÀÌ µé¾î°¡´Â ¸®½ºÆ® ¹Ú½º¸¦ ±¸ÇöÇØ º¸ÀÚ.
2 ±¸Çö
¿ì¼± ¸®½ºÆ® ¹Ú½º¸¦ Æû¿¡´Ù Ãß°¡Çϰí, ¼Ó¼ºÀ» ´ÙÀ½°ú °°ÀÌ ¼³Á¤ÇØ ÁØ´Ù.
Style = lbOwnerDrawVariable
IntegralHeight = false
±× ´ÙÀ½ À̺¥Æ® Çڵ鷯¸¦ ¾Æ·¡¿Í °°ÀÌ ±¸ÇöÇØ ÁØ´Ù.
// ¶óÀÎ ±¸ºÐÀÚ·Î »ç¿ëÇÒ ¹®ÀÚ
static const char LineSeperator = '\n';
// ¾ÆÀÌÅÛ ±×¸²ÀÚ ¹Ú½º »ö±ò
static const TColor ShadowColor = TColor(0x000A0A0A);
// ¾ÆÀÌÅÛ ¹Ú½º »ö±ò
static const TColor NormalColor = clWindow;
// ¼±ÅÃÇÑ ¾ÆÀÌÅÛ ¹Ú½º »ö±ò
static const TColor SelectedColor = clSkyBlue;
// ¶óÀÎ °£ÀÇ °£°Ý (¹éºÐÀ²)
static LineSpacer = 140;
// ¸ð¼¸®°¡ µ¿±×¶õ »ç°¢ÇüÀ» ±×¸®´Â°¡?
static const bool bRountRect = false;
// ¸ð¼¸®°¡ µ¿±×¶õ »ç°¢ÇüÀÏ °æ¿ì, ±ïÀ» ¸ð¼¸®ÀÇ ¾ç
static const int MLLB_XCURVE = 10;
static const int MLLB_YCURVE = 10;
void TListBox::MeasureItem(int Index, int &Height)
{
Height = 0;
// ÆøÀ» °è»êÇÒ ¾ÆÀÌÅÛÀÌ ¿Ã¹Ù¸¥ ¾ÆÀÌÅÛÀ̶ó¸é,
// (Index°¡ -1ÀÏ °æ¿ì, ÇöÀç ¸®½ºÆ® ¹Ú½º ¾È¿¡ µé¾î°¡´Â ¾ÆÀÌÅÛÀÌ ¾Æ´Ï´Ù.)
if (Index != -1)
{
// ÇöÀç ¸®½ºÆ® ¹Ú½º ¾ÈÀÇ ÅØ½ºÆ®¸¦ Àоî¿Â´Ù.
string text = Items->Strings[Index].c_str();
// ÇÑ ÇàÀÇ ±âº» ³ôÀ̸¦ °è»êÇÑ´Ù.
TCanvas* pCanvas = Canvas;
int fontHeight = -(pCanvas->Font->Size);
int pitch = (pCanvas->Font->PixelsPerInch);
int cy = (int)((double)(abs(fontHeight * pitch / 72) * LineSpacer) / 100.0);
// ÅØ½ºÆ®¸¦ °Ë»öÇÏ¸é¼ °³Çà ¹®ÀÚ¸¦ ¸¸³ª¸é,
// ¹ÝȯÇÒ ³ôÀÌ¿¡´Ù°¡ ÇÑ ÇàÀÇ ³ôÀ̸¦ ´õÇÑ´Ù.
unsigned int oldpos = 0;
unsigned int pos = 0;
while (oldpos < text.size() && pos < text.size())
{
oldpos = pos;
pos = text.find_first_of(LineSeperator, oldpos);
if (pos == string::npos) pos = text.size();
pos++;
Height += cy; // ÇÑ ÇàÀÇ ³ôÀ̸¦ ´õÇÑ´Ù.
}
Height += cy; // ¸¶Áö¸·À¸·Î Çѹø ´õ ´õÇØÁØ´Ù.
}
else
{
Height = 80; // Á¦´ë·Î µÈ ¾ÆÀÌÅÛÀÌ ¾Æ´Ï¶ó¸é ±×³É 80À»...
}
}
void TListBox::DrawItem(int Index, TRect &Rect, TOwnerDrawState State)
{
// ¸®½ºÆ® ¾ÈÀÇ ¾ÆÀÌÅÛÀÌ ¾Æ´Ï¶ó¸é ¿¡·¯´Ù.
if (Index < 0) return;
// ¹®ÀÚ¿À» Àоî¿Â´Ù.
string text = Items->Strings[Index].c_str();
// ¹®ÀÚ¿ÀÇ ±æÀ̰¡ 0ÀÌ¶óµµ ¿¡·¯´Ù.
if (text.size() == 0) return;
// ¸®½ºÆ® ¹Ú½ºÀÇ Äµ¹ö½º¸¦ ¾ò¾î¿Â´Ù.
TCanvas* pCanvas = Canvas;
/////////////////////////////////////////////////////////
// +------------+
// | |-+ ´ë° ÀÌ·± ¸ð¾çÀ¸·Î µÎ °³ÀÇ
// +------------+ | »ç°¢ÇüÀ» ±×¸°´Ù.
// +------------+
/////////////////////////////////////////////////////////
// ±×¸²ÀÚ¸¦ ±×¸± »ç°¢ÇüÀ» °è»êÇÑ´Ù.
TRect shadow;
shadow.left = Rect.left + 6;
shadow.top = Rect.top + 6;
shadow.right = Rect.right;
shadow.bottom = Rect.bottom;
// ¹àÀº »óÀÚ¸¦ ±×¸± »ç°¢ÇüÀ» °è»êÇÑ´Ù.
TRect light;
light.left = Rect.left + 3;
light.top = Rect.top + 3;
light.right = Rect.right - 3;
light.bottom = Rect.bottom - 3;
// ¸ÕÀú ÇöÀç ¸®½ºÆ® ¹Ú½ºÀÇ ¹è°æ »ö±ò·Î »ç°¢ÇüÀ» ±×¸°´Ù.
// ±×¸®Áö ¾ÊÀ¸¸é, ÀÌÀüÀÇ focus »ç°¢ÇüÀÌ Áö¿öÁöÁö ¾Ê´Â´Ù.
pCanvas->Brush->Style = bsSolid;
pCanvas->Brush->Color = Color;
pCanvas->FillRect(Rect);
// ±×¸²ÀÚ »ç°¢ÇüÀ» ±×¸°´Ù.
pCanvas->Brush->Style = bsSolid;
pCanvas->Brush->Color = ShadowColor;
if (bRountRect)
{
pCanvas->RoundRect(
shadow.left, shadow.top, shadow.right, shadow.bottom,
MLLB_XCURVE, MLLB_YCURVE);
}
else
{
pCanvas->FillRect(shadow);
}
// ¹àÀº(?) »ç°¢ÇüÀ» ±×¸²ÀÚ »ç°¢Çü À§¿¡´Ù ±×¸°´Ù.
pCanvas->Brush->Style = bsSolid;
pCanvas->Brush->Color = TColor(::GetSysColor(COLOR_HIGHLIGHT));
if (State.Contains(odSelected)) pCanvas->Brush->Color = SelectedColor;
else pCanvas->Brush->Color = NormalColor;
if (bRountRect)
{
pCanvas->RoundRect(
light.left, light.top, light.right, light.bottom,
MLLB_XCURVE, MLLB_YCURVE);
}
else
{
pCanvas->FillRect(light);
}
// ¹®ÀÚ¿À» Çϳª¾¿ ±×¸°´Ù.
int fontHeight = -(pCanvas->Font->Size);
int pitch = (pCanvas->Font->PixelsPerInch);
int cy = (int)((double)(abs(fontHeight * pitch / 72) * LineSpacer) / 100.0);
unsigned int oldpos = 0;
unsigned int pos = 0;
unsigned int count = 0;
while (oldpos < text.size() && pos < text.size())
{
oldpos = pos;
pos = text.find_first_of(LineSeperator, oldpos);
if (pos == string::npos) pos = text.size();
pos++;
string substring = text.substr(oldpos, (pos - 1) - oldpos);
Set<TFontStyle, fsBold, fsStrikeOut> FONT_STYLE;
pCanvas->Font->Color = clWindowText;
pCanvas->Font->Style = FONT_STYLE;
TRect textRect;
textRect.left = light.left + 10;
textRect.top = Rect.top + count * cy + 6;
textRect.right = light.right - 20;
textRect.bottom = textRect.top + cy;
DrawText(pCanvas->Handle, substring.c_str(), -1, &textRect,
DT_LEFT | DT_NOPREFIX | DT_END_ELLIPSIS | DT_SINGLELINE | DT_VCENTER |
DrawTextBiDiModeFlagsReadingOnly());
count++;
}
} ¸¶Áö¸·À¸·Î ÆûÀÌ ¸®»çÀÌÁîµÇ¾úÀ» ¶§, ¸®½ºÆ® ¹Ú½º¸¦ »õ·Î ±×·ÁÁà¾ßÇÑ´Ù.
void __fastcall TForm::FormResize(TObject *Sender)
{
ListBox->Invalidate();
}
3 ¼³¸í
º° °Å ¾ø´Ù. MeasureItem À̺¥Æ® Çڵ鷯´Â ½ÇÁ¦·Î ¾ÆÀÌÅÛÀ» ±×¸®±â Àü¿¡ ¾ÆÀÌÅÛÀÌ È¸é¿¡¼ Â÷ÁöÇÒ ³ôÀ̸¦ ¾Ë±â À§Çؼ È£ÃâµÇ´Â ÇÔ¼ö´Ù. DrawItem À̺¥Æ® Çڵ鷯´Â À̸§ ±×´ë·Î ½ÇÁ¦·Î ¾ÆÀÌÅÛÀ» ±×·ÁÁÖ´Â ÇÔ¼ö´Ù.
±×·¯¹Ç·Î MeasureItem À̺¥Æ® Çڵ鷯°¡ È£ÃâµÇ¾úÀ» ¶§, °³Çà ¹®ÀÚÀÇ °¹¼ö¸¦ ÀÌ¿ëÇØ, ¶óÀÎÀÇ ³ôÀ̸¦ Á¤ÇØÁØ ´ÙÀ½, DrawItem ÇÔ¼ö ¾È¿¡¼ °³Çà ¹®ÀÚ¸¦ ±¸ºÐÀÚ·Î ¹®ÀÚ¿µéÀ» ÇÑ ¶óÀξ¿ ³»·ÁÁÖ¸é¼ µû·Î ±×·ÁÁÖ´Â °ÍÀÌ´Ù. ±×¸²ÀÚ »ç°¢ÇüÀ» ±×·ÁÁÖ´Â °ÍÀº ÇÙ½É ±â´É°ú´Â ¾Æ¹« °ü·ÃÀÌ ¾ø°í, ´ÜÁö ¿¬Ãâ(-_-)ÀÏ »ÓÀÌ´Ù.
¿¾³¯¿¡ ®´ø ¼Ò½º´Ù º¸´Ï ÇãÁ¢ÇÏ´Ù. ÇÔ¼ö·Î »©¾ßÇÒ ºÎºÐµµ ±ºµ¥±ºµ¥ º¸À̰í...
VisualCpp·Î ®´ø °É ´Ù½Ã CppBuilder·Î ¿Å±ä °ÍÀε¥, º°·Î °í»ýÇÑ ±â¾ïÀÌ ¾ø´Â °É·Î ºÁ¼´Â ´Ù½Ã VisualCpp ¹öÀüÀ¸·Î µ¹¾Æ°¡´Â °Íµµ º°·Î ¾î·ÆÁö ¾ÊÀ» µí ÇÏ´Ù.
4 ¸µÅ©
SeriousMoin v1 (koMoinMoin 1.0a4 Modified)