Re: SendMessage in VB.NET

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Scott Gunn (scott_at_thebigspider.co.uk)
Date: 01/14/05


Date: Fri, 14 Jan 2005 22:38:47 -0000

Hello

If SendMessage (ListView.Handle, LVM_GETCOLUMN, 0, pCol) Then

Returns true but I don't get any information on the column in pCol

Regards
Scott.

"Tom Shelton" <tom@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:eHwzCXo#EHA.4004@tk2msftngp13.phx.gbl...
> In article <eP7YoLo#EHA.3336@TK2MSFTNGP11.phx.gbl>, Scott Gunn wrote:
> > Hi, I'm trying to find out what order the columns in a listview have
been
> > reordered into.
> >
> > I found some examples on the Internet that use csharp and I tried to
convert
> > them into vb but it always returns false and pCol is empty
> >
> > Where am I going wrong?
> >
> > [Declares]
> >
> > Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal
> > hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef
> > lParam As LV_COLUMN) As Integer
> >
>
> Option Strict On ' always a good idea
> Option Explicit On ' again, always a good idea
>
> Imports System.Runtime.InteropServices
>
> Public Declare Auto Function SendMessage Lib "user32" _
> (ByVal hWnd As IntPtr, _
> ByVal wMsg As Integer, _
> ByVal wParam As Integer, _
> ByRef lParam As As LVCOLUMN) As Boolean
>
> <StructLayout (LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
> Public Structure LVCOLUMN
> Pulbic mask As Integer
> Public fmt As Integer
> Public cx As Integer
> Public pszText As String
> Public chTextMax As Integer
> Public iSubItem As Integer
> Public iImage As Integer
> Public iOrder As Integer
> End Structure
>
> Public Const LVM_FIRST As Integer = &H1000
> Public Const LVM_GETCOLUMN As Integer = (LVM_FIRST + 25)
>
> > [ Code to get the column info for column 0]
> >
> > Call SendMessage(lvListView.Handle.ToInt32, LVM_GETCOLUMN, 0, pCol)
>
> Try
>
> If SendMessage (ListView.Handle, LVM_GETCOLUMN, 0, pCol) Then
> ' DO STUFF
> Else
> Throw New Win32Exception (Marshal.GetLastWin32Error ())
> End If
>
> Catch ex As Win32Exception
> MessageBox.Show (ex.Message)
> End Try
>
>
> --
> Tom Shelton [MVP]
> OS Name: Microsoft Windows XP Professional
> OS Version: 5.1.2600 Service Pack 2 Build 2600
> System Up Time: 1 Days, 23 Hours, 24 Minutes, 18 Seconds