CImageList and CImage question

I want to use an image list with a list control. I am using CImage to load a bitmap file (actually 
several files) like:

CImage image;
image.Load("test.bmp");

How do I add this image to a CImageList, which can then be used by the list control?

-- 
Regards,

Frank
0
JazzedApps (12)
8/29/2007 7:52:04 PM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
804 Views

Similar Articles

[PageSpeed] 23

This looks ugly but seems to be the only way.

CImage image;
image.Load("test.bmp");
CBitmap Bmp;
Bmp.Attach(image.Detach();
m_ImageList.Add(&Bmp,RGB(0,0,0));
Bmp.DestroyObject();

image.Load("test2.bmp");

Bmp.Attach(image.Detach();
m_ImageList.Add(&Bmp,RGB(0,0,0));
Bmp.DestroyObject();
....

AliR.


"Frank S" <JazzedApps@community.nospam> wrote in message 
news:uRIAUYn6HHA.4584@TK2MSFTNGP03.phx.gbl...
>I want to use an image list with a list control. I am using CImage to load 
>a bitmap file (actually several files) like:
>
> CImage image;
> image.Load("test.bmp");
>
> How do I add this image to a CImageList, which can then be used by the 
> list control?
>
> -- 
> Regards,
>
> Frank 


0
AliR3470 (3235)
8/29/2007 8:14:25 PM
Yes, that is ugly, and it would much easier to do

CBitmap Bmp;
bmp.Attach((HBITMAP)::LoadImage(NULL, _T("test.bmp"), IMAGE_BITMAP, 
                                                 0,0, LR_LOADFROMFILE);
if((HBITMAP)bmp != NULL)
      m_ImageList.Add(&Bmp, RGB(0,0,0));
Bmp.DestroyObject();

or better still

BOOL AddImage(LPCTSTR filename, CImageList & imagelist)
   {
    CBitmap Bmp;
    Bmp.Attach( (HBITMAP)::LoadImage(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    if((HBITMAP)Bmp == NULL)
       return FALSE;
    imagelist.Add(&Bmp, RGB(0,0,0));
  }

which makes it easy:
     AddImage(_T("test1.bmp"), imagelist);
     AddImage(_T("test2.bmp"), imagelist);
     CString name = ... name of bitmap file
     AddImage(name, imagelist);

					joe

On Wed, 29 Aug 2007 15:14:25 -0500, "AliR \(VC++ MVP\)" <AliR@online.nospam> wrote:

>This looks ugly but seems to be the only way.
>
>CImage image;
>image.Load("test.bmp");
>CBitmap Bmp;
>Bmp.Attach(image.Detach();
>m_ImageList.Add(&Bmp,RGB(0,0,0));
>Bmp.DestroyObject();
>
>image.Load("test2.bmp");
>
>Bmp.Attach(image.Detach();
>m_ImageList.Add(&Bmp,RGB(0,0,0));
>Bmp.DestroyObject();
>...
>
>AliR.
>
>
>"Frank S" <JazzedApps@community.nospam> wrote in message 
>news:uRIAUYn6HHA.4584@TK2MSFTNGP03.phx.gbl...
>>I want to use an image list with a list control. I am using CImage to load 
>>a bitmap file (actually several files) like:
>>
>> CImage image;
>> image.Load("test.bmp");
>>
>> How do I add this image to a CImageList, which can then be used by the 
>> list control?
>>
>> -- 
>> Regards,
>>
>> Frank 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
8/29/2007 10:28:46 PM
Joseph M. Newcomer wrote:
> Yes, that is ugly, and it would much easier to do
> 
> CBitmap Bmp;
> bmp.Attach((HBITMAP)::LoadImage(NULL, _T("test.bmp"), IMAGE_BITMAP, 
>                                                  0,0, LR_LOADFROMFILE);
> if((HBITMAP)bmp != NULL)
>       m_ImageList.Add(&Bmp, RGB(0,0,0));
> Bmp.DestroyObject();
> 
> or better still
> 
> BOOL AddImage(LPCTSTR filename, CImageList & imagelist)
>    {
>     CBitmap Bmp;
>     Bmp.Attach( (HBITMAP)::LoadImage(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
>     if((HBITMAP)Bmp == NULL)
>        return FALSE;
>     imagelist.Add(&Bmp, RGB(0,0,0));
>   }
> 
> which makes it easy:
>      AddImage(_T("test1.bmp"), imagelist);
>      AddImage(_T("test2.bmp"), imagelist);
>      CString name = ... name of bitmap file
>      AddImage(name, imagelist);
> 
> 					joe
> 
> On Wed, 29 Aug 2007 15:14:25 -0500, "AliR \(VC++ MVP\)" <AliR@online.nospam> wrote:
> 
>> This looks ugly but seems to be the only way.
>>
>> CImage image;
>> image.Load("test.bmp");
>> CBitmap Bmp;
>> Bmp.Attach(image.Detach();
>> m_ImageList.Add(&Bmp,RGB(0,0,0));
>> Bmp.DestroyObject();
>>
>> image.Load("test2.bmp");
>>
>> Bmp.Attach(image.Detach();
>> m_ImageList.Add(&Bmp,RGB(0,0,0));
>> Bmp.DestroyObject();
>> ...
>>
>> AliR.
>>
>>
>> "Frank S" <JazzedApps@community.nospam> wrote in message 
>> news:uRIAUYn6HHA.4584@TK2MSFTNGP03.phx.gbl...
>>> I want to use an image list with a list control. I am using CImage to load 
>>> a bitmap file (actually several files) like:
>>>
>>> CImage image;
>>> image.Load("test.bmp");
>>>
>>> How do I add this image to a CImageList, which can then be used by the 
>>> list control?
>>>
>>> -- 
>>> Regards,
>>>
>>> Frank 
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm

Thanks for the help!

-- 
Regards,

Frank
0
JazzedApps (12)
8/29/2007 10:37:16 PM
Reply:

Similar Artilces:

Several questions
Does any one know if the variouis sets of functions keys can be customozed or moved around. I have a client that uses some from each menu and would like them all together. Any one point me to a good reference on using quickbooks with RMS? Lastly, I have a wine shop that wants to offer a percent value off if customers buy a full case of wine. I can find how to do the buy one get one thing, but any way to do a percentage discount automatically? TIA 1) Search the newsgroup - this has been answered many times - most recently about a week ago... 2) the Knowledge base on PartnerSource/Cus...

XML Linefeed question
Hi I posted this in the wrong ng yesterday, sry. I have my XMLDocument getting digitally signed with elements from my X509Certificate that I locate on the web server. This signing method is getting called by a classic website. The website I am sending this data to is looking a for a particular format of the X509Certificate element, in particular with line breaks intact. I've seen a few examples around the net where the X509Certificate has line breaks...I require this format for my app's receiving end. They say my xmldoc is getting signed ok with all the proper elements, b...

activate question
How do I make a pop up window that does not take activation away from the app? (Like a menu.) Hi, Thanks for your post. I'd like to share the following information with you: 1. A pop-up window is a special type of overlapped window used for dialog boxes, message boxes, and other temporary windows that appear outside an application's main window. When it will be displayed at the top of the window Z-Order. The Z-Order of a window indicates the window's position in a stack of overlapping windows. The window at the top of the z-order overlaps all other windows. The window at ...

question about CImageList
hello! I'm wondering what can be the cause of GDI resource leakage in my app. I have a CListView in the report style and i'm using icons with each of the list items. Firstly I create a CImageList m_ImageList.Create(16, 16, ILC_MASK | ILC_COLORDDB,1,1000); and set it to the list GetListCtrl().SetImageList(&m_ImageList,LVSIL_SMALL); then I retirieve icons from the shell and add them to the image list SHGetFileInfo((LPCTSTR)pFile->GetPath(),0,&pShell,sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_ICON); m_ImageList.Add(pShell.hI...

Smarlist Question
We have 2 company in GP 9. In Smartlist? some of smartlist is not working in company B. Company B smartlist either has no data or showing company A data. How we can fix this need help. -- Buzz Dan GP 9 End USER with lot of confussion This sounds like you have SmartList Builder and custom SmartLists were created for your Company A. Company B was either created later or not taken into account when the SmartLists for Company A were created. At this point, I do not think there is a global way to simply 'fix' them all. Someone needs to go through each of the custom SmartLists...

a compatibility question
is there a utility or some kind of process that will scan my source code and tell me what operating systems my program is compatible with? thanks, ed There may be. Certainly programs like BoundsChecker for Windows have these options. I'm not aware of any static analysis tool, although it would be trivial to write one and incredibly tedious to enumerate the thousands of API calls. joe On Sun, 23 May 2004 17:05:07 GMT, "ed" <cteel04.notthis@hotmail.notthis.com> wrote: >is there a utility or some kind of process that will scan my source code and >tell me what o...

License questions
I have 12 servers will be upgraded to Windows 2003 server. I have 200 users. How any copies and licenses I need to purchase? Besides, I need install Exchange 2003 on two servers. I will have 200 mailbox. How any licenses I need? Is there any website I can get those license infomation? Thanks in advance! Lisa Licensing questions are best answered by your software vendor. Here are some links. Pricing and Licensing for Medium Organizations http://www.microsoft.com/exchange/howtobuy/medium.mspx Exchange Server 2003 Licensing FAQ http://www.microsoft.com/exchange/howtobuy/licensingFAQ.mspx...

pie chart question.....
Please can someone help me with a special pie chart that I need to prepare. The chart will be used as a visual indicator of a sales mix and will be updated over time to show trends. To explain my idea, I will use cars as the example: Let's say that we sell 4 types of car: FORD TOYOTA BMW MERCEDES Overall, I want the pie to represent the total sales value whilst showing the split of sales (% or value label) by make of car, eg FORD etc. In these large slices of the pie, I would like to use a different colour (for each type of car) However, and here (for me, anyway) comes the difficult ...

CImageList
Why should I bother with it? I have an array of CBitmaps, so why should I add them to a CImageList and call draw? What is the benefit? It makes things a little easier coding but still, I would be interested to know why it is not considered a pointless class? "Peter" <peter@peter.com> wrote in message news:eoen6fablzjs.1n8ddxht0mufn.dlg@40tude.net... > Why should I bother with it? I have an array of CBitmaps, so why should I > add them to a CImageList and call draw? What is the benefit? It makes > things a little easier coding but still, I would be interested to ...

CImageList background
Hi, I have a CListControl list bunch of images. I set the list control's image list, like this. m_iList.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR32, 0, 1024); SetImageList(&m_iList, LVSIL_NORMAL); Then I add bitmap to my image list like this: m_iList.Replace(i, &mfcBmp, NULL); The problem is if the actual image is smaller than the image size specify when create the image list, the backgound of the space around the image is black. I want the background be white. So I used pmyImageList->SetBkColor(RGB(255, 255, 255)); But it doesn't help. How can I fix this? ...

Conditional Formatting Question.
I've set up a work evaluation workbook with multiple worksheets. For explanation sake I'll stick with my first worksheet titled "Jan". I have set it up where I have a name column, month column, shift column an various other columns for evaluatin purposes. below the names and under each column I've set up my evaluation formulas. What it does is calculate each column individually and determine the average. (example: absenteeism-it will figure out the average hrs of sick time used by employees that given month) It will also calculate 10% above & below average as well...

Notes question
Hi, I am using Outlook 2002. I am starting to use the Notes option now, but I find that the notes do not stay open when I close Outlook itself. I have another computer with Outlook 2000 on it where the notes will stay open. I'm sure it must be a setting somewhere, I can't seem to find it though. Does anyone have any suggestions. Thanks. ...

XMLSPY Question
Altova posted an announcement regarding XMLSPY 2008 stating it can handle much larger files. So how large is large? Does it load the entire XML document into memory, or does it stream, like xmlreader? I read it has spyware so am reluctant to download the trial version. I did download Stylus Studio and it appears to be a DOM based system. I transform very large xml documents for my clients and some of these files are over 500Mb. I even did noe that was almost 3Gb. I wote some tools with xmlreader/writer that split the files, but requires some hard-coding for each one. sure would be nice to...

Question about saving a layout
I like to zoom all documents I'm working on to 185% in Page View in Microsoft Word for Mac 2004. I'd like this to be the default view when I open any Word documents. How can I save this workspace so every document is opened at 185% zoom? Every time I save my document in this zoom, when I open it again its back to 122% zoom. I've looksed in prefs, but can find no settings. Thanks! Hello Michael, You should find that documents will re-open with the same zoom value you had when you closed them (and the same view, e.g. Page Layout view). To have blank new documents open at 185...

Howto draw CImageList using alpha channel
I am desperately trying to draw images from an imagelist to the screen, using the alpha channel to blend nicely into the background. Alas, I give up, I am totally confused with all the flags and options, having tried out probably all the possible combinations except the one that works :-) Here's my (abbreviated) code: --------- CImageList myImageList; myImageList.Create (24,24,ILC_COLOR32,0,1); CBitmap myBitmap; myBitmap.LoadBitmap (IDB_MYBITMAP); myImageList.Add (&myBitmap, RGB(255,0,255)); CDC dc; dc.Attach (lpDrawItemStruct->hDC); // this comes from the caller myImageLis...

A couple of questions?
Hi! I have a Windows 2003 Server with Exchange 2003 installed. In Exchange 2003 System Manager\Recipients\Recipient Policies\Default policy in E-Mail Addresses (Policy) tab, i have two different @dyndns adresses. So when i create a new user in AD they get both username@dyndns1.com and username@dyndns2.com as e-mail adresses when the "Automatically update e-mail addresses based on recipient policy" is marked. I want to make some users that only use their accounts to log on to OWA and only get one of the @dyndns adresses. But when i unmark "Automatically......." and remove ...

is there any easy way to draw a transparent bitmap by CImageList?
i use the following code to draw transparent bitmaps, it works fine on win2000 or later, but bitmaps have background color on win98. ;-( for(int i = 0; i < m_nRow; ++i) { for(int j = 0; j < m_nCol && i * m_nCol + j < m_nImage; ++j) { CPoint pt; pt.x = j * m_nCellWidth + m_nHInterval / 2; pt.y = i * m_nCellHeight + m_nVInterval / 2; m_pImageList->Draw(pDC, i * m_nCol + j, pt, ILD_NORMAL); } } -- With best regards, Wenming Hu How are you creating the Image List? Can you modify the colour mask depending on the platform, to get what you want? M ...

Password question
How to avoid having to enter password each time opening WLM? Thanks John Tools | Accounts | Mail Account | Servers. Type in the password and check the Remember Password box. -- Bruce Hagen MS-MVP [Mail] Imperial Beach, CA "John Smith" <JohnSmith@nospam.com> wrote in message news:eSHXUnEyKHA.5132@TK2MSFTNGP05.phx.gbl... > How to avoid having to enter password each time opening WLM? > Thanks John Are you talking about the initial prompt for Sign-in? Go to Tools, Options, Connections, "Stop signing in". If you d...

Copy Paste Question
I am new with VBA - is the code below copying from Test1 and Test2 t paste into current spreadsheet?? :confused: Why am I getting an error on this line form the code below. Workbooks.Open Filename:=ar(i) It seems not to see the files I am trying to open???? _____________________________________________________ Sub macro2() ' Dim present_workbook As String Dim ar As Variant ar = Array("D:\Documents and Settings\My Documents\test1.xls ", D:\Documents and Settings\My Documents\test2.xls ") ' all the sprea sheets present_workbook = ActiveWorkbook.Name For i =...

IF funtion question
Hi all, Kindly assist on the following: eg: 10.00 per 1st 5 items, 5.00 per every additional 5 items Thus, if the total is 20 items, then the answer would be 20.00 Pls adv on generating the formula for the above. Thanks in advance. wm.. Is your maths right? =A1-5+10 George Gee "wm" <wm@discussions.microsoft.com> wrote in message news:1D100FC4-7880-436E-B3CD-8302040D2A2A@microsoft.com... > Hi all, > > Kindly assist on the following: > > eg: 10.00 per 1st 5 items, 5.00 per every additional 5 items > Thus, if the total is 20 items, then the answer wou...

document printing question
I have set up an invitation on a 5.5 x 8.5 format, but cannot have the document print without the "centering graphics" (not sure what to call them) that appear when I do a print preview -- DeniseK Are you planning to print two invitations per sheet or is your stock already 5.5 x 8.5? In page setup, landscape, type 5.5 width, 8.5 height. Publisher will say it will print two copies per sheet. If your stock is already 5.5 x 8.5 you must setup your printer for a custom size. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com ...

CImageList::Remove()
Hi, I have a CListCtrl as type icon. I followed a tutorial from codeproject.com to set my own bitmaps as the thumbnail images. This works fine. My problem is that when I delete an item from the list ctrl, any items below it don't shift down, there is just a blank spot where that item used to be. I am doing this: void CMyDlg::DeleteListItem(int nIdx) { m_List.DeleteItem(nIdx); m_ImageList.Remove(nIdx); TRACE("There are now %i images in the list, %i items in the list ctrl...\n", m_List.GetImageCount(), m_ImageList.GetItemCount()); } The TRACE statem...

MSCRM 4
Hi, I recently did an install of CRM 4.0 and started playing around with some of the new features. A couple of things popped out right away that I was wondering if anyone had any luck doing (I fought the same issues in CRM 3.0). A) Adding an image besides a text field that would trigger an action based on data in the text field (have an opportunity record with a voucher field that has an image beside the voucher field, click on the image to do a lookup into a third-party app that is generating the vouchers)? B) Is there a built-in way to create a URL field that does not prepend http:// to ...

Question about MS Office 2004 for Mac
For Office 2004 of Mac version in German (retail version), is it possible to install the Mac version Office on 2 Macs with one product key? Someone I know owns this retail version and there are 3 product keys on the back of the software case. He probably cannot remember which product key is used to activate which Mac. Does anyone have any idea? Thanks. Office will let you re-use the keys to install without a problem, but if you try to launch two networked versions that depend on the same key, it will refuse the launch the second one. This is the US-edition behavior--I doubt it differs for...

Howto draw CImageList using alpha channel (repost)
I am desperately trying to draw images from an imagelist to the screen, using the alpha channel to blend nicely into the background. Alas, I give up, I am totally confused with all the flags and options, having tried out probably all the possible combinations except the one that works :-) Here's my (abbreviated) code: --------- CImageList myImageList; myImageList.Create (24,24,ILC_COLOR32,0,1); CBitmap myBitmap; myBitmap.LoadBitmap (IDB_MYBITMAP); myImageList.Add (&myBitmap, RGB(255,0,255)); CDC dc; dc.Attach (lpDrawItemStruct->hDC); // this comes from the caller myImageLis...