SendMessage and WM_SETTEXT

M

Mark Ingalls

Hello Everyone,

I'm trying to send a text string to a dialog edit control using
SendMessage and WM_SETTEXT and cannot get it working correctly.

Here is the declaration of the function:

<DllImport("user32.dll", EntryPoint:="SendMessage", SetLastError:=True,
CharSet:=CharSet.Auto)> _
Private Function SendMessageString(ByVal hWnd As IntPtr, _
ByVal Msg As Integer, _
ByVal wParam As IntPtr, _
ByRef lParam As String) As IntPtr
End Function


and here is how I call it:

SendMessageString (editHwnd, WM_SETTEXT, 0, message.ToString())

The edit control of the dialog box is getting filled in, but it is
either filled with boxes (using CharSet.Auto or CharSet.Unicode in the
declaration) or with characters from languages other than US English
(using CharSet.Ansi in the declaration).

Any ideas on why the text is not making it through to the edit control?

For those that want more details, I'm trying to write a file name into
the edit control of the "Print To File" dialog box. I don't control the
printing, or I'd use the PrintDocument.PrintSettings stuff in the
framework. I'm calling the PrintAllPages() method of an ActiveX control
that doesn't support printing to a file directly, so these are the
hoops I must jump through.

thanks,
mark
 
H

Herfried K. Wagner [MVP]

Mark Ingalls said:
I'm trying to send a text string to a dialog edit control using
SendMessage and WM_SETTEXT and cannot get it working correctly.

Here is the declaration of the function:

<DllImport("user32.dll", EntryPoint:="SendMessage", SetLastError:=True,
CharSet:=CharSet.Auto)> _
Private Function SendMessageString(ByVal hWnd As IntPtr, _
ByVal Msg As Integer, _
ByVal wParam As IntPtr, _
ByRef lParam As String) As IntPtr

=> 'ByVal lParam As String'.
 
N

Newbie Coder

Are you making a password program that uncovers the '*' from the edit box?
If so, there are loads of VB.NET examples out on the Internet including some
that I have posted 3-4 years ago.

With the SendMessage API function its common to overload it too & Herfried
is correct becaiuse you don't want to be passing ByRef as you'll soon crash
your app.
 

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