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
<ctacke/> - 06 Sep 2007 14:49 GMT
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.

Signature
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Managed Code in an Embedded World
www.OpenNETCF.com
> Hi All
>
[quoted text clipped - 24 lines]
> Thanks,
> ink
Peter Foot [MVP] - 06 Sep 2007 15:43 GMT
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

Signature
Peter Foot
Microsoft Device Application Development MVP
www.peterfoot.net | www.inthehand.com
In The Hand Ltd - .NET Solutions for Mobility
> Hi All
>
[quoted text clipped - 24 lines]
> Thanks,
> ink
ink - 07 Sep 2007 10:37 GMT
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-360d48
05edcd.aspx
Does either of you have any idea on how I could do this across processes?
Or maybe a work around.
Thanks
ink
> Hi All
>
[quoted text clipped - 24 lines]
> Thanks,
> ink
Michael Salamone - 28 Sep 2007 15:26 GMT
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.

Signature
Michael Salamone, eMVP
Entrek Software, Inc.
www.entrek.com
> Thank you both for your responses.
>
[quoted text clipped - 41 lines]
>> Thanks,
>> ink