¼ÒÀ¯ÀÚ°¡ ±×¸° ¸ñ·Ï »óÀÚ ¸¸µé±â

´ÙÀ½ ¿¹Á¦¿¡¼­´Â ¼ÒÀ¯ÀÚ°¡ ±×¸° Ç׸ñ 5 °³¸¦ Æ÷ÇÔ ÇÏ´Â ¸ñ·Ï »óÀÚ¸¦ ±×¸³´Ï´Ù: 4 °³ÀÇ µå·ÎÀ× ±¸Çö ¹× Æ÷Å©. °¢ ¸ñ·Ï Ç׸ñ ºñÆ®¸Ê °³Ã¼ÀÇ À̸§À¸·Î Ç¥½Ã µË´Ï´Ù. ´ÜÃß´Â ´Ù¸¥ »ç¶÷µé ó·³ µÇÁö ¾ÊÀº Ç׸ñÀ» Çϳª ¼±Åà ¹¯´Â. ¼±ÅÃÇÑ Æ÷Å©¿Í ¹öÆ°À» ¼±Åà "¸Â¾Æ!" ¸Þ½ÃÁö¸¦ Ç¥½Ã ÇÏ °í ´ëÈ­ »óÀÚ¸¦ ´Ý½À´Ï´Ù. "´Ù½Ã ½Ãµµ!" ¸Þ½ÃÁö°¡ Ç¥½Ã µË´Ï´Ù ´Ù¸¥ ¸ñ·Ï Ç׸ñ ¼±Åà ¹öÆ°À» ¼±ÅÃ.

¸ñ·Ï »óÀÚ Ç¥ÁØ ¸ñ·Ï »óÀÚ ½ºÅ¸ÀÏ ¿Ü¿¡ LBS_OWNERDRAW ¹× LBS_HASSTRINGS ½ºÅ¸ÀÏÀ» ÇÏ°íÀÖ´Ù. ÄÚµå ÅؽºÆ®¸¦ ¼³Á¤ ÇÏ·Á¸é LB_ADDSTRING ¸Þ½ÃÁö¸¦ Àü¼Û ÇÏ ¿© ¸ñ·Ï »óÀÚ¸¦ ÃʱâÈ­ ÇÏ °í °¢ ¸ñ·Ï »óÀÚ Ç׸ñ ºñÆ®¸ÊÀ» ¿¬°áÇÒ LB_SETITEMDATA ¸Þ½ÃÁö¸¦ º¸³À´Ï´Ù. ÄÚµå´Â ¶ÇÇÑ WM_MEASUREITEM ¸Þ½ÃÁö¸¦ ó¸® ÇÏ ¿© °¢ ¸ñ·Ï »óÀÚ Ç׸ñÀÇ ³ôÀÌ ¼³Á¤ ÇÏ °í WM_DRAWITEM ¸Þ½ÃÁö¸¦ ó¸® ÇÏ ¿© ÅؽºÆ® ¹× °¢ Ç׸ñ¿¡ ´ë ÇÑ ºñÆ®¸ÊÀ» ±×¸³´Ï´Ù.

#define XBITMAP 80 
#define YBITMAP 20 
 
#define BUFFER MAX_PATH 
 
HBITMAP hbmpPencil, hbmpCrayon, hbmpMarker, hbmpPen, hbmpFork; 
HBITMAP hbmpPicture, hbmpOld; 
 
void AddItem(HWND hwnd, LPSTR lpstr, HBITMAP hbmp) 
{ 
    int nItem; 
 
    nItem = SendMessage(hwndList, LB_ADDSTRING, 0, lpstr); 
    SendMessage(hwndList, LB_SETITEMDATA, nItem, hbmp); 
} 
 
