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

Re: SendMessage not working? by Chris

Chris
Wed Apr 27 09:26:14 CDT 2005

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


"Mark" <news@mail.adsl4less.com> wrote in message
news:7a57043a.0504270621.41b605c7@posting.google.com...
> 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



Re: SendMessage not working? by news

news
Wed Apr 27 09:31:43 CDT 2005

Thanks for the quick reply.

On
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/editcontrols/editcontrolreference/editcontrolmessages/em_replacesel.asp
it says:

"If there is no current selection, the replacement text is inserted at
the current location of the caret." Indeed if I do the same think in
the full framework (using user32 instead of coredll), it works fine,
inserting text at the caret position.

I'll dig out the last error anyway and see what gives.

Cheers
Mark


Re: SendMessage not working? by Peter

Peter
Wed Apr 27 09:46:08 CDT 2005

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

--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://www.peterfoot.net |
http://www.opennetcf.org

"Mark" <news@mail.adsl4less.com> wrote in message
news:7a57043a.0504270621.41b605c7@posting.google.com...
> 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



Re: SendMessage not working? by news

news
Wed Apr 27 09:49:18 CDT 2005

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