- ³»ºÎ¿¡¼ÀÇ µå·¡±×&µå¶ø ó¸®Çϱâ
- ¿ÜºÎ¿¡¼ÀÇ ÆÄÀÏ µå·¡±×&µå¶ø ó¸®Çϱâ
- PerformanceGraph
- XMLDocument »ç¿ë¹ý
- TreeView »óÀÇ ¸ðµç ³ëµå Ⱦ´ÜÇϱâ
- TreeNode ¾ÆÀÌÄÜ ¼³Á¤Çϱâ
- Ä¿¸Çµå ¶óÀÎ Àμö ¾ò±â
- RichEdit ÄÁÆ®·Ñ ³»ºÎÀÇ ¹®ÀÚ¿ ºü¸£°Ô ġȯÇϱâ
- Virtual ListView »ç¿ëÇϱâ
- Memo, RichEdit ÄÄÆ÷³ÍÆ®¿¡¼ ƯÁ¤ ¶óÀÎ ¼±ÅÃÇϱâ
- CppWebBrowser »ç¿ëÇϱ⠻ùÇÃ
- ListBox °¡·Î½ºÅ©·Ñ Çϱâ
- ´Ù¼öÀÇ ÄÁÆ®·Ñ ÇѲ¨¹ø¿¡ À̸§ Á¤Çϱâ
- StringGrid ¼¿ ¼±Åýà ÇÏÀ̶óÀÌÆ® ¸·±â
- ListView Ä÷³ Æø ÀÚµ¿ Á¶ÀýÇϱâ
- ListView ¾ÈÀÇ ¾î´À ¾ÆÀÌÅÛÀ» Ŭ¸¯Çß´ÂÁö ¾Ë¾Æ³»±â
- ListView ÆùÆ® Ä®¶ó ¹Ù²Ù±â
- TRichEdit, TMemo¿¡¼ ½ºÅ©·Ñ¹Ù°¡ Ç×»ó ÃÖÇÏÀ§¿¡ À§Ä¡ÇÏ°Ô Çϱâ
1 ³»ºÎ¿¡¼ÀÇ µå·¡±×&µå¶ø ó¸®Çϱâ
OnStartDrag, OnDragOver, OnEndDrag À̺¥Æ®¸¦ Àß Ã³¸®ÇØÁÖ¸é ³¡. ´Ü Æû ³»ºÎ¿¡ ÄÁÆ®·ÑÀÌ Çϳª ¹Û¿¡ ¾ø´Â °ÍÀÌ ¾Æ´Ï¹Ç·Î, ¾î´À ÄÁÆ®·Ñ¿¡¼ µå·¡±×¸¦ ½ÃÀÛÇß°í, ÇöÀç ¾î´À ÄÁÆ®·Ñ À§¿¡ ¿Í ÀÖ´À³Ä¸¦ Àß Ã³¸®ÇؾßÇÑ´Ù.
void __fastcall OnStartDrag(
TObject *Sender, TDragObject *&DragObject)
{
// ÇöÀç ¾î¶² ¾ÆÀÌÅÛÀÌ ¼±ÅõǾú´Â°¡¸¦
// ÄÁÆ®·ÑÀÇ Á¾·ù¿¡ µû¶ó ±â¾ïÇØµÐ´Ù.
}
void __fastcall OnDragOver(
TObject *Sender, TObject *Source,
int X, int Y, TDragState State, bool &Accept)
{
// Sender´Â ÇöÀç ¸¶¿ì½º Ä¿¼°¡ ¿Ã¶ó°¡ÀÖ´Â ÄÁÆ®·Ñ.
// Source´Â µå·¡±×°¡ ½ÃÀÛµÈ ÄÁÆ®·Ñ.
//
// »ó´ç¼öÀÇ ÄÁÆ®·ÑµéÀÌ HitTest ÇÔ¼ö¸¦ °¡Áö°í Àִµ¥
// À̸¦ ÀÌ¿ëÇØ ÇØ´çÇÏ´Â µå·¡±×¸¦ ó¸®ÇØÁÙÁö ¸»Áö¸¦ ÆÇ´ÜÇÑ´Ù.
// Accept º¯¼ö¸¦ false·Î ÇÏ¸é µå·¡±× 󸮸¦ ¸·À» ¼ö ÀÖ´Ù.
}
void __fastcall OnEndDrag(TObject *Sender, TObject *Target,
int X, int Y)
{
// Sender´Â µå·¡±×°¡ ½ÃÀÛµÈ ÄÁÆ®·Ñ.
// TargetÀº µå·¡±×°¡ ³¡³ ÄÁÆ®·Ñ.
//
// ÁÂÇ¥¸¦ ÀÌ¿ëÇØ ÃÖÁ¾ÀûÀ¸·Î ¾îµð¿¡ µå·¡±×Ç߳ĸ¦ ÆÇ´ÜÇÑ ´ÙÀ½
// ÇØ´çÇϴ ó¸®¸¦ ÇØÁÖ¸é µÈ´Ù.
}
2 ¿ÜºÎ¿¡¼ÀÇ ÆÄÀÏ µå·¡±×&µå¶ø ó¸®Çϱâ
ÇÁ·Î±×·¥ ¿ÜºÎ¿¡¼ ÆÄÀÏÀ» ²ø¾î´Ù Æû À§¿¡ ³õ´Â °æ¿ì¸¦ ó¸®ÇÏ·Á¸é, WM_DROPFILES ÇÔ¼ö¸¦ °¡·Îä¾ßÇÑ´Ù. ´ëºÎºÐÀÇ ÄÄÆ÷³ÍÆ®¿¡ ÇØ´çÇÏ´Â À̺¥Æ® Çڵ鷯°¡ ³ëÃâµÇ¾î ÀÖÁö ¾ÊÀ¸¹Ç·Î ¼ºêŬ·¡½ÌÀ» ÇØ¾ßÇÑ´Ù.
TWndMethod OriginalProc = Component->WndProc; // ¿ø·¡ ÇÁ·Î½ÃÁ®¸¦ ±â·ÏÇØµÐ´Ù.
Component->WndProc = ConsumeComponentMessage; // »õ·Î¿î ÇÁ·Î½ÃÁ®¸¦ ´ëÀÔ
...
// ¸Þ½ÃÁö ó¸®ÇÔ¼ö
MESSAGE void __fastcall ConsumeComponentMessage(TMessage& Message)
{
if (Message.Msg == WM_DROPFILES)
{
HDROP hDrop = (HDROP)Message.WParam;
char FileName[1024] = {0,};
// 3¹øÂ° ÀÎÀÚ¸¦ NULL·Î ³Ñ±â¸é ÆÄÀÏÀÇ °¹¼ö¸¦ ¹ÝȯÇÑ´Ù.
int Count = ::DragQueryFile(hDrop, 0xFFFFFFFF, NULL, MAX_PATH);
for (int i=0; i<Count; ++i)
{
// i¹øÂ° ÆÄÀÏ À̸§À» ¹Þ¾Æ¿Â´Ù.
DragQueryFile(hDrop, i, FileName, MAX_PATH);
// ÀÌ ½ÃÁ¡¿¡¼ FileName ¹è¿¿¡´Â ÇØ´çÇÏ´Â
// ÆÄÀÏ ¶Ç´Â µð·ºÅ丮ÀÇ À̸§ÀÌ µé¾î°¡ÀÖ°Ô µÈ´Ù.
// ¹º°¡ ¿øÇÏ´Â ÀÛ¾÷À» ÇÏ¸é µÇ°Ú´Ù.
}
// ¿ë¹«°¡ ³¡³µÀ¸¸é »èÁ¦ÇØÁØ´Ù.
DragFinish((HDROP)Message.WParam);
}
else
{
OriginalProc(Message); // WM_DROPFILES ¿Ü¿¡´Â ¿ø·¡ Çڵ鷯·Î ó¸®ÇÑ´Ù.
}
}
3 PerformanceGraph
4 XMLDocument »ç¿ë¹ý
- Active ÇÁ·ÎÆÛƼ¸¦ true·Î ¼³Á¤ÇØÁÖ´Â °ÍÀ» ÀØÁö ¸»ÀÚ.
- DocumentElement ÇÁ·ÎÆÛƼ´Â XML ÃÖ»óÀ§ ³ëµå¸¦ ³ªÅ¸³½´Ù. ±âº»ÀûÀ¸·Î »ý¼ºµÇÁö ¾ÊÀ¸¹Ç·Î µû·Î »ý¼ºÇØÁà¾ßÇÑ´Ù. LoadFrom... ÇÔ¼ö¸¦ »ç¿ëÇØ¼ Æ®¸®¸¦ ±¸¼ºÇÏ´Â °æ¿ì¿¡´Â ³»ºÎÀûÀ¸·Î »ý¼ºÇØÁֹǷΠÇÊ¿ä¾ø´Ù.
- ÆÄÀÏ¿¡´Ù XML ¹®¼¸¦ ·ÎµåÇÏ´Â µ¥¿¡´Â LoadFromFile ÇÔ¼ö¸¦ ÀÌ¿ëÇÏ¸é µÇ°í, ÀúÀåÇÏ´Â µ¥¿¡´Â SaveToFile ÇÔ¼ö¸¦ ÀÌ¿ëÇÏ¸é µÈ´Ù.
- ÀÚ½Ä ³ëµå¸¦ ¾×¼¼½ºÇϱâ À§Çؼ´Â ChildNodes ÇÁ·ÎÆÛƼ¸¦ ÀÌ¿ëÇÑ´Ù. ÀÌ ÇÁ·ÎÆÛƼ´Â ¸®½ºÆ® Çü½ÄÀÇ Ä÷º¼Ç Ŭ·¡½º¸¦ ¹ÝȯÇϴµ¥, VCL Ŭ·¡½ºµéÀÇ ´ëºÎºÐÀÌ ±×·¸µíÀÌ Count º¯¼ö¸¦ ÀÌ¿ëÇØ Ⱦ´ÜÇÒ ¼ö ÀÖ´Ù.
IXMLNode* pRoot = XMLDocument->DocumentElement;
IXMLNodeList* pChildren = pRoot->ChildNodes;
for (int i=0; i<pChildren->Count; i++)
{
IXMLNode* pChild = pChildren->Nodes[i];
...
} Nodes ÇÔ¼ö°¡ ¹Þ¾ÆµéÀÌ´Â ÀÎÀÚ°¡ OLE Variant ÇüÀ̱⠶§¹®¿¡, ¹®ÀÚ¿À» ÀÌ¿ëÇØ¼ ÀÚ½Ä ³ëµå¿¡ Á¢±ÙÇÏ´Â °Íµµ °¡´ÉÇÏ´Ù. ¹®ÀÚ¿Àº ´ç¿¬È÷(?) ÅÂ±× À̸§ÀÌ´Ù.
IXMLNode* pChild = pChildren->Nodes[AnsiString("NodeName")]; - ³ëµåÀÇ ¼Ó¼º(attribute)¸¦ ¾×¼¼½ºÇϱâ À§Çؼ´Â Attributes ÇÁ·ÎÆÛƼ¸¦ ÀÌ¿ëÇÑ´Ù. ÀÌ ¶ÇÇÑ OLE Variant ÇüÀ» ÀÌ¿ëÇϱ⠶§¹®¿¡ ÆíÇÏ°Ô »ç¿ëÇÒ ¼ö ÀÖ´Ù.
AnsiString StringAttr = pNode->Attributes[AnsiString("MyString")];
int IntAttr = pNode->Attributes[AnsiString("MyInt")];
pNode->Attributes[AnsiString("MyString")] = "Test";
pNode->Attributes[AnsiString("MyInt")] = 33; - ÀúÀåÇÒ ¶§ ÀÎÄÚµùÀ» ÁöÁ¤Çϱâ À§Çؼ´Â Encoding ÇÁ·ÎÆÛƼ¸¦ ÀÌ¿ëÇÑ´Ù. "euc-kr" Àß ¸Ô´Â´Ù.
- ¸ðµç ÀÚ½Ä ³ëµåµéÀ» »èÁ¦Çϱâ À§Çؼ´Â ´ÙÀ½°ú °°ÀÌ ÇÏ¸é µÈ´Ù.
IXMLNode* pRoot = XMLDocument->DocumentElement;
if (pRoot != NULL)
{
pRoot->ChildNodes->Clear();
}
5 TreeView »óÀÇ ¸ðµç ³ëµå Ⱦ´ÜÇϱâ
¿¡µðÆ® ÄÁÆ®·Ñ »óÀÇ ÅØ½ºÆ®¿Í °°Àº ÅØ½ºÆ®¸¦ °¡Áö´Â ³ëµå¸¦ ã¾Æ¼ Æ÷Ä¿½ÌÇϱâ
TTreeNode* pItem = TreeView->Items->GetFirstNode();
while (pItem)
{
if (pItem->Text.AnsiPos(Edit->Text.UpperCase()) != 0)
{
pItem->MakeVisible();
pItem->Selected = true;
pItem->Focused = true;
break;
}
pItem = pItem->GetNext();
}
6 TreeNode ¾ÆÀÌÄÜ ¼³Á¤Çϱâ
TTreeView ÄÁÆ®·Ñ¿¡´Ù°¡ À̹ÌÁö ¸®½ºÆ®¸¦ ºÙÀÎ ÈÄ¿¡, °¢°¢ÀÇ ³ëµåÀÇ ImageIndex °ªÀ» ¼³Á¤ÇÏ¸é µÈ´Ù. ¿©±â¼ ÁÖÀÇÇØ¾ßÇÒ °ÍÀº SelectedIndexµµ °°ÀÌ ¼³Á¤ÇÏÁö ¾ÊÀ¸¸é, ÇØ´çÇÏ´Â ³ëµå¸¦ ¼±ÅÃÇÏ´Â °æ¿ì ¾ÆÀÌÄÜÀÌ Äá°¡·ç°¡ µÈ´Ù´Â Á¡ÀÌ´Ù.
TTreeNode* pNode = TreeView->Items->Add(NULL, "test");
pNode->ImageIndex = 0;
pNode->SelectedIndex = 0;
7 Ä¿¸Çµå ¶óÀÎ Àμö ¾ò±â
¹®¼¸¦ ½ÇÇà ÆÄÀÏ ´ÜÃà ¾ÆÀÌÄÜ¿¡´Ù ²ø¾î´Ù ³õ¾ÒÀ» ¶§, ÇØ´ç ¹®¼¸¦ ¿±â À§Çؼ´Â Ä¿¸Çµå ¶óÀÎÀ» ÀÌ¿ëÇØ¾ß ÇÑ´Ù.
ÇÁ·ÎÁ§Æ®À̸§.cpp ÆÄÀÏ, Áï WinMain ÇÔ¼ö°¡ ÀÖ´Â ÆÄÀÏÀ» ¿¾îº¸¸é WinMain ÇÔ¼ö ¼¼¹øÂ° ÀÎÀÚ·Î ¹®ÀÚ¿À» ¹Þ´Â °ÍÀ» ¾Ë ¼ö ÀÖ´Ù. ¹®Á¦´Â ÀÌ ¹®ÀÚ¿ÀÌ ÅëÂ¥ ¹®ÀÚ¿À̶ó´Â Á¡ÀÌ´Ù. Àû´çÈ÷ ÆÄ½ÌÇØ¼ »ç¿ëÇØ¾ßÇÑ´Ù.
8 RichEdit ÄÁÆ®·Ñ ³»ºÎÀÇ ¹®ÀÚ¿ ºü¸£°Ô ġȯÇϱâ
ÇÙ½ÉÀº ¹®ÀÚ¿ÀÇ »çº»À» ¸¸µéÁö ¾Ê´Â °ÍÀÌ´Ù. ·çÇÁ ³»ºÎ¿¡¼ RichEdit ÄÁÆ®·ÑÀÇ Text ÇÁ·ÎÆÛƼ¸¦ °Çµå¸®´Â °ÍÀº ¸Å¹ø ¹®ÀÚ¿ÀÇ »çº»À» ¸¸µé°Ô µÇ¹Ç·Î ÁÖÀÇÇØ¾ßÇÑ´Ù.
void __fastcall Selection(
const AnsiString& start, const AnsiString& end, TRichEdit *re)
{
TSearchTypes options;
int pos = re->FindText(start, 0, re->GetTextLen(), options);
if( pos == -1 )
{
ShowMessage("Ein unbekannter Fehler ist aufgetreten...");
return;
}
re->Lines->BeginUpdate();
try
{
int pos;
do
{
re->SelStart = pos;
re->SelLength = start.Length();
re->SelText = end;
pos += end.Length();
pos = re->FindText(start, pos, re->GetTextLen()-pos, options);
}
while(pos != -1);
}
__finally
{
re->Lines->EndUpdate();
}
}
void __fastcall FindeText(const String& a, const String& b, TRichEdit* re)
{
frmMain->Progress->Position = 0;
frmMain->Progress->Max = re->GetTextLen();
TSearchTypes options;
re->Lines->BeginUpdate();
try
{
int pos = re->FindText(a, 0, re->GetTextLen(), options);
while( pos != -1 )
{
re->SelStart = pos;
re->SelLength = a.Length();
re->SelText = b;
frmMain->Progress->Position = pos;
frmMain->Progress->Update();
pos += b.Length();
pos = re->FindText(a, pos, re->GetTextLen()-pos, options);
}
}
__finally
{
re->Lines->EndUpdate();
frmMain->Progress->Position = 0;
}
frmMain->txtSuchen->Text = a;
frmMain->txtErsetzen->Text = b;
}
void __fastcall StrReplace(
const AnsiString &search, const AnsiString& replace, TRichEdit *re)
{
re->Text = StringReplace(
re->Text, search, replace, TReplaceFlags() << rfReplaceAll);
} ù¹øÂ° ¹æ¹ýÀÌ Á¦ÀÏ ºü¸£´Ù.
9 Virtual ListView »ç¿ëÇϱâ
TListView´Â ¾ÆÀÌÅÛ °¹¼ö°¡ ¸¹¾ÆÁö¸é O(N)À¸·Î ¼Óµµ°¡ ¶³¾îÁø´Ù. ¾ÆÀÌÅÛÀÌ ¸®½ºÆ® Çü½ÄÀ¸·Î µé¾î°¡Àֱ⠶§¹®¿¡, ƯÁ¤ À§Ä¡ÀÇ ¾ÆÀÌÅÛ µ¥ÀÌÅ͸¦ Àоî¿Í ȸ鿡 ±×·Á¾ßÇÏ´Â °æ¿ì, ÀÌ ¸®½ºÆ®¸¦ ¼±ÇüÀ¸·Î °Ë»öÇØ¾ßÇÏ´Ï ´À¸± ¼ö ¹Û¿¡ ¾ø´Ù.
Ç¥½ÃÇØ¾ßÇÒ ¾ÆÀÌÅÛÀÌ ¾ÆÁÖ ¸¹Àº °æ¿ì, VirtualListView¸¦ »ç¿ëÇØ¾ßÇÑ´Ù. "°¡»ó"À̶ó°í ÇØ¼ ¹º°¡ Ưº°ÇÑ °ÍÀº ¾Æ´Ï°í, ´ÜÁö µ¥ÀÌÅÍ °ü¸®¸¦ »ç¿ëÀÚ°¡ ÇØÁÙ »ÓÀÌ´Ù. ÀÏ´Ü ListViewÀÇ OwnerData ¼Ó¼ºÀ» true·Î ¼³Á¤ÇØÁÖ°í, OnData À̺¥Æ® Çڵ鷯¸¦ ¿À¹ö¶óÀ̵åÇØÁÖ¸é µÈ´Ù. ¾Æ·¡´Â º¼·£µå ´º½º±×·ì¿¡¼ ±Ü¾î¿Â °£´ÜÇÑ »ùÇÃÀÌ´Ù.
#include <vector>
struct MyInfo
{
AnsiString Caption;
int SomeValue;
// other stuff you want to include...
};
struct MyCustomSort
{
const DWORD Column;
MyCustomSort(const DWORD ColumnIndex) : Column(ColumnIndex) {}
operator bool (const MyInfo& lhs, const MyInfo& rhs) const
{
switch( Column )
{
case 0:
return (lhs.Caption < rhs.Caption);
case 1:
return (lhs.SomeValue < rhs.SomeValue);
//...
}
return false;
}
};
std::vector<MyInfo> MyData;
__fastcall TForm1::TForm1(TComponent *Owner)
: TForm(Owner)
{
//...
MyData.reserve(100);
for(unsigned i = 0; i < 100; ++i)
{
// fill MyData as needed...
MyInfo &Info = MyData[i];
Info.Caption = i;
Info.SomeValue = i;
//...
}
ListView1->Items->Count = 100;
//...
}
void __fastcall TForm1::ListView1ColumnClick(TObject* Sender, TListColumn* Column)
{
AnsiString OldStatus = StatusBar1->SimpleText;
StatusBar1->SimpleText = (OldStatus + " - Sorting ..");
StatusBar1->Update();
std::sort(MyData.begin(), MyData.end(),
MyCustomSort(Column->Index));
ListView1->Invalidate();
StatusBar1->SimpleText = OldStatus;
}
void __fastcall TForm1::ListView1Data(TObject *Sender, TListItem *Item)
{
Item->Caption = MyData[Item->Index].Caption;
if( Item->SubItems->Count > 0 )
Item->SubItems->Strings[0] = MyData[Item->Index].SomeValue;
else
Item->SubItems->Append(MyData[Item->Index].SomeValue);
// add in the other values as needed...
}
10 Memo, RichEdit ÄÄÆ÷³ÍÆ®¿¡¼ ƯÁ¤ ¶óÀÎ ¼±ÅÃÇϱâ
// ÇØ´ç ¶óÀÎÀ¸·Î Ä¿¼¸¦ À̵¿
int start = RichEdit1->Perform(EM_LINEINDEX, LineNumber-1, 0);
// ¶óÀÎÀÇ ±æÀ̸¦ ¾Ë¾Æ³½´Ù.
int end = (start + RichEdit1->Perform(EM_LINELENGTH, start, 0));
// ¶óÀÎÀ» ¼±ÅÃÇÑ´Ù.
RichEdit1->Perform(EM_SETSEL, start, end);
CHARRANGE range;
range.cpMin = RichEdit1->Perform(EM_LINEINDEX, LineNumber-1, 0);
range.cpMax = (range.cpMin + RichEdit1->Perform(EM_LINELENGTH,range.cpMin, 0));
RichEdit1->Perform(EM_SETSEL, 0, reinterpret_cast<int>(&range));
11 CppWebBrowser »ç¿ëÇϱ⠻ùÇÃ
CppWebBrowser1->GoHome();
CppWebBrowser1->GoForward();
CppWebBrowser1->GoBack();
WideString tempURL = "http://www.osakac.ac.jp/";
BSTR URL;
URL = BSTR(tempURL);
CppWebBrowser1->Navigate(URL);
CppWebBrowser1->Refresh();
// HTML ¼¼À̺êÇϱâ
void __fastcall TForm1::Button6Click(TObject *Sender)
{
TVariant *in;
TVariant *out;
CppWebBrowser1->QueryStatusWB(Shdocvw_tlb::OLECMDID_SAVEAS);
CppWebBrowser1->ExecWB(
Shdocvw_tlb::OLECMDID_SAVEAS,Shdocvw_tlb::OLECMDEXECOPT_DODEFAULT,in,out);
}
12 ListBox °¡·Î½ºÅ©·Ñ Çϱâ
When setting up the forms at runtime, send the ListBox a LB_SETHORIZONTALEXTENT message specifying the maximum viewable width. The OS will then automatically handle displaying the horizontal scroll bar when appropriate:
ListBox1->Perform(LB_SETHORIZONTALEXTENT, ListBox1->Width, 0);
Why this isn't handled automatically by Windows, or exposed as a property in the VCL, I have no idea.
13 ´Ù¼öÀÇ ÄÁÆ®·Ñ ÇѲ¨¹ø¿¡ À̸§ Á¤Çϱâ
(I'm supposing all buttons are children of the same component and the buttons are named BitBtn1, BitBtn2,...,BitBtn100.)
Use the FindChildControl method of the buttons' parent.
TBitBtn* btn;
for (int i=1; i<=100; i++)
{
AnsiString name = "BitBtn" + IntToStr(i); // "BitBtn1", "BitBtn2", ...
btn = dynamic_cast <TBitBtn*> (BitBtn1->Parent->FindChildControl(name));
if (btn)
{
btn->Caption = "New &Caption";
}
}
14 StringGrid ¼¿ ¼±Åýà ÇÏÀ̶óÀÌÆ® ¸·±â
You need to use the Selection property for that:
TGridRect gr;
gr.Left = gr.Top = gr.Right = gr.Bottom = -1;
StringGrid1->Selection = gr;
15 ListView Ä÷³ Æø ÀÚµ¿ Á¶ÀýÇϱâ
This function will correctly adjust column widths every time you call it.
void General_AutoSizeTListViewColumns( TListView * ListView )
{
for (int index=0;
index<ListView->Columns->Count;
++index )
{
ListView->Columns->Items[ index ]->Width=ColumnTextWidth;
ListView->Columns->Items[ index ]->Width=ColumnHeaderWidth;
}
}
16 ListView ¾ÈÀÇ ¾î´À ¾ÆÀÌÅÛÀ» Ŭ¸¯Çß´ÂÁö ¾Ë¾Æ³»±â
Use the OnMouseDown/Up event instead. Inside that handler, call the GetHitTestInfoAt() method of the ListView to find out where exactly the user is clicking. If the return value of GetHitTestInfoAt() contains the htOnStateIcon value, then use the GetItemAt() method to get the item and use it's Checked property as needed.
For example:
void __fastcall TForm1::ListView1MouseDown(
TObject* Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
THitTests ht = ListView1->GetHitTestInfoAt(X, Y);
if(ht.Contains(htOnStateIcon))
{
TListItem *item = ListView1->GetItemAt(X, Y);
if(item)
// use item->Checked as needed
}
}
17 ListView ÆùÆ® Ä®¶ó ¹Ù²Ù±â
TListView has a Font property for that. If that is not good enough for your needs, then you will need to instead use one of the TListView's On...Draw events to draw each list item yourself, then you can anipulate the TListView's Canvas anyway you want.
As an example (and there are lines you can leave commented out, or comment in as desired to experiment with)
void __fastcall TForm1::ListView1CustomDrawSubItem(
TCustomListView *Sender, TListItem *Item, int SubItem,
CustomDrawState State, bool& DefaultDraw)
{
DefaultDraw = true;
// choose columns to act upon
// exit if not first subitem column
if (SubItem != 1) return;
// you could also just use ListView1 here
TListView *ListView = static_cast<TListView*>(Sender);
if (ListView)
{
// extract the bounding rectangle of the subitem
RECT R = {LVIR_BOUNDS, SubItem, 0, 0};
SNDMSG(ListView->Handle, LVM_GETSUBITEMRECT,
Item->Index,reinterpret_cast<LPARAM>(&R));
// change rectangle size if desired...
// InflateRect(&R, -1, -1);
TCanvas *LVCanvas = ListView->Canvas;
HDC Hdc = LVCanvas->Handle;
// render a rectangle in/on perimeter of R if desired...
// LVCanvas->Brush->Color = clWindow;
// LVCanvas->Rectangle(R.left, R.top, R.right, R.bottom);
// change rectangle size if desired...
// InflateRect(&R, -LVCanvas->Pen->Width, -LVCanvas->Pen->Width);
// TColor OldColor=LVCanvas->Brush->Color; // save original canvas brush color
LVCanvas->Brush->Color = clRed; // set new canvas brush color
// fill the rectangle
LVCanvas->FillRect(R); // fill 100% (adjust R.right otherwise)
// get the text currently in the subitem
AnsiString text(Item->SubItems->Strings[SubItem-1]);
// COLORREF x=GetTextColor(Hdc); // save original text color
// int y=GetBkMode(Hdc); // save original background mix mode
SetBkMode(Hdc, TRANSPARENT);
SetTextColor(Hdc, ColorToRGB(clYellow)); // set new text color
// render the text in rectangle R with various attributes
DrawText(Hdc, text.c_str(), text.Length(),
&R, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
// LVCanvas->Brush->Color=OldColor; // restore color
// SetTextColor(Hdc, x); // restore text color
// SetBkMode(Hdc, y); // restore background mix mode
// tell Windows we drew the item manually
DefaultDraw = false;
}
}
18 TRichEdit, TMemo¿¡¼ ½ºÅ©·Ñ¹Ù°¡ Ç×»ó ÃÖÇÏÀ§¿¡ À§Ä¡ÇÏ°Ô Çϱâ
Memo1->SelStart = Memo1->GetTextLen();
Memo1->Perform(EM_SCROLLCARET, 0, 0);
Àß ¾È µÉ ¶§´Â À§¾Æ·¡·Î Focus °ü·Ã Äڵ带 Áý¾î³Ö¾îº¸±æ ¹Ù¶õ´Ù.
Memo1->SetFocus();
Memo1->SelStart = Memo1->GetTextLen();
Memo1->Perform(EM_SCROLLCARET, 0, 0);
OriginalControl->SetFocus();
SeriousMoin v1 (koMoinMoin 1.0a4 Modified)