이미지를 그리는 방법

이 항목에서는 ImageList_Draw 함수를 사용하여 이미지를 그리는 방법을 보여 줍니다.

알아야 할 사항

기술

필수 구성 요소

  • C/C++
  • Windows 사용자 인터페이스 프로그래밍

지시

이미지를 그리려면 ImageList_Draw 또는 ImageList_DrawEx 함수를 사용합니다. 이미지 목록의 핸들, 그릴 이미지의 인덱스, 대상 디바이스 컨텍스트에 대한 핸들, 디바이스 컨텍스트 내의 위치 및 하나 이상의 그리기 스타일을 지정합니다.

다음 C++ 코드 예제의 사용자 정의 함수는 ImageList_Draw 함수를 사용하여 이미지를 그리고 이미지 경계 사각형의 클라이언트 좌표를 저장합니다. 후속 함수는 경계 사각형을 사용하여 사용자가 이미지를 클릭했는지 여부를 확인합니다.

// DrawTheImage - draws an image transparently and saves 
// the bounding rectangle of the drawn image.
// Returns TRUE if successful, or FALSE otherwise. 
// hwnd - handle to the window in which to draw the image. 
// himl - handle to the image list that contains the image. 
// cx and cy - client coordinates for the upper-left corner of the image. 
// 
// Global variables and constants 
//     g_nImage - index of the image to draw. 
//     g_rcImage - bounding rectangle of the image. 
//     CX_IMAGE and CY_IMAGE - width and height of the image. 
extern int g_nImage; 
extern RECT g_rcImage; 
 
#define CX_IMAGE 32 
#define CY_IMAGE 32 
 
BOOL DrawTheImage(HWND hwnd, HIMAGELIST himl, int cx, int cy) 
{ 
    HDC hdc; 
 
    if ((hdc = GetDC(hwnd)) == NULL) 
        return FALSE; 
    if (!ImageList_Draw(himl, g_nImage, hdc, cx, cy, ILD_TRANSPARENT)) 
        return FALSE; 
    ReleaseDC(hwnd, hdc); 
 
    SetRect(&g_rcImage, cx, cy, CX_IMAGE + cx, CY_IMAGE + cy); 
 
    return TRUE; 
} 

이미지 목록 참조

이미지 목록에 대한

이미지 목록 사용하기