Found the following interesting discussion in the Newsgroups:
| ComboBox class, CB_INSERTSTRING , VB.NET and marshalling... by:GianPiero Andreis | |
| Hello All, let me pose a simple question about combobox and the CB_INSERTSTRING message. Suppose for instance that I already have a combobox handle, how can I declare and use the SendMessage function just for insert a new item into the combobox ? Of course, the combo box DO NOT belong to my process, so I can't use the standard properties of that class. In fact, I need to "put" a new entry in the combo box of IExplorer. EnumWindows get me the handle of the IExplorer main window, with EnumChildWindows I can obtain the handle of the "www address" combo. At this point, I would like to put into the combo an "www address" of choice. I tried ALL the parameters of the MarshalAs attribute related to the string, (with the UnmanagedType enum) but never seems to works, sometime IE crashes.. :-) Please, don't tell to me to use SendKeys class. .NET SendKeys class works well (do not alter, no more, the numlock and/or capslock status of my keyboard, like the older sendkeys in VB) but I need to use SendMessage because I want to unterstand hot to marshalling correctly the parameters. And last, but not least, I LIKE API's... Thank You Gentleman for Your precious help. Best regards Ing. GianPiero Andreis | |
| Reply: by:CJ Taylor | |
Whats your code look like for the SendMessage? And what part are you marshalling? individual variables or an entire structure? | |
| Reply: by:GianPiero Andreis | |
| Ok, a piece of code... This is the function I use for looping over the child windows in IE. Everything works well except the SendMessageA function
And this is the prototype for the function.
There is no need to use System.IntPtr, I don't look for system portability at this time. Regarding to formatted classes, at this time I don't use it because I see Win32 APi's are working as well without the use of that encapsulation. Maybe this is the cause of the problem, but consider that I use API very very often in .NET (because I wrote automation programs, macro player and so on), and everything works well without formatted classes. I tried also the use of StringBuilder class as fouth parameter in the SendMessageA function, but IE crashes. If You need other informations, I would be glad to write for You forward. Please excuse my english, is very poor, I know. Thank You in advance, Sir. Ing. GianPiero Andreis | |
| Reply: by:GianPiero Andreis | |
| Hey All, finally this code works. I worked hard over the CB_*** messages, but there are no way (it seems to me) to set an item into the ComboBox, like the old VB instead allow with API. The only solution I find is to send a message with the edit portion of the combo (i.e. is a child window that belongs to the combo). So You need, once You have the combo handle, to enumerate all the child windows in the combo, and when the class name You find is "Edit", You can send the message WM_SETTEXT with the string You wanted. Below You find the declaration of SendMessage and the line of code that send the string into the combo. Hope this helps someone. Best regards
| |
| Reply: by:M. Angelo | |
| If you use sendmessage to set the strings in a list control you will not be able to use the framework functions to retrieve it because it deals with objects instead of strings. The ListBox and the TextBox are not extremely difficult to subclass but I found the ComboBox subclassing not pratical. I would like to read further from your experience. Regards | |
Posted by Xander Zelders

0 Comments:
Post a Comment
<< Home