CListCtrl/CImageList. Redraw causes images to load incorrectly.

I have a derived class of CListCtrl that has a CImageList member
variable along with a member function called DrawImageList() that is
meant to dynamically build an image list from paths that are contained
in a column. It works when the dialog is initialized, however when I
add something to the listctrl(which then calls DrawImageList) the
ordering of the images is unpredicatable. This is thoroughly confusing
for me....

void CMyListCtrl::DrawImageList()
{
    //Clean out the current image list and create a new one
    //based on whats currently in the list control
    SetRedraw(FALSE);
    
    m_myImageList.Detach();       //try to detach. delete etc...
    m_myImageList.DeleteImageList();
    m_myImageList.Create(	GetSystemMetrics(SM_CXSMICON), 
        GetSystemMetrics(SM_CYSMICON), 
        ILC_COLOR24|ILC_MASK, 0, 150);
    
    
//The following reports that there are indeed 0 images in the list
//and that the list has some amount of images, say 15.
    TRACE(_T("There are %d images\n"),m_myImageList.GetImageCount());
    TRACE(_T("There are %d list items\n"),GetItemCount());
    
    
    m_myImageList.SetBkColor(RGB(255, 255, 255));
    TCHAR szBuffer[MAX_PATH];
    DWORD cchBuf(MAX_PATH);
    CString csTemp;
    
    LVITEM lvi;
    
    for(int i = 0; i < GetItemCount();  i++)
    {	
        HICON* pMyIcon= new HICON;
        lvi.iItem = i;
        lvi.iSubItem = 1; //this is the column the path is in
        lvi.mask = LVIF_TEXT;
        lvi.iImage = i;
        lvi.pszText = szBuffer;
        lvi.cchTextMax = cchBuf;
        GetItem(&lvi);
        csTemp = szBuffer;

        //Extract the icon from the filepath(this works)
        ExtractIconEx(csTemp,0, NULL, pMyIcon,1));
        
        if(0 != *pMyIcon)
        {
            int nIdx = m_myImageList.Add(*pMyIcon);
            ASSERT(nIdx!=-1);
//The trace seems to indicate that its going well
     TRACE(_T("%s should be at %d with image index of %d \n"),csTemp,
i,nIdx);
        }
        else
        {
//there is no icon so load my default icon
            int nIdx =   
m_myImageList.Add(AfxGetApp()->LoadIcon(IDI_BLANKICON));
            ASSERT(nIdx!=-1);
            TRACE(_T("BLANK IMAGE %s should be at %d with image index
of %d \n"),csTemp, i,nIdx);
            
        }
        delete pMyIcon;
    }
//    Now set my CListCtrl::SetImageList to set it to this image list.
    SetImageList(&m_myImageList,LVSIL_SMALL);	
    
    Invalidate();
    UpdateWindow();	
    SetRedraw(TRUE);
    
}
0
alant (3)
7/16/2003 10:21:21 PM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
747 Views

Similar Articles

[PageSpeed] 30

On 16 Jul 2003 15:21:21 -0700, alant@voicebox.com (AT) wrote in
<3474d950.0307161421.5d314e49@posting.google.com>:

>I have a derived class of CListCtrl that has a CImageList member
>variable along with a member function called DrawImageList() that is
>meant to dynamically build an image list from paths that are contained
>in a column. It works when the dialog is initialized, however when I
>add something to the listctrl(which then calls DrawImageList) the
>ordering of the images is unpredicatable.

Do you mean that the images are not matched with the correct items in
the list?

>This is thoroughly confusing for me....

One big red flag - you're not checking the return values of the
functions you call for possible errors.  You should.

>void CMyListCtrl::DrawImageList()
>{
>    //Clean out the current image list and create a new one
>    //based on whats currently in the list control
>    SetRedraw(FALSE);
>    
>    m_myImageList.Detach();       //try to detach. delete etc...
>    m_myImageList.DeleteImageList();

I'd reverse the two lines above.  You can't delete an image list if
one isn't attached to the class instance.

>    m_myImageList.Create(	GetSystemMetrics(SM_CXSMICON), 
>        GetSystemMetrics(SM_CYSMICON), 
>        ILC_COLOR24|ILC_MASK, 0, 150);
>    
>    
>//The following reports that there are indeed 0 images in the list
>//and that the list has some amount of images, say 15.
>    TRACE(_T("There are %d images\n"),m_myImageList.GetImageCount());
>    TRACE(_T("There are %d list items\n"),GetItemCount());
>    
>    
>    m_myImageList.SetBkColor(RGB(255, 255, 255));
>    TCHAR szBuffer[MAX_PATH];
>    DWORD cchBuf(MAX_PATH);
>    CString csTemp;
>    
>    LVITEM lvi;
>    
>    for(int i = 0; i < GetItemCount();  i++)
>    {	
>        HICON* pMyIcon= new HICON;
>        lvi.iItem = i;
>        lvi.iSubItem = 1; //this is the column the path is in
>        lvi.mask = LVIF_TEXT;
>        lvi.iImage = i;
>        lvi.pszText = szBuffer;
>        lvi.cchTextMax = cchBuf;
>        GetItem(&lvi);
>        csTemp = szBuffer;
>
>        //Extract the icon from the filepath(this works)
>        ExtractIconEx(csTemp,0, NULL, pMyIcon,1));

This function extacts icons only from .exe and .dll files, according
to the docs.  If that's what you're displaying, then you're okay
(although you said "paths").  You might also look at SHGetFileInfo().

Note that the docs also specify that the icons returned by this
function must be destroyed with a call to DestroyIcon().  I don't see
that in your code and I can't tell if the call to DeleteImageList()
will do that, but I wouldn't bet on it.

[snip rest]

-- 
Charles Calvert             |  Software Design/Development
Celtic Wolf, Inc.           |  Project Management
http://www.celticwolf.com/  |  Technical Writing
(703) 580-0210              |  Research
0
cbciv (23)
8/15/2003 3:27:11 AM
Reply:

Similar Artilces:

Bad GetHashCode cause difficult serialize
I overloaded GetHashCode in my object, and was based on some properties. Well it ended up a bug in my data. While serializing to XML: I had an exception due to the data, and it raise a mscorelib error "argument out of range". Bad error message, I finally kept digging farther in the exception and found it... good reminded to always catch exceptions yourself... Anyway, Thought may save some one some time. Schneider ...

incorrect totals using rounded numbers
Formula for col. H is =SUM(C8*F8) where C8 is a dollar amt with 2 decimal pts. and F8 is a figure formatted as "custom" but is actually a percentage displayed as 0.1234567 (7 decimal pts.) The result displays as a dollar amount with 2 decimal points. All is well UNTIL I total column H, using =SUM(H8:H20). The total is off 2 cents! Apparently it is not totaling the figures displayed as currency with 2 decimal points, but rather the unrounded results of of the formula "=sum(C8*F8). How do I correct this??? -- Alexis http://www.mcgimpsey.com/excel/pennyoff.html -- Re...

Callouts fire incorrectly for some entities
Hi, For some Entities (SalesOrder, Quote and likely others) update callouts fire when opening the record in the MS Crm Application. Obviously that is not expected behavior. Only if changes were made to the record in question and subsequently saved would one expect a callout. If anyone has found any documentation on this bug, or figured out a workaround, please could you post it here? Best Regards Thomas Scheelhardt ...

Incorrect cash balance in an investment account
First off, thanks for all of the help on the Ameritrade money market issue. Cal, if you can help me with this one i'll be immensely grateful - it's the most vexing Money problem i've come across and frankly it undermines my ability to make much use of Money currently. Here's my problem: I download transactions for several RBC Dain Rauscher accounts that i have. Over time i've made a number of transfers between my various RBC accounts as well between my RBC accounts and other accounts (most notably my savings account). At various points, when i've downloaded tran...

How to load a picture (not BMP) being in Resources of the project
Hello. How to load a picture (not BMP) being in Resources of the project as Custom in CImage. Thus not keeping it on HDD. HRSRC src = FindResource (AfxGetInstanceHandle (), MAKEINTRESOURCE (IDR_DIALOGJPG), "IMAGE"); int nSize = SizeofResource (AfxGetInstanceHandle (), src); HGLOBAL hRaw = LoadResource (AfxGetInstanceHandle (), src); IStream* pStream = NULL; ULONG n; void* pData = GlobalLock (hRaw); CreateStreamOnHGlobal (hRaw, TRUE, &pStream); img. Load (pStream); FreeResource (hRaw); After this code I have exception. How to be? Depends. If you keep your .exe on your har...

Cache, Applicatin and Load Balanced servers
We can use Session to store data and have it accessible on every server in our farm when we use StateServer or SQL Server for Session. What about Application and Cache object in Load Balanced scenario? Can they be share in any way between servers? I think not, but maybe I'm wrong? 3P wrote: > We can use Session to store data and have it accessible on every server > in our farm when we use StateServer or SQL Server for Session. > > What about Application and Cache object in Load Balanced scenario? Can > they be share in any way between servers? I think not, bu...

how to load MFC-DLL from a non-MFC application?
Hi, I have a DLL which has MFC dialog. And I have an application which is running ATL. how can the application use the dialog box from the MFC-DLL? Regards, Tony I am not sure what you are asking here. Is your application which wants to use this DLL in the same process as the DLL? You can use ATL and MFC together in the same app without any issues. -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo.com "Tony" <tonyl@micro.com> wrote in message news:uXq1YFfnDHA.2068@TK2MSFTNGP09.phx.gbl... | Hi, | | I have a DLL which has MFC dialog. And I have an application which i...

Problem w/ Outlook Loading
Does anyone know a solution for the following error message when trying to open Outlook 2002? Error Message - Unable to open your default e-mail folders Please help!!! Usually this occurs when you are not really hitting the server. Are you accessing Outlook or OWA? Is this on a LAN, through VPN or through the 'net? Did you authenticate? "anonymous@discussions.microsoft.com" wrote: > Does anyone know a solution for the following error > message when trying to open Outlook 2002? > > Error Message - Unable to open your default e-mail folders > > Please h...

Redraw part of my dialog
Hi, I have a dialog based application. I open a second dialog from the first. On the second when I hit a certain key I have to open the notepad. Everything works fine but when I close the notepad the part of the dialog that was covered by the notepad isn't "refreshed propely" (I have a background bitmap and a listbox over it, I can see the bitmap in the listbox area that was covered by the notepad). How can I do it ? thanks in advance Stefano Malavasi __________________________________________________________________________________________ Email: s_malavasi_REMOVE_@_R...

Still can't load Publisher
Dear "replytonewsgroup@goaway.com" and John G, I've obviously confused you both by using the word "disk" to refer to the CD-ROM that Office came on. Perhaps it's regional to refer to a CD as a "disk" (as in, "Load disks 1 thru 3 of MSOffice), but I apologize for the confusion it caused you both, thinking I meant "hard disk". This morning, I took the advice of "replytonewsgroup@goaway.com" and upgraded to SR-3. This did indeed load some DLLs to my hard drive, but as you can see in this link: http://www.improventures.com/p...

Scroll position of a CListCtrl
Hi, Could somebody please tell me how to obtain the horizontal scroll position of a CListCtrl. I've tried to obtain it through CWnd::OnHScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar ) but it gives the "nPos" only when the scrolling is done by dragging the scroll bar. 'nPos' returns 0 (zero) when the scrolling is done by clicking on the arrows. Thank you. Probably what your seeing is a scroll message with the code SB_LEFT or SB_RIGHT which indicates that the scroll bar is at the minimum (far left) or maximum (far right) position, in which case you just n...

What causes #######
What causes ####### to display into infinity. I know normally when this happens it means the column width is not correct, but what I am getting is one that auto colmn resizing has no effect on. The cell causing the problem is E5 it is formatted Custom h:mm with the formula =D4-C5 D5 and C5 is formatted General and when a value is entered such as 845 it changes to 8:45:00 AM with a fomat of Custom h:mm:ss AM/PM I do not want the formatting of D5 or C5 to be altered as it is very convient to enter 845 to display the time for example. Anyone got some idea what is happening h...

CListCtrl #8
Hello all What is the best way to hide columns (per user selection) for a list control. I see that I can delete a column, but if the user where to later decide they wanted to see the column again I imagine there would be a horrendous amount of processing to get the data back into the column Thank you Dan One way is to set the column's width to zero using the SetColumnWidth() member function. -- Cheers Check Abdoul [VC++ MVP] ----------------------------------- "Dan" <anonymous@discussions.microsoft.com> wrote in message news:AE4A3F18-7CEE-4E3A-B864-57AFEF3FA2D...

Image Writer
I was advised to use Image Writer as a default versatile printer in Publisher to create PostScript files and PDFs. Image Writer is supposed to be available under Add Printers/Generic, but the only Generic printer on my system is "Generic / Text Only." Can something be downloaded from somewhere? Jim, What version Publisher? Look on the Publisher disk. I simply don't know why it isn't on your computer. I've had it on my computer since time began so I assumed it was a Windows thing, after looking around I have concluded it is a Publisher driver. -- Mary Sauer MS M...

Outlook received time incorrect
Hi, I've set my machine's timezone according to Microsoft's instructions: http://support.microsoft.com/default.aspx/kb/914387 I can send an email to myself at 9:00, and it'll be shown in "sent items" as sent at 9:00. But, my Inbox will display the email as if it was sent at 10:00. When viewing the mail, it specifies that it was sent at 9:00. So my problem is that for some reason, although the mail contains information that it was sent at 9:00, outlook's inbox displays it at 10:00. Note: all my calendar items are displayed correctly, and my calender options dis...

incorrect date conversion in excel 2003
hi, consider the following date problem, i have 2 programs. one that ceates test results using a date field. this is exported to excel 2002, but in excel 2003 strange things happen. the dates in 'test' and 2002 are correct test 2002 2003 DD-MM-YYYY DD-MM-YYYY 01-06-1998 01-06-1998 06-01-1998* 10-11-1998 10-11-1998 11-10-1998* 25-12-1998 25-12-1998 25-12-1998 As you can see the *dates in 2003 are in MM-DD-YY format, while the last date in 2003 is correct. What is the problem here, help please. Joske Hi question is HOW do you export nthe dates to Excel. -- Regards Frank Kabel ...

Linking Cells across sheets to be mirror images
Hey all=). I'm not sure my title makes sense, so let me go into further detail. Lets say you have a large report of data, in which you copy lines out of to a new sheet, in the same workbook. So now you can work on this single item, without all the other info, but instead of having to go back to the main sheet once I am finished and find that line again, is there a way, to link the cells, so that whatever you type into your new cells, will update the cells of origin? ...

loading photo from publisher into jpeg format web page
hi all, first time here. i need help in loading a publisher photo (s) into my new web page (yahoo) that only accepts photos in the jpeg format it seems? would appreciate any help. thanks What format are you trying to use? Most if not all Publisher photos are .jpg. Bring the image into a paint program (MS Paint will suffice) and convert it to .jpg. www.irfanview.com is free and a wonderful little viewer that will convert the image. Get the plug-ins too, some formats need them. -- Mary Sauer MS MVP http://office.microsoft.com/ http://www.mvps.org/msauer/ news://msnews.microsoft.com "d...

Set Height Property of image control
I've tried to set the image height of an image control in the OnOpen code: Me.ctlImage.Height = 1.193 * Me.ctlImage.Width such that it will conform to the aspect ratio of images to be displayed. The assignment statement didn't have any affect. With a debug stop after the statement, neither the height or width show any value. What do I need to do here to set the Height property of the image control? Thanks, Bill I see I need to do two things. One is that the width needs to be obtained with the ImageWidth property. And two, that I need to deal with these quantities being in twi...

Redrawing a treeitem
In a CTreeView a treeitem (A) will be drawn in black. Then I draw several treeitems (B, C, D) that have (A) as their parent using different colors (red, blue, black) depending on 'something'. Now I would like to redraw (A) if a subtreeitem has been colored red, or blue if no subtreeitem has been colored red. I would like to REDRAW rather than to find out first if (A) has to be colored as it is MUCH easier to do this afterwards because B,C and D have to find out what color they should use at the moment of drawing. So I would like to know if it is possible to redraw a particular treeite...

Images and thumbnails questions
Hello-- I am running XP Pro, with Access 2007. I have several folders, each with hundreds of image files-- most of these are photo .tifs. I would like to make a database that contains the file names and key information about each file (date it was taken, what it is a picture of, etc.). I want this database to be searchable by users, who will be prompted to enter criteria for specific attributes ("The photo(s) you are looking and from what year(s)? _____________"); users must be able to answer in plain language-- the users cannot be required to enter any code or any...

imp...histogram showing incorrect value
i am makign an histogram chart. teh x axis has values from 0-70 and y axis has values from 1-31 (why its starting from 1 i am unable to make out) the range shoudl ideally start from 0. so my problem is that the minimum value is 7.9 but my histogram shows be 8.9 .. why is this so and i how to resolve this. if i try and change the format axis for Y where its written: value (Y) axis crosses at category number: 1 if i change from 1 to 0 then it gives me an error: the number must be between 1 and 31999. try again by entering a number in this range. thanks in advance monika In XL, each x-ax...

How can I scan images into seperate worksheets at once?
I am trying to use my scanner to insert documents into excel. When I do it, it adds all the images into one sheet that overlap each other. How can I get excel to add each image to its own worksheet? jwewing23 wrote: > I am trying to use my scanner to insert documents into excel. When I do it, > it adds all the images into one sheet that overlap each other. How can I get > excel to add each image to its own worksheet? What I do is scan into a file, then run that file through OCR software and then that data goes into Excel. But then I want data I can manipulate with Excel -- I&...

Using TaskDialogIndirect is Causing an Access Violation in MFC
When trying to use TaskDialogIndirect with a callback in MFC, the application performs an access violation in wincore.cpp on line 425. This is using VisualStudio 2005 SP1 with Vista updates. "6XGate" <6XGate@discussions.microsoft.com> wrote in message news:A136A6FD-0AD0-472C-B5B1-9217D1B48A34@microsoft.com... > When trying to use TaskDialogIndirect with a callback in MFC, the > application > performs an access violation in wincore.cpp on line 425. > > This is using VisualStudio 2005 SP1 with Vista updates. Show your code and the callstack when it crashes. ...

OWA fails to load emails; Exchweb Virtual dir loses subfolders.
Windows Server 2003 Exchange 2003 Standard SP1 IIS 6.0 I have been having problems with OWA since I took over this companies network, but this one has me stumped. Any help would be appreciated! I believe the server has been used for all sorts of things since its been installed by the previous admin, so its not a "vanilla" system. Background -This server used to be a DC, (with Exchange on) but has been demoted to ease its load. Have since found out MS don't advise an Exchange demotion! -OWA is externally published from the Exchange server through ISA 2004 using Forms based...