?
Solved

LVM_SORTITEMS

Posted on 2007-03-22
11
Medium Priority
?
983 Views
Last Modified: 2013-11-20
Urgent!

Can anybody help me call the LVM_SORTITEMS windows message in .NET?
I'm trying to make a call to the Win32 API directly through using SendMessage. Does anyone know how to do this?

Greatly appreciated.
0
Comment
Question by:maloriopolium
  • 4
  • 3
8 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 18777258
You can do that// =============================================================
// Comparison routine for sorting ListView on a column
// =============================================================
int CALLBACK ListViewCompareProc(LPARAM lParam1, LPARAM lParam2,
LPARAM lParamSort )
{
      int iResult;

   // MessageBox( hwnd, "Doing sort compare", "SortMsg", MB_OK );
   
      switch( lParamSort )
   {
         case 0:                                                // sub-item 0; file name
            iResult = 0;
            break;

      case 1:                                                // sub-item 1; folder size
      case 2:                                                // sub-item 2; number of files
            if ( lParam1 > lParam2 )
               iResult = 1;
         else
         if ( lParam1 < lParam2 )
               iResult = -1;
         else
               iResult = 0;
         break;
   }


   
   return iResult;
}


SendMessage( hwndList, LVM_SORTITEMS,(WPARAM)(LPARAM)(nSomeId),(LPARAM)(PFNLVCOMPARE)ListViewCompareProc );
 like
0
 

Author Comment

by:maloriopolium
ID: 18777349
Hi jkr,

I am trying to do this in C# .NET. Can this be done? I know you can make various other Win32 API calls in C# but just not sure how to go about this one since one of the parameters is a pointer to a function (PFNLVCOMPARE)

Thanks.
0
 
LVL 86

Accepted Solution

by:
jkr earned 1000 total points
ID: 18777388
Hm, I doubt that you'll be able to pass a function pointer to a C# function. What you could do is creating a "native" Win32 DLL that contains such a sor function and call it via P/Invoke. See http://www.codeproject.com/dotnet/PInvoke.asp ("Using Platform Invoke")
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 19

Assisted Solution

by:alb66
alb66 earned 1000 total points
ID: 18778040
If you are using a ListView you can call the Sort() method.
See MSDN documentation at http://msdn2.microsoft.com/en-us/library/system.windows.forms.listview.sort(VS.71).aspx
0
 

Author Comment

by:maloriopolium
ID: 18784720
Thanks jkr,

I just read that article you linked, it sys,
"Callback functions and passing arrays as parameters involve some more complications and can be the subject for the next article."

which sort of implies that it IS possible to pass function pointers to C#?
Do you know or can anyone point me to something that discusses the passing of callback functions or function pointers as a parameter to a Win32 API function??

Much appreciated
0
 
LVL 86

Expert Comment

by:jkr
ID: 18785858
No, function pointer require native Win32 modules. Since C# is a P-code language (which means that it is interpreted to some extent), there are no memory addresses that resemble assembly code which could serve as a function pointer. That's why you need P/Invoke as an intermediate layer that provides these.
0
 

Author Comment

by:maloriopolium
ID: 18786874
Can you explain what it means by using P/Invoke? It seems that all I have to do is declare the attribute:
[DllImport("user32.dll")]

and then declare a
static extern int SendMessage(....)
function which should be that of the Win32 API function.
Is that all there is to using P/Invoke?

0
 
LVL 86

Expert Comment

by:jkr
ID: 18787147
Yes, that pretty much is it. However, I'd suggest to have the DLL that exposes the callback function itself call 'SendMessage()', since you need to have a native module pass that function pointer, managed modules won't be able to get that one.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question