For Programmers: Free Programming Magazines  


Home > Archive > C# > April 2006 > Get the list from from iexplorer combo box









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Get the list from from iexplorer combo box
ME

2006-04-10, 7:02 pm

I need to be able to get the list from a combobox using PInvoke. This code
works fine for a windows form application however I need to read the
combobox that is on an HTML page (inside iexplorer, the class name for the
box is "Internet Explorer_TridentCmboBx" ). When I read the combobox from
IE it will accurately get the count, but the text of each item returns non
printable ascii characters.

What am I doing wrong?

Thanks,

Matt

//C#


//------------------------------ CODE ---------------------

public const UInt32 CB_GETCOUNT = 0x0146;
public const UInt32 CB_GETCURSEL = 0x0147;
public const UInt32 CB_GETLBTEXT = 0x0148;
public const UInt32 CB_GETLBTEXTLEN = 0x0149;

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam,
IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam,
StringBuilder lParam);

public static List<ListItemVals> GetListItems(IntPtr controlPointer, object
sender)
{
int count = 0;
List<ListItemVals> retVal = new List<ListItemVals>();
ListItemVals item = new ListItemVals();
IntPtr zero = new IntPtr(0);
//Get the count of items in the list
IntPtr ptr = SendMessage(GetHandleRef(controlPointer,
sender), CB_GETCOUNT,
zero, zero);
count = ptr.ToInt32();
for (int i = 0; i < count; i++)
{
item = GetValueFromCombo(controlPointer, sender, i);
retVal.Add(item);
}
return retVal;
}
public static ListItemVals GetValueFromCombo(IntPtr pointer, object sender,
int index)
{
//List<ListItemVals> retVal = new List<ListItemVals>();
int len = 0;
StringBuilder sb = new StringBuilder();
ListItemVals item = new ListItemVals();
IntPtr wParam = new IntPtr(index);
IntPtr zero = new IntPtr(0);
//Get the count of items in the list
IntPtr ptr = SendMessage(GetHandleRef(pointer, sender), CB_GETLBTEXTLEN ,
wParam, zero);
len = ptr.ToInt32();
sb.Capacity = len;
IntPtr txtPtr = SendMessage(GetHandleRef(pointer, sender), CB_GETLBTEXT,
wParam, sb);
//Get the list item
item.textValue = sb.ToString();
item.itemValue = wParam.ToInt32();

//return the value
return item;
}


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com