Shoutbox

[Help]Listview insert column - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [Help]Listview insert column (/showthread.php?tid=89039)

[Help]Listview insert column by DaAniv on 02-08-2009 at 02:11 PM

can you Insert a new column using http://msdn.microsoft.com/en-us/library/bb761101(VS.85).aspx and if yes how?
and remove using http://msdn.microsoft.com/en-us/library/bb774894(VS.85).aspx?


RE: [Help]Listview insert column by matty on 02-08-2009 at 02:26 PM

You need to use the SendMessage API as stated on MSDN.

SendMessage has 4 parameters.

  • The handle to the item
  • The Message (LVM_INSERTCOLUMN)
  • The wParam (in this case column number)
  • The lParam (in this case LPLVCOLUMN)

RE: [Help]Listview insert column by DaAniv on 02-08-2009 at 02:44 PM

how do you write it?


RE: [Help]Listview insert column by matty on 02-08-2009 at 02:46 PM

Try it and post what you come up with and we will go from there. I wont just give you the code you wont learn that way.


RE: [Help]Listview insert column by DaAniv on 02-08-2009 at 02:52 PM

I don't really get how to set the LPLVCOLUMN structure

code:
Interop.Call("user32", "SendMessageW",GetControlHandle("LsvSentences"),"LVM_INSERTCOLUMN",2,LPLVCOLUMN);
and this is fine for the sendmessage?
RE: [Help]Listview insert column by matty on 02-08-2009 at 03:04 PM

quote:
Originally posted by DaAniv
code:
Interop.Call("user32", "SendMessageW",GetControlHandle("LsvSentences"),"LVM_INSERTCOLUMN",2,LPLVCOLUMN);
and this is fine for the sendmessage?
No this will not work at all.

The message you are sending through SendMessage is not a string it is an integer. LVM_INSERTCOLUMN is 0x101B. Column index I also believe is zero-based meaning the first column is 0 the second is 1 etc.

LPLVCOLUMN you need to allocate memory for and fill the structure yourself.

js code:
var LPLVCOLUMN = Interop.Allocate(32);
If you have no idea about what I just wrote then read the documentation and study a bit more :)
RE: [Help]Listview insert column by DaAniv on 02-08-2009 at 06:11 PM

JavaScript code:
function InserColumn(hWnd,iCol,Header)
{
    //Message constants
    var LVM_INSERTCOLUMN = 0x101B;
    var LVCF_TEXT = 0x4;
    var LVCF_WIDTH = 0x2;
       
    var cx= Interop.Allocate(4)//How do I know how much bytes I need?
    cx.WriteWord(0, 50)

    var  pszText=Interop.Allocate((Header.length+2)*2)
    pszText.WriteString(0, Header,true)
    //Create an LVCOLUMN structure
    var LVCOLUMN = Interop.Allocate(32);
    LVCOLUMN.WriteDWord(0,    LVCF_WIDTH); //How do I know the offset?
    LVCOLUMN.WriteDWord(6, cx.DataPtr);  //How do I know the offset?
    LVCOLUMN.WriteDWord(16,    LVCF_TEXT); //How do I know the offset?
    LVCOLUMN.WriteDWord(22, pszText.DataPtr); //How do I know the offset?
   

    var Result = Interop.Call("user32", "SendMessageW", hWnd, LVM_INSERTCOLUMN, iCol, LVCOLUMN);
   
    //Clear the DataBlocs
    cx.Size = 0;
    pszText.size=0;
    LVCOLUMN.Size = 0
   
    //Return the result
    return Result;
}
as said in the comments how do I know the cx bytes and offset when I create the structure?
RE: [Help]Listview insert column by matty on 02-08-2009 at 09:09 PM

It is found on this page which I already linked to.

quote:
Originally posted by http://msdn.microsoft.com/en-us/library/bb774743(VS.85).aspx
typedef struct _LVCOLUMN {
    UINT mask;
    int fmt;
    int cx;
    LPTSTR pszText;
    int cchTextMax;
    int iSubItem;
#if (_WIN32_IE >= 0x0300)
    int iImage;
    int iOrder;
#endif
#if (_WIN32_WINNT >= 0x0600)
    int cxMin;
    int cxDefault;
    int cxIdeal;
#endif
} LVCOLUMN, *LPLVCOLUMN;

You need to match up the offset with the specific field you are filling.