°øÅë ÄÁÆ®·Ñ »ç¿ëÇϱâ
À©µµ¿ìÁî(Windows)¸¦ »ç¿ëÇÏ´Ù º¸¸é Ç×»ó º¼ ¼ö ÀÖ´Â ÄÁÆ®·ÑµéÀÌ ÀÖ½À´Ï´Ù. ±×·± °ÍµéÀ» °øÅë ÄÁÆ®·Ñ(Common Control)À̶ó°í ÇÏÁÒ. ¿©±â¼´Â ±×·± ÄÁÆ®·ÑµéÀÇ »ç¿ë¹ý¿¡ ´ëÇØ ÀÍÇôº¸±â·Î ÇÏ°Ú½À´Ï´Ù.
±×·³ ±âº» ÄÁÆ®·ÑÀÇ Á¾·ùºÎÅÍ ¾Ë¾Æº¸ÁÒ. ´ÙÀ½ ±×¸²Àº Visual C++ 6.0 ¿¡¼ ±âº»ÀûÀ¸·Î »ç¿ëÇÏ´Â ÄÁÆ®·ÑµéÀÔ´Ï´Ù. ¹°·Ð »ç¿ëÀÚ°¡ Ãß°¡·Î ocx ÄÁÆ®·Ñ °°Àº °É Ãß°¡ÇÒ ¼öµµ ÀÖÁö¿ä.
±×·³ Çϳª¾¿ »ç¿ë¹ýÀ» ÀÍÇôº¸±â·Î ÇÏÁÒ.
1. ¸®½ºÆ® ¹Ú½º(ListBox)
´ÙÀ̾ó·Î±× º£À̽ºÀÇ ÇÁ·ÎÁ§Æ®¸¦ Çϳª ¸¸µé°í, ´ÙÀ̾ó·Î±× Æû À§¿¡ ¸®½ºÆ® ¹Ú½º 2°³¸¦ ¾Æ·¡À§·Î ³ª¶õÈ÷ ¿Ã·Á³õ½À´Ï´Ù. ±×¸®°í ID´Â °¢°¢ À§ÀÇ ¸®½ºÆ®¹Ú½º¸¦ IDC_LIST1, ¾Æ·¡ÀÇ ¸®½ºÆ®¹Ú½º¸¦ IDC_LIST2 ·Î ÇÏÁÒ.
±×¸®°í ±× ¿·¿¡´Ù ¿¡µðÆ®¹Ú½º¸¦ °¢°¢ Çϳª¾¿ ³õ½À´Ï´Ù. ±× ID´Â IDC_EDIT1, IDC_EDIT2ÀÔ´Ï´Ù.
±×¸®°í´Â OnInitDialog() ÇÔ¼ö¿¡ ´ÙÀ½Ã³·³ Äڵ带 Ãß°¡ÇÕ´Ï´Ù.
BOOL CControlDlg::OnInitDialog()
{
...................
//
TODO: Add extra initialization here
CListBox
*pList = (CListBox *)GetDlgItem(IDC_LIST1);
pList->AddString("¸®½ºÆ®
¹Ú½º ¿¹Á¦");
pList->AddString("ListBox
Sample");
pList->AddString("test1");
pList->AddString("test2");
pList->AddString("test3");
pList->AddString("test4");
pList->AddString("test5");
return
TRUE; // return TRUE unless you set the focus to a control
}
±×¸®°í´Â Ŭ·¡½º À§Àúµå¸¦ ½ÇÇà½ÃÄѼ IDC_LIST1°ú IDC_LIST2 ÀÇ LBN_SELCHANGE ¸Þ½ÃÁö¿¡ ´ëÇÑ Çڵ鷯¸¦ °¢°¢ ´ÙÀ½Ã³·³ ÀÛ¼ºÇÕ´Ï´Ù.
// ¸®½ºÆ® ¹Ú½º1¿¡ º¯µ¿ÀÌ ÀÖÀ» °æ¿ì
void CControlDlg::OnSelchangeList1()
{
// TODO: Add your control
notification handler code here
CString
str;
CListBox *pList1, *pList2;
int
Select;
//
¸®½ºÆ®¹Ú½º1ÀÇ Æ÷ÀÎÅÍ ¾ò±â
pList1
= (CListBox *)GetDlgItem(IDC_LIST1);
//
¸®½ºÆ® ¹Ú½º2ÀÇ Æ÷ÀÎÅÍ ¾ò±â
pList2
= (CListBox *)GetDlgItem(IDC_LIST2);
//
¼±ÅÃµÈ ¾ÆÀÌÅÛÀÇ À妽º¸¦ Select¿¡ ÀúÀå
Select
= pList1->GetCurSel();
//
¼±ÅÃµÈ ¾ÆÀÌÅÛÀÇ À妽º¿¡ ÇØ´çÇÏ´Â ¹®ÀÚ¿À» Àоî¿Í str¿¡ ÀúÀå
pList1->GetText(Select,
str);
//
¸®½ºÆ®¹Ú½º¿¡¼ ¼±ÅÃµÈ ¾ÆÀÌÅÛ »èÁ¦
pList1->DeleteString(Select);
//
¸®½ºÆ®¹Ú½º2¿¡ ¼±ÅÃµÈ ¾ÆÀÌÅÛ Ãß°¡
pList2->AddString(str);
m_Edit1
= pList1->GetCount(); // ¸®½ºÆ®¹Ú½º1ÀÇ ¾ÆÀÌÅÛ °¹¼ö
m_Edit2
= pList2->GetCount(); // ¸®½ºÆ®¹Ú½º2ÀÇ ¾ÆÀÌÅÛ °¹¼ö
UpdateData(FALSE);
}
//
¸®½ºÆ®¹Ú½º2¿¡ º¯µ¿ÀÌ ÀÖÀ» °æ¿ì
void CControlDlg::OnSelchangeList2()
{
// TODO: Add your control
notification handler code here
CString
str;
CListBox *pList1, *pList2;
int
Select;
pList1
= (CListBox *)GetDlgItem(IDC_LIST1);
pList2
= (CListBox *)GetDlgItem(IDC_LIST2);
Select
= pList2->GetCurSel();
pList2->GetText(Select,
str);
pList2->DeleteString(Select);
pList1->AddString(str);
m_Edit1
= pList1->GetCount();
m_Edit2
= pList2->GetCount();
UpdateData(FALSE);
}
ÀÌ ÇÁ·Î±×·¥ÀÇ °á°ú´Â À§ÀÇ ¸®½ºÆ® ¹Ú½º¿¡ ³ª¿À´Â ¹®ÀÚ¿À» ¸¶¿ì½º·Î Ŭ¸¯Çϸé, ±× ¹®ÀÚ¿ÀÌ »èÁ¦µÇ¸é¼ ¾Æ·¡ÂÊÀÇ ¸®½ºÆ® ¹Ú½º¿¡ ±× ¹®ÀÚ¿ÀÌ Ç¥½ÃµÇ´Â °Ì´Ï´Ù. ¹Ý´ëÀÇ °æ¿ìµµ ¸¶Âù°¡ÁöÁÒ. ±×¸®°í ¿¡µðÆ®¹Ú½º¿¡´Â °¢ ¸®½ºÆ® ¹Ú½ºÀÇ ¹®ÀÚ¿ÀÇ °¹¼ö°¡ Ç¥½ÃµÇÁÒ.
´ÙÀ½Àº CListBox Ŭ·¡½ºÀÇ ¸â¹öÇÔ¼öµéÀ» ³ªÅ¸³½ °Ì´Ï´Ù.Construction
CListBox | Constructs a CListBox object. |
Initialization
Create | Creates the Windows list box and attaches it to the CListBox object. |
InitStorage | Preallocates blocks of memory for list box items and strings. |
General Operations
GetCount | Returns the number of strings in a list box. |
GetHorizontalExtent | Returns the width in pixels that a list box can be scrolled horizontally. |
SetHorizontalExtent | Sets the width in pixels that a list box can be scrolled horizontally. |
GetTopIndex | Returns the index of the first visible string in a list box. |
SetTopIndex | Sets the zero-based index of the first visible string in a list box. |
GetItemData | Returns the 32-bit value associated with the list-box item. |
GetItemDataPtr | Returns a pointer to a list-box item. |
SetItemData | Sets the 32-bit value associated with the list-box item. |
SetItemDataPtr | Sets a pointer to the list-box item. |
GetItemRect | Returns the bounding rectangle of the list-box item as it is currently displayed. |
ItemFromPoint | Returns the index of the list-box item nearest a point. |
SetItemHeight | Sets the height of items in a list box. |
GetItemHeight | Determines the height of items in a list box. |
GetSel | Returns the selection state of a list-box item. |
GetText | Copies a list-box item into a buffer. |
GetTextLen | Returns the length in bytes of a list-box item. |
SetColumnWidth | Sets the column width of a multicolumn list box. |
SetTabStops | Sets the tab-stop positions in a list box. |
GetLocale | Retrieves the locale identifier for a list box. |
SetLocale | Sets the locale identifier for a list box. |
Single-Selection Operations
GetCurSel | Returns the zero-based index of the currently selected string in a list box. |
SetCurSel | Selects a list-box string. |
Multiple-Selection Operations
SetSel | Selects or deselects a list-box item in a multiple-selection list box. |
GetCaretIndex | Determines the index of the item that has the focus rectangle in a multiple-selection list box. |
SetCaretIndex | Sets the focus rectangle to the item at the specified index in a multiple-selection list box. |
GetSelCount | Returns the number of strings currently selected in a multiple-selection list box. |
GetSelItems | Returns the indices of the strings currently selected in a list box. |
SelItemRange | Selects or deselects a range of strings in a multiple-selection list box. |
SetAnchorIndex | Sets the anchor in a multiple-selection list box to begin an extended selection. |
GetAnchorIndex | Retrieves the zero-based index of the current anchor item in a list box. |
String Operations
AddString | Adds a string to a list box. |
DeleteString | Deletes a string from a list box. |
InsertString | Inserts a string at a specific location in a list box. |
ResetContent | Clears all the entries from a list box. |
Dir | Adds filenames from the current directory to a list box. |
FindString | Searches for a string in a list box. |
FindStringExact | Finds the first list-box string that matches a specified string. |
SelectString | Searches for and selects a string in a single-selection list box. |
Overridables
DrawItem | Called by the framework when a visual aspect of an owner-draw list box changes. |
MeasureItem | Called by the framework when an owner-draw list box is created to determine list-box dimensions. |
CompareItem | Called by the framework to determine the position of a new item in a sorted owner-draw list box. |
DeleteItem | Called by the framework when the user deletes an item from an owner-draw list box. |
VKeyToItem | Override to provide custom WM_KEYDOWN handling for list boxes with the LBS_WANTKEYBOARDINPUT style set. |
CharToItem | Override to provide custom WM_CHAR handling for owner-draw list boxes which don't have strings. |
- the end of this article -