What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Tips

Tips
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Tips
Change a ListViewControl's column header in real-time
When you're developing a big script for the mass, one day you'll want to add multilingual support. Most of the time, you can change the text of a control this with PlusWnd::SetControlText, but what if you have a nice ListViewControl with column headers to display interesting information? Formerly, developers simply re-wrote the XML file to make the change in the ListViewControl's <Columns> element, but this method can slow down your computer and is very impractical. Today, I'll show you a much more interesting way to do it. :)

The following method uses the LVM_SETCOLUMN message to set the column header's information. Not all options of the LVCOLUMN structure need to be used because we only want to change the text. Therefore, we also need to create a buffer to hold the string. The comments will clarify this. :)
code:
/*
[bool] SetColumnHeader(
   [hWnd] hWnd: Handle of the ListViewControl, retrieved with PlusWnd::GetControlHandle
   [number] iCol: Column id, the first column is 0, second is 1 etc.
   [string] sHeader: The new column header
)
Returns true if LVM_SETCOLUMNW succeeded, otherwise false.
*/


function SetColumnHeader(hWnd, iCol, sHeader) {

//Message constants
var LVM_FIRST = 0x1000;
var LVM_SETCOLUMNW = (LVM_FIRST + 96); //We'll use the Unicode instead of the ANSI version to have more characters supported
var LVCF_TEXT = 0x4;

//Create a buffer for the header
var pszText = Interop.Allocate((sHeader.length+1)*2); //Make a DataBloc where the header fits in perfectly
pszText.WriteString(0, sHeader); //Write the header in the DataBloc

//Create an LVCOLUMN structure
var LVCOLUMN = Interop.Allocate(16);
LVCOLUMN.WriteDWord(0, LVCF_TEXT); //mask: pszText is valid
LVCOLUMN.WriteDWord(12, pszText.DataPtr); //pszText: pointer to our buffer

//Call LVM_SETCOLUMNW to change the header and save the result
var Result = Interop.Call("user32", "SendMessageW", hWnd, LVM_SETCOLUMNW, iCol, LVCOLUMN);

//Clear the DataBlocs
pszText.Size = 0;
LVCOLUMN.Size = 0

//Return the result
return Result;

}
You may use and edit this snippet for your own scripts, but if you're going to release your script it'd be nice if you put a little credit in your script. :)

EDIT: Snippet now placed in a function for easier access.

This post was edited on 06-03-2007 at 08:11 AM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
06-02-2007 05:02 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Tips - by surfichris on 03-13-2006 at 12:06 PM
RE: Tips - by -dt- on 03-13-2006 at 12:11 PM
RE: Tips - by segosa on 03-13-2006 at 12:39 PM
RE: Tips - by surfichris on 03-13-2006 at 01:13 PM
RE: Tips - by Volv on 04-19-2006 at 06:29 AM
RE: Tips - by -dt- on 04-19-2006 at 06:57 AM
RE: Tips - by davidt on 08-15-2006 at 09:21 AM
RE: RE: Tips - by CookieRevised on 10-21-2006 at 01:44 AM
RE: Tips - by Plan-1130 on 10-25-2006 at 08:15 PM
RE: Tips - by matty on 10-25-2006 at 08:21 PM
RE: Tips - by tryxter on 01-08-2007 at 06:46 PM
RE: Tips - by CookieRevised on 01-28-2007 at 01:15 AM
RE: Tips - by Matti on 06-02-2007 at 05:02 PM
RE: Tips - by Matti on 06-07-2007 at 05:38 PM
RE: Tips - by henry1817 on 12-30-2009 at 04:13 PM
RE: Tips - by matty on 12-30-2009 at 04:20 PM
RE: Tips - by whiz on 06-24-2010 at 10:53 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On