SendMessage not working?

M

Mark

Hi,

Starting with a clean smartphone project, I have the main form with a
textbox in it called textBox1. I'm trying to add text to it using
SendMessage (to avoid that annoying flicker). Here are the pinvokes...

const uint EM_REPLACESEL = 0xc2;
[DllImport("coredll")]
extern static IntPtr GetCapture();
[DllImport("coredll")]
extern static int SendMessage(IntPtr hWnd, uint Msg, bool WParam,
string LParam);

Here's the code that should update the textbox:

textBox1.Capture = true;
IntPtr hWnd = GetCapture();
textBox1.Capture = false;
SendMessage(hWnd, EM_REPLACESEL, false, "hello");


I successfully get a handle on the text box, but the word "hello"
doesn't appear in the text box. Any ideas what I'm doing wrong here?

TIA
Mark
 
C

Chris Tacke, eMVP

EM_REPLACESEL replaces only selected text - do you have anything in the
textbox selected? Changing your P/Invoke declaration to add
SetLastError=true and checking the LastWin32Error might be useful as well.

--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
 
P

Peter Foot [MVP]

On Smartphone the native edit window is hosted within another window - so
the handle you have is not to the edit box itself. Use GetWindow with
argument GW_CHILD to return the handle of the edit control, then you can
send this the message.

Peter
 
N

news

D'oh!
I grabbed the last error, which indicated an invalid handle. So I did a
..Focus() followed by GetFocus() (pinvoked) to get the handle instead of
..Capture. Worked a treat this time. :)

Probably because Smartphone doesn't have mouse support, so the .Capture
wasn't capturing anything.

BTW, without selecting text first, it simply added the text to the
start of the textbox (which is where the caret is by default I guess).

Cheers
Mark
 

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