473,320 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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


Nov 20 '05 #1
4 3106
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****************@TK2MSFTNGP10.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
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

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 EnumChildWindowsSub(ByVal argl_hChildWnd As IntPtr, ByVal
argl_Param As Integer) As Boolean
Dim lsb_ClassName As New StringBuilder(256)
Call GetClassNameA(argl_hChildWnd, lsb_ClassName,
lsb_ClassName.Capacity)
If (lsb_ClassName.ToString = "ComboBox") Then
SendMessageA(argl_hChildWnd.ToInt32, CB_INSERTSTRING, 0,
"www.thatsite.com")
'This just for see with Spy that the combo handle is correct
Me.Text = "I find combo with handle " &
Hex(argl_hChildWnd.ToInt32).ToString
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(UnmanagedType.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****@blowgoats.com> ha scritto nel messaggio
news:10*************@corp.supernews.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****************@TK2MSFTNGP10.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
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


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(UnmanagedType.AnsiBStr)> ByVal lParam As String) As IntPtr
'Code (argl_hChildWnd is the handle of the Edit window into the combo)
SendMessageA(argl_hChildWnd, New IntPtr(WM_SETTEXT), IntPtr.Zero,
"www.thatsite.com")


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


Nov 20 '05 #5

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

Similar topics

3
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...
1
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...
7
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...
2
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...
7
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...
6
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...
2
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...
4
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...
2
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...
0
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.