Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Any ideas on updating CListCtrl icon in separate thread ?

Any ideas on updating CListCtrl icon in separate thread ?

Scheduled Pinned Locked Moved C / C++ / MFC
helpdatabaseperformancetutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Miroslav Rajcic
    wrote on last edited by
    #1

    I am having a virtual list control which can load a large number of file items. I have noticed that main speed issue here is file icon calculation, so I created the separate thread to calculate icon index in background. But, my problem is following: - how to communicate changes between the threads (I used to PostMessage for each calculated icon, but this was slowing down my icon thread enormously) - how to add icon calculations priority (if the user scrolls to the bottom of the list, those icons must be calculated first) I welcome any good idea or code pointer. Thanks in advance. Miroslav Rajcic

    H P 2 Replies Last reply
    0
    • M Miroslav Rajcic

      I am having a virtual list control which can load a large number of file items. I have noticed that main speed issue here is file icon calculation, so I created the separate thread to calculate icon index in background. But, my problem is following: - how to communicate changes between the threads (I used to PostMessage for each calculated icon, but this was slowing down my icon thread enormously) - how to add icon calculations priority (if the user scrolls to the bottom of the list, those icons must be calculated first) I welcome any good idea or code pointer. Thanks in advance. Miroslav Rajcic

      H Offline
      H Offline
      Hesham Amin
      wrote on last edited by
      #2

      PostMessage blocks the calling thread untill the window you sent the message processes it.. try SendMessage..

      M 1 Reply Last reply
      0
      • H Hesham Amin

        PostMessage blocks the calling thread untill the window you sent the message processes it.. try SendMessage..

        M Offline
        M Offline
        Miroslav Rajcic
        wrote on last edited by
        #3

        I think the oposite is the truth :) Miroslav Rajcic

        H 1 Reply Last reply
        0
        • M Miroslav Rajcic

          I am having a virtual list control which can load a large number of file items. I have noticed that main speed issue here is file icon calculation, so I created the separate thread to calculate icon index in background. But, my problem is following: - how to communicate changes between the threads (I used to PostMessage for each calculated icon, but this was slowing down my icon thread enormously) - how to add icon calculations priority (if the user scrolls to the bottom of the list, those icons must be calculated first) I welcome any good idea or code pointer. Thanks in advance. Miroslav Rajcic

          P Offline
          P Offline
          peterchen
          wrote on last edited by
          #4

          You will probably need to "batch" the updates (e.g. load 10 icons, then update) anyway. Then, PostMessage is not an issue. You could call InvalidateRect from the worker thread, causing a new LVN_GETDISPINFO in the main thread (and they'd batch nicely). However, I see no chance to get the icon rect without stalling the main thread. You might use this for better prformance if the list is in Report Mode, though. (You need to invalidate the entire icon "column") I'm not sure if you need to set call SetImageList again after adding icons to it. Just try it, and don't if you don't need to. You probably need to keep a separate tracking file / icon, and track which icons are already loaded. in the LVN_GETDISPINFO handler, specify an empty / dummy icon id when it's not yet loaded. To prioritize: Share a variable iNextFileIndexToProcess, between the two threads, indicating the index in the list of the file who's icon is next to load. If an icon is already loaded, just skip to the next. If you arrive at the end of the list, start with the first one again. (You need a separate indicator that you have loaded all icons. e.g. break on iIconsLoaded == iFilesInList) Add a handler for WM_HSCROLL, where you set the iNextFileIndexToProcess to the first displayed item (LVM_GETTOPINDEX) This is just a rough outline, but I believe it's good ;)


          Those who not hear the music think the dancers are mad.  [sighist] [Agile Programming]

          M 1 Reply Last reply
          0
          • P peterchen

            You will probably need to "batch" the updates (e.g. load 10 icons, then update) anyway. Then, PostMessage is not an issue. You could call InvalidateRect from the worker thread, causing a new LVN_GETDISPINFO in the main thread (and they'd batch nicely). However, I see no chance to get the icon rect without stalling the main thread. You might use this for better prformance if the list is in Report Mode, though. (You need to invalidate the entire icon "column") I'm not sure if you need to set call SetImageList again after adding icons to it. Just try it, and don't if you don't need to. You probably need to keep a separate tracking file / icon, and track which icons are already loaded. in the LVN_GETDISPINFO handler, specify an empty / dummy icon id when it's not yet loaded. To prioritize: Share a variable iNextFileIndexToProcess, between the two threads, indicating the index in the list of the file who's icon is next to load. If an icon is already loaded, just skip to the next. If you arrive at the end of the list, start with the first one again. (You need a separate indicator that you have loaded all icons. e.g. break on iIconsLoaded == iFilesInList) Add a handler for WM_HSCROLL, where you set the iNextFileIndexToProcess to the first displayed item (LVM_GETTOPINDEX) This is just a rough outline, but I believe it's good ;)


            Those who not hear the music think the dancers are mad.  [sighist] [Agile Programming]

            M Offline
            M Offline
            Miroslav Rajcic
            wrote on last edited by
            #5

            Thank you for your effort. Your coments have been very valuable. I'll try them and see. Miroslav Rajcic

            1 Reply Last reply
            0
            • M Miroslav Rajcic

              I think the oposite is the truth :) Miroslav Rajcic

              H Offline
              H Offline
              Hesham Amin
              wrote on last edited by
              #6

              Yes..Miroslav I checkd it and I was wrong.. thank you.. :)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups