CImageList에 저장된 그림을 불러오는 방법을 알아보자.
리소스에 그림과 같은 이미지가 있다면.
CImageList m_imgList;
m_imgList.Create(IDB_STATUS, 16, 16, RGB(255,0,255));
와 같이 이미지에서 16 *16 Size의 이미지를 리스트로 불러올 수 있다.
그리고
CListCtrl m_List;
m_List.SetImageList(&m_imgList,LVSIL_SMALL);
리스트 컨트롤에 추가하여 이미지를 사용할 수가 있다.
CImageList에서 있는 16*16 Size의 이미지를 직접 불러와서 사용하는 방법을 알아보자
이미지 리스트에서 이미지를 추출하는 코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | void GetImageFromList(CImageList *lstImages, int nImage, CBitmap *destBitmap){//First we want to create a temporary image list we can manipulate CImageList tmpList; tmpList.Create(lstImages); //Then swap the requested image to the first spot in the list tmpList.Copy( 0, nImage, ILCF_SWAP ); //Now we need to get som information about the image IMAGEINFO lastImage; tmpList.GetImageInfo(0,&lastImage); //Heres where it gets fun //Create a Compatible Device Context using //the valid DC of your calling window CDC dcMem; dcMem.CreateCompatibleDC (GetWindowDC()); //This rect simply stored the size of the image we need CRect rect (lastImage.rcImage); //Using the bitmap passed in, Create a bitmap //compatible with the window DC //We also know that the bitmap needs to be a certain size. destBitmap->CreateCompatibleBitmap (this->GetWindowDC(), rect.Width (), rect.Height ()); //Select the new destination bitmap into the DC we created above CBitmap* pBmpOld = dcMem.SelectObject (destBitmap); //This call apparently "draws" the bitmap from the list, //onto the new destination bitmap tmpList.DrawIndirect (&dcMem, 0, CPoint (0, 0), CSize (rect.Width (), rect.Height ()), CPoint (0, 0)); //cleanup by reselecting the old bitmap object into the DC dcMem.SelectObject (pBmpOld);} |
이미지 리스트에서 이미지를 불러와 메뉴에 이미지를 붙이는 소스
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | if(!bmp[0].GetSafeHandle())//이미지 리스트에 이미지가 담겨 있지 않다면 이미지를 가져온다{ GetImageFromList(&m_imgList,0,&bmp[0]);//Enable GetImageFromList(&m_imgList,1,&bmp[1]);//Run GetImageFromList(&m_imgList,4,&bmp[2]);//Disable GetImageFromList(&m_imgList,5,&bmp[3]);//Break GetImageFromList(&m_imgList,6,&bmp[4]);//Start } if(!m_MenuFunction.GetSafeHmenu()) { m_MenuFunction.CreatePopupMenu(); m_MenuFunction.InsertMenu(MF_BYCOMMAND,MF_STRING,ID_MANUAL_SEQ,"Run Selected Item"); m_MenuFunction.InsertMenu(MF_BYCOMMAND,MF_STRING,WM_SET_ENABLE,"Set Enable Item"); m_MenuFunction.InsertMenu(MF_BYCOMMAND,MF_STRING,WM_SET_SKIP,"Set Disable Item"); m_MenuFunction.InsertMenu(MF_BYCOMMAND,MF_STRING,WM_SET_STOP,"Set Break Point"); m_MenuFunction.InsertMenu(MF_BYCOMMAND,MF_STRING,WM_SET_START,"Set Restart Point"); //가지고 온 이미지를 메뉴에 추가하는 과정 m_MenuFunction.SetMenuItemBitmaps(ID_MANUAL_SEQ,MF_BYCOMMAND,&bmp[1],&bmp[1]); m_MenuFunction.SetMenuItemBitmaps(WM_SET_ENABLE,MF_BYCOMMAND,&bmp[0],&bmp[0]); m_MenuFunction.SetMenuItemBitmaps(WM_SET_SKIP,MF_BYCOMMAND,&bmp[2],&bmp[2]); m_MenuFunction.SetMenuItemBitmaps(WM_SET_STOP,MF_BYCOMMAND,&bmp[3],&bmp[3]); m_MenuFunction.SetMenuItemBitmaps(WM_SET_START,MF_BYCOMMAND,&bmp[4],&bmp[4]); }
|
'개발언어 > c++' 카테고리의 다른 글
| MFC 문자열 배열 상수(#define CString[]),#define 문자열 (1) | 2017.08.15 |
|---|---|
| popup Menu에 OnUpdateUI Event 매크로 시행하기(OnUpdateUI for popup menu) (0) | 2017.08.10 |
| CMenu에 Image 추가하기 (0) | 2017.08.09 |
| 소스 수정(편집)과 동시에 파일 적용(Visual Studio) apply code changes (0) | 2017.08.09 |
| ON_UPDATE_COMMAND_UI_RANGE(사용자 UI갱신매크로) (0) | 2017.08.09 |