473,659 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ComboBox class, CB_INSERTSTRING , VB.NET and marshalling...

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
EnumChildWindow s 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


Nov 20 '05 #1
4 3143
Whats your code look like for the SendMessage?

And what part are you marshalling? individual variables or an entire
structure?
"GianPiero Andreis" <le************ *@hotmail.com> wrote in message
news:uN******** ********@TK2MSF TNGP10.phx.gbl. ..
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
EnumChildWindow s 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

Nov 20 '05 #2
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

Public Function EnumChildWindow sSub(ByVal argl_hChildWnd As IntPtr, ByVal
argl_Param As Integer) As Boolean
Dim lsb_ClassName As New StringBuilder(2 56)
Call GetClassNameA(a rgl_hChildWnd, lsb_ClassName,
lsb_ClassName.C apacity)
If (lsb_ClassName. ToString = "ComboBox") Then
SendMessageA(ar gl_hChildWnd.To Int32, CB_INSERTSTRING , 0,
"www.thatsite.c om")
'This just for see with Spy that the combo handle is correct
Me.Text = "I find combo with handle " &
Hex(argl_hChild Wnd.ToInt32).To String
Return False
Else
Return True
End If
End Function

And this is the prototype for the function.
Private Declare Auto Function SendMessageA Lib "user32" (ByVal hwnd As Long,
ByVal wMsg As Long, ByVal wParam As Long, <MarshalAs(Unma nagedType.LPStr )>
ByVal lParam As String) As Long

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
"CJ Taylor" <no****@blowgoa ts.com> ha scritto nel messaggio
news:10******** *****@corp.supe rnews.com...
Whats your code look like for the SendMessage?

And what part are you marshalling? individual variables or an entire
structure?
"GianPiero Andreis" <le************ *@hotmail.com> wrote in message
news:uN******** ********@TK2MSF TNGP10.phx.gbl. ..
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
EnumChildWindow s 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


Nov 20 '05 #3
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

'Declaration
Private Declare Auto Function SendMessageA Lib "user32" (ByVal hwnd As
IntPtr, ByVal wMsg As IntPtr, ByVal wParam As IntPtr,
<MarshalAs(Unma nagedType.AnsiB Str)> ByVal lParam As String) As IntPtr
'Code (argl_hChildWnd is the handle of the Edit window into the combo)
SendMessageA(ar gl_hChildWnd, New IntPtr(WM_SETTE XT), IntPtr.Zero,
"www.thatsite.c om")


Nov 20 '05 #4
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

GianPiero Andreis wrote:
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
EnumChildWindow s 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


Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2631
by: Pete | last post by:
I have a combobox which is used to select records, which is satisfactory at the moment. However, a second user is going to start using this database and there will be 1600 records. This makes the combobox a little unfeasable as searching through this many names would be difficult and time-consuming. I would like the user to be able to select a group of people from a first combobox, and then when he goes to the second, only the names of
1
2492
by: anonymous | last post by:
I've been trying to put a them, please help me out. Here's the major parts of my code: public Form1() { DataSet myDataSet = new DataSet("myDataSet"); DataTable testTable = new DataTable("table"); testTable.Columns.Add("Col1", typeof(Int32)); testTable.Columns.Add("Col2", typeof(String)); testTable.Rows.Add(testTable.NewRow());
7
23527
by: NCrum | last post by:
I want to set the Default value of a Combobox for any changeable record and have got this working but it is totaly unsatisfactory see the code below I loop through the items in the Combo looking for a match between cVal and the selectedValue then stop when I do have a match the obvious problem is that each iteration fires the selectedIndexChanged but also for a large list this will slow everything down. There must be a better way int...
2
12877
by: John Tyce | last post by:
When a button is clicked, a date is inserted or added into a combo box like this : ComboBox.Items.Add(string) or ComboBox.Items.Insert(0,string); Either way, the new string does not show up in the ComboBox. I get no errors or problems, it just will not work. At load time I am retrieving dates from an Oracle database and adding them to the ComboBox with out any problems. However, once the application is up and running I cannot add to the...
7
606
by: GianPiero Andreis | last post by:
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...
6
7805
by: Sakharam Phapale | last post by:
Hi All, How to fill one ComboBox from other ComboBox control? 1) Only setting the reference does the trick but doesn't show items in control. If you see in immediate window, it shows the item count correctly
2
6195
by: Don | last post by:
I've looked high and low for some code that will allow me to have a combobox with a flat borderstyle. I found a few examples, but nothing that was really usable for me. I had the following criteria that I wanted to meet, but nothing did: - No reliance on a separate library - No unmanaged code - Easy subclassing of System.Windows.Forms.Combobox (i.e. no custom control monstrosity) - No extra funky features that I didn't need
4
6661
by: Jerad Rose | last post by:
I'm baffled by this -- is there not a typed object used for ComboBox Items? Best I can tell, all of the methods for ComboBox that accept an Item are of type Object. Why in the world is a common/standard .NET control accepting an Object as a parameter type? In Web Forms, there is a ListItem object that can be passed in to add/retrieve objects from a DropDownItems collection. I searched Google groups, and all the solutions I'm finding...
2
3340
by: calenlas | last post by:
Hi all, I'm taking my first steps into C# <--C++ DLL Interop and unfortunately I've run into (what seems to be) a very complicated case as my first task. Perhaps someone here can help me. I need to pass an array of RADIO_INFO2 structures to be filled by a function in the DLL. This is how the structure is defined in the C++ example that comes with the DLL:
0
1103
by: dvanmil | last post by:
I am in the process of creating my own custom Open File Dialog and was wondering about one thing that should be the final key to my puzzle. Hopefully someone might have some more insights into this matter that might prove to be helpful. In my dialog I want to prevent the user to browse freely in certain places (this is due to the fact that my application will be running in a terminal server environment). So I want to to limit the items that...
0
8330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2749
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.