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. lvm_sortitems with no MFC?

lvm_sortitems with no MFC?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialc++jsonquestion
2 Posts 2 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.
  • K Offline
    K Offline
    Kayembi
    wrote on last edited by
    #1

    Hi, I have a custom listbox set up with several columns (file name, file type, size and path), and I want it so that whenever a user clicks on a column header, the items are sorted, just as in Windows Explorer, for instance. The column click part is easy, as I just have this code underneath case WM_NOTIFY: case IDC_LIST1: //CHECK FOR COLUMN CLICK: if(((LPNMHDR)lParam)->code == LVN_COLUMNCLICK) { if(((LPNMLISTVIEW)lParam)->iSubItem == 0) { //need to sort items using LVM_SORTITEMS here... } } However, I have no idea about how to use LVM_SORTITEMS. Obviously, I need to send it using SendDlgItemMessage and use a callback function as it says over on MSDN, but I don't know how to set up the callback function. The problem is that all of the examples I have found are MFC based, but I am _not_ using MFC, just the straight Windows API. Does anybody know where I can find a decent "sort listview items" code example that does not use MFC, or could anybody give me some pointers on how to go about it myself? Many thanks for any help, KB

    D 1 Reply Last reply
    0
    • K Kayembi

      Hi, I have a custom listbox set up with several columns (file name, file type, size and path), and I want it so that whenever a user clicks on a column header, the items are sorted, just as in Windows Explorer, for instance. The column click part is easy, as I just have this code underneath case WM_NOTIFY: case IDC_LIST1: //CHECK FOR COLUMN CLICK: if(((LPNMHDR)lParam)->code == LVN_COLUMNCLICK) { if(((LPNMLISTVIEW)lParam)->iSubItem == 0) { //need to sort items using LVM_SORTITEMS here... } } However, I have no idea about how to use LVM_SORTITEMS. Obviously, I need to send it using SendDlgItemMessage and use a callback function as it says over on MSDN, but I don't know how to set up the callback function. The problem is that all of the examples I have found are MFC based, but I am _not_ using MFC, just the straight Windows API. Does anybody know where I can find a decent "sort listview items" code example that does not use MFC, or could anybody give me some pointers on how to go about it myself? Many thanks for any help, KB

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Kayembi wrote: ...but I don't know how to set up the callback function. It has the following signature: int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort); The MSDN article Q170884 should give you some ideas, even though it's in VB. Basically, each item that is added to the list control has an associated item data (use the LVM_SETITEM message for this). When CompareFunc() is called, lParam1 points to one item's data and lParam2 points to another item's data. You have to cast lParam1 and lParam2 to the appropriate type, and then do some sort of comparision.

      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