Controlling a ListView

The place for programming-related topics.
Post Reply
WoF
Lt. Commander
Posts: 43
Joined: 04 Aug 2005, 13:18

Controlling a ListView

Post by WoF »

Hi TiKu,
it's me again with some problem. I thought, maybe you, as a crack and expert in working with ListView, are the right guy to address.

I'm currently messin' with the CommonDialog control in VB. I wanted it to start in Details mode and now I want it to sort the files in order of date.
I managed the first like that:
I find the window handle of the CommonDialog, get the handle of the ShellDLL_DefView window and send it a message to set the view style to what I want (details). That works great already.
Now I know I'd have to click on the column header #4 to obtain the sorting by date.
Also I found out how I can get window handles of the SysHeader32 which I think are the column headers and of the SysListView32 window.
What I want to know: can I use SendMessage to click on the column header? What message do I have to use? How do I select column 4 and click on it? Or maybe there is even a WM_SORTTHISLISTLIKEIWANTIT message I can send to the ListView.

I thought, maybe you are the right one to ask here.

Best regards
WoF
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Post by TiKu »

Hi,

there're three approaches coming to my mind that might work.
  1. Use the SendInput() API to simulate a mouse click (WM_LBUTTONDOWN + WM_LBUTTONUP) on the column. This would require the dialog to be the active window, but I'm sure that this approach will work.
  2. Send WM_LBUTTONDOWN and WM_LBUTTONUP with the appropriate coordinates to the header control. I'm pretty sure that this approach will work.
  3. Use the WM_NOTIFY message to send a HDN_ITEMCLICK notification to the listview control (or maybe to the listview's parent window). I'm not sure whether this will work. The shell might do some black voodoo stuff when handling WM_LBUTTON[DOWN|UP] that wouldn't be executed in this case.
HTH
TiKu
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
WoF
Lt. Commander
Posts: 43
Joined: 04 Aug 2005, 13:18

Post by WoF »

Hi and thank you, Tiku, for the prompt reply.
I actually worked something out:
Get the dialog's window position with GetWindowPlacement
Set the mouse position to the column using SetCursorPos
Emulate a left button click with mouse_event.

That does the trick, but I consider it rather ugly, because it depends on the absolute column position.

How would I have to use the WM_NOTIFY and HDN_ITEMCLICK you mentioned? Is this for a SendMessage call? How would I address the click to column 4?

Thank you anyway
WoF
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Post by TiKu »

This might work:

Code: Select all

NMHEADER details = {0};
details.hdr.hwndFrom = hWndHeader;
details.hdr.code = HDN_ITEMCLICK;
details.iItem = columnIndex; // set this to 3 for column 4
details.iButton = 0; // left mouse button
SendMessage(hWndListView, WM_NOTIFY, 0, (LPARAM) &details);
TiKu
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
WoF
Lt. Commander
Posts: 43
Joined: 04 Aug 2005, 13:18

Post by WoF »

Thanks. Obviously I forgot to mention that I'm writing Visual Basic 6.0...
Is there a direct definition for the NMHEADER struct? Or could you show me how to define it in VB?
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Post by TiKu »

Code: Select all

Private Type NMHDR
  hwndFrom As Long
  idFrom As Long
  code As Long
End Type

Private Type NMHEADER
  hdr As NMHDR
  iItem As Long
  iButton As Long
  pitem As Long
End Type
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
WoF
Lt. Commander
Posts: 43
Joined: 04 Aug 2005, 13:18

Post by WoF »

Thanks a lot, Tiku.
I could work it out finally. Had to use HDN_ITEMCLICKW constant and then it worked.

If you are interested I have appended my little test project.
With a little mor work one could create a fully configurable file open dialog, but I just wanted to work out and refine the principle.

Best regards
WoF
Attachments
CDLGSorted.zip
(3.45 KiB) Downloaded 664 times
Post Reply