Re: SendMessage and WM_GETTEXT
From: Peter Huang (v-phuang_at_online.microsoft.com)
Date: 11/19/04
- Previous message: Peter Huang: "RE: Classic ASP, .NET Object and Multiple Threads"
- In reply to: Dennis C. Drumm: "Re: SendMessage and WM_GETTEXT"
- Next in thread: Dennis C. Drumm: "Re: SendMessage and WM_GETTEXT"
- Reply: Dennis C. Drumm: "Re: SendMessage and WM_GETTEXT"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 19 Nov 2004 05:44:11 GMT
Hi
Usually win32 API has two versions. ansi version or unicode version.
e.g.
SendMessageA is Ansi version
SendMessageW is unicode version.
Because the declare in the google link has define the entrypoint as
SendMessageA, that means to use the ansi version.
For detailed information you may try to take a look at the
DllImportAttribute Class and the DllImportAttribute.CharSet Field
DllImportAttribute.ExactSpelling Field.
Specifying a Character Set
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconcharsetobjectfield.asp
[DllImport("user32.dll")]
public static extern int MessageBoxA(int hWnd, String text,
String caption, uint type);
[DllImport("user32.dll", CharSet=CharSet.Unicode)]
public static extern int MessageBoxW(int hWnd, String text,
String caption, uint type);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int MessageBox(int hWnd, String text,
String caption, uint type);
The example above will tell you what is the default conversion when using
CharSet.
Charset.Auto
Automatically marshal strings appropriately for the target operating
system. The default is Unicode on Windows NT, Windows 2000, Windows XP, and
the Windows Server 2003 family; the default is Ansi on Windows 98 and
Windows Me.
[DllImport("user32.dll",CharSet=CharSet.Auto)]
private static extern int SendMessage(IntPtr _WindowHandler, int
_WM_USER, int wParam, [Out] StringBuilder windowText);
private const int WM_GETTEXT = 0xD;
private void button1_Click(object sender, System.EventArgs e)
{
int textSize = 1024;
StringBuilder buffer = new StringBuilder ( textSize );
SendMessage ( this.textBox1.Handle , WM_GETTEXT, textSize,
buffer );
MessageBox.Show(buffer.ToString());
}
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
- Previous message: Peter Huang: "RE: Classic ASP, .NET Object and Multiple Threads"
- In reply to: Dennis C. Drumm: "Re: SendMessage and WM_GETTEXT"
- Next in thread: Dennis C. Drumm: "Re: SendMessage and WM_GETTEXT"
- Reply: Dennis C. Drumm: "Re: SendMessage and WM_GETTEXT"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|