DWORD APIENTRY DlgDrawProc( 
        HWND hDlg,            // window handle to dialog box 
        UINT message,         // type of message 
        UINT wParam,          // message-specific information 
        LONG lParam) 
{ 
    int nItem; 
    TCHAR tchBuffer[BUFFER]; 
    HBITMAP hbmp; 
    HWND hListBox; 
    TEXTMETRIC tm; 
    int y; 
    HDC hdcMem; 
    LPMEASUREITEMSTRUCT lpmis; 
    LPDRAWITEMSTRUCT lpdis; 
    RECT rcBitmap; 
 
    switch (message) 
    { 
 
        case WM_INITDIALOG: 
 
            // Load bitmaps. 
 
            hbmpPencil = LoadBitmap(hinst, MAKEINTRESOURCE(700)); 
            hbmpCrayon = LoadBitmap(hinst, MAKEINTRESOURCE(701)); 
            hbmpMarker = LoadBitmap(hinst, MAKEINTRESOURCE(702)); 
            hbmpPen = LoadBitmap(hinst, MAKEINTRESOURCE(703)); 
            hbmpFork = LoadBitmap(hinst, MAKEINTRESOURCE(704)); 
 
            // Retrieve list box handle. 
 
            hListBox = GetDlgItem(hDlg, IDL_STUFF); 
 
            // Initialize the list box text and associate a bitmap 
            // with each list box item. 
 
            AddItem(hListBox, "pencil", hbmpPencil); 
            AddItem(hListBox, "crayon", hbmpCrayon); 
            AddItem(hListBox, "marker", hbmpMarker); 
            AddItem(hListBox, "pen",    hbmpPen); 
            AddItem(hListBox, "fork",   hbmpFork); 
 
            SetFocus(hListBox); 
            SendMessage(hListBox, LB_SETCURSEL, 0, 0); 
            return TRUE; 
 
        case WM_MEASUREITEM: 
 
            lpmis = (LPMEASUREITEMSTRUCT) lParam; 
 
            // Set the height of the list box items. 
 
            lpmis->itemHeight = 20; 
            return TRUE; 
 
        case WM_DRAWITEM: 
 
            lpdis = (LPDRAWITEMSTRUCT) lParam; 
 
            // If there are no list box items, skip this message. 
 
            if (lpdis->itemID == -1) 
            { 
                break; 
            } 
 
            // Draw the bitmap and text for the list box item. Draw a 
            // rectangle around the bitmap if it is selected. 
 
            switch (lpdis->itemAction) 
            { 
                case ODA_SELECT: 
                case ODA_DRAWENTIRE: 
 
                    // Display the bitmap associated with the item. 
 
                    hbmpPicture =(HBITMAP)SendMessage(lpdis->hwndItem, 
                        LB_GETITEMDATA, lpdis->itemID, (LPARAM) 0); 
 
                    hdcMem = CreateCompatibleDC(lpdis->hDC); 
                    hbmpOld = SelectObject(hdcMem, hbmpPicture); 
 
                    BitBlt(lpdis->hDC, 
                        lpdis->rcItem.left, lpdis->rcItem.top, 
                        lpdis->rcItem.right - lpdis->rcItem.left, 
                        lpdis->rcItem.bottom - lpdis->rcItem.top, 
                        hdcMem, 0, 0, SRCCOPY); 
 
                    // Display the text associated with the item. 
 
                    SendMessage(lpdis->hwndItem, LB_GETTEXT, 
                        lpdis->itemID, (LPARAM) tchBuffer); 
 
                    GetTextMetrics(lpdis->hDC, &tm); 
 
                    y = (lpdis->rcItem.bottom + lpdis->rcItem.top - 
                        tm.tmHeight) / 2; 
 
                    TextOut(lpdis->hDC, 
                        XBITMAP + 6, 
                        y, 
                        tchBuffer, 
                        strlen(tchBuffer)); 
 
                    SelectObject(hdcMem, hbmpOld); 
                    DeleteDC(hdcMem); 
 
                    // Is the item selected? 
 
                    if (lpdis->itemState & ODS_SELECTED) 
                    { 
                        // Set RECT coordinates to surround only the 
                        // bitmap. 
 
                        rcBitmap.left = lpdis->rcItem.left; 
                        rcBitmap.top = lpdis->rcItem.top; 
                        rcBitmap.right = lpdis->rcItem.left + XBITMAP; 
                        rcBitmap.bottom = lpdis->rcItem.top + YBITMAP; 
 
                        // Draw a rectangle around bitmap to indicate 
                        // the selection. 
 
                        DrawFocusRect(lpdis->hDC, &rcBitmap); 
                    } 
                    break; 
 
                case ODA_FOCUS: 
 
                    // Do not process focus changes. The focus caret 
                    // (outline rectangle) indicates the selection. 
                    // The IDOK button indicates the final 
                    // selection. 
 
                    break; 
            } 
            return TRUE; 
 
        case WM_COMMAND: 
 
            switch (LOWORD(wParam)) 
            { 
                case IDOK: 
                    // Get the selected item's text. 
 
                    nItem = SendMessage(GetDlgItem(hDlg, IDL_STUFF), 
                       LB_GETCURSEL, 0, (LPARAM) 0); 
                       hbmp = SendMessage(GetDlgItem(hDlg, IDL_STUFF), 
                            LB_GETITEMDATA, nItem, 0); 
 
                    // If the item is not the correct answer, tell the 
                    // user to try again. 
                    //
                    // If the item is the correct answer, congratulate 
                    // the user and destroy the dialog box. 
 
                    if (hbmp != hbmpFork) 
                    { 
                        MessageBox(hDlg, "Try again!", "Oops", MB_OK); 
                        return FALSE; 
                    } 
                    else 
                    { 
                        MessageBox(hDlg, "You're right!", 
                            "Congratulations.", MB_OK); 
 
                      // Fall through. 
 
                    } 
 
                case IDCANCEL: 
 
                    // Destroy the dialog box. 
 
                    EndDialog(hDlg, TRUE); 
                    return TRUE; 
 
                default: 
 
                    return FALSE; 
            } 
 
        case WM_DESTROY: 
 
            // Free any resources used by the bitmaps. 
 
            DeleteObject(hbmpPencil); 
            DeleteObject(hbmpCrayon); 
            DeleteObject(hbmpMarker); 
            DeleteObject(hbmpPen); 
            DeleteObject(hbmpFork); 
 
            return TRUE; 
 
        default: 
            return FALSE; 
 
    } 
    return FALSE; 
} 
 

 

Index