Combobox Select String API not working.

I

ink

Hi All

I am trying to Select an item in a combobox on a form running in a different
application(written in C# CF2.0) and running in a different process using
the windows API.
I am developing with C# CF2.

This is my code and it always returns -1.
I know the text is in the combobox
And the Handle is defiantly correct for that combobox, because I can send a
screen tap to it and the list will drop down.

Please can some one take a look and let me know where I am going wrong.

uint CB_SELECTSTRING = 0x014d;

[DllImport("coredll.dll", EntryPoint = "SendMessage", CharSet =
CharSet.Auto)] //
static extern int SendMessage4(IntPtr hWnd, uint Msg, int wParam, string
lParam);


public int ComboBoxSelectString(IntPtr hWnd, string s, int StartAtIndex)
{
return SendMessage4(hWnd, CB_SELECTSTRING, StartAtIndex, s);
}


Thanks,
ink
 
G

Guest

IIRC the ComboBox is a composite control. You need to select on the handle
of the textbox portion where the text is, not the button portion that
controls drop down. I think (and I'm guessing) that Peter Foot has reported
something about getting to the individual controls, either in his blog or
one of the newsgroups.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
 
P

Peter Foot [MVP]

I think the problem you are encountering is that CB_SELECTSTRING isn't
supported across processes. This is certainly the case with the companion
message CB_FINDSTRING, and since they both do a similar thing I expect they
have the same limitation. This from the SDK documentation:-

"This message does not work across processes. You cannot make the call
SendMessage(CB_FINDSTRING) to another process."

Peter
 
I

ink

Thank you both for your responses.

I can send a Scroll down KeyB_Event to the combo box to select different
items but it would be good if I could select a particular item in the list.

My Combos are populated from a database so not always the same. It would be
good if it would be a bit more dynamic.
I got the idea of searching from this blog but this is not across process
http://blog.opennetcf.org/ayakhnin/PermaLink,guid,550d5abb-15f7-4bf4-86fe-360d4805edcd.aspx

Does either of you have any idea on how I could do this across processes?
Or maybe a work around.

Thanks
ink
 
M

Michael Salamone

You can try DLL injection. Search "InjectDLL" for more info.

Create a DLL that gets injected into app you want to control. Your
controller process can talk to (use some IPC - SendMessage(WM_COPYDATA) may
be convenient if your DLL can create a hidden window (in a new thread with a
message pump).

Only problem is your DLL would get injected into every process. If you know
the name of the process you care about, then you can have DllMain return
FALSE during DLL_PROCESS_ATTACH for all processes except the one you care
about. At least that way it will immediately get unloaded from all other
processes.

--
Michael Salamone, eMVP
Entrek Software, Inc.
www.entrek.com


ink said:
Thank you both for your responses.

I can send a Scroll down KeyB_Event to the combo box to select different
items but it would be good if I could select a particular item in the
list.

My Combos are populated from a database so not always the same. It would
be good if it would be a bit more dynamic.
I got the idea of searching from this blog but this is not across process
http://blog.opennetcf.org/ayakhnin/PermaLink,guid,550d5abb-15f7-4bf4-86fe-360d4805edcd.aspx

Does either of you have any idea on how I could do this across processes?
Or maybe a work around.

Thanks
ink





ink said:
Hi All

I am trying to Select an item in a combobox on a form running in a
different application(written in C# CF2.0) and running in a different
process using the windows API.
I am developing with C# CF2.

This is my code and it always returns -1.
I know the text is in the combobox
And the Handle is defiantly correct for that combobox, because I can send
a screen tap to it and the list will drop down.

Please can some one take a look and let me know where I am going wrong.

uint CB_SELECTSTRING = 0x014d;

[DllImport("coredll.dll", EntryPoint = "SendMessage", CharSet =
CharSet.Auto)] //
static extern int SendMessage4(IntPtr hWnd, uint Msg, int wParam, string
lParam);


public int ComboBoxSelectString(IntPtr hWnd, string s, int StartAtIndex)
{
return SendMessage4(hWnd, CB_SELECTSTRING, StartAtIndex, s);
}


Thanks,
ink
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top