Use Spy++. Look at the target window. I am sure that the target edit control has the style ES_UPPERCASE! So this tells you why the characters are converted.
You may do a dirty hack in using SetWindowLong(GWL_STYLE) and remove this style.
문제
I've made a program in C#
that get the data info from an electronic ID card (Belgium), got no problem to do that but I need to put those informations in the registration form of a program... and that's where I got some issues...
I succeed to identify the window and the textboxes with spy++ (and select it by the FindWindow
and FindWindowEx
methods) but the problem is that when I'm sending a string with the SendMessage
(or SendMessageW) method, my string which contains upper and lower-case characters in my software appears completely in upper-case characters in the other program... I really need to havec upper lower-case characters as well as accented characters... I tried to put the Charset in Unicode or Ansi, it doesn't change anything... Does anyone have a solution to my problem? Thanks a lot for your help!
Here is the code used:
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string className, string lpszWindow);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
private static extern int SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, string lParam);
[DllImport("user32.dll", EntryPoint = "SendMessageW", CharSet = CharSet.Unicode)]
static extern IntPtr SendMessageUnicode(IntPtr hWnd, UInt32 Msg, IntPtr wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
private const int WM_SETTEXT = 12;
...
IntPtr x = new IntPtr();
IntPtr parent = FindWindow(null, "Formulaire inscription lecteur");
IntPtr child = FindWindowEx(parent, x, "Edit", null);
int q = SendMessage(child, WM_SETTEXT, IntPtr.Zero, "TesT");
// same thing with this://SendMessageUnicode(child, WM_SETTEXT, IntPtr.Zero, "TeSt");
Here is what I get on the registration form:
Edit:
Thanks for your answers... I used xMRi's method and it works perfectly...
In case, here is the code used to do that (cause there is a lot of not working codes out there):
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, UInt32 dwNewLong);
[DllImport("user32.dll")]
public static extern IntPtr GetWindowLong(IntPtr hWnd, GetWindowLongParam nCmd);
private const int WM_SETTEXT = 12;
private const int GWL_STYLE = (-16);
private const int ES_UPPERCASE = 0x0008;
private const int ES_READONLY = 0x0800;
private const int DTM_SETSYSTEMTIME = 0x1002;
public enum GetWindowLongParam
{
GWL_WNDPROC = (-4),
GWL_HINSTANCE = (-6),
GWL_HWNDPARENT= (-8),
GWL_STYLE = (-16),
GWL_EXSTYLE = (-20),
GWL_USERDATA = (-21),
GWL_ID = (-12),
}
IntPtr x = new IntPtr();
IntPtr parent = FindWindow(null, "Formulaire inscription lecteur");
IntPtr child = FindWindowEx(parent, x, "Edit", null);
//defining style: 1. Get the styles, and then delete uppercase and readonly
lExStyle = (long)GetWindowLong(child, GetWindowLongParam.GWL_STYLE);
lExStyle &= ~(ES_UPPERCASE);
lExStyle &= ~(ES_READONLY);
//set the new styles
SetWindowLong(child, GWL_STYLE, (uint)lExStyle);
//then send the message
SendMessage(child, WM_SETTEXT, IntPtr.Zero, string);
The only problem to put data in the other program is on an "Edit" but linked to a sysmonthcal32 ... I tried to send it in different forms, overridden the readonly style, ... nothing seems to work...
All the others "edit" are filled with the strings sent by my software...
http://i.stack.imgur.com/dRaS8.png
Any ideas?
Thanks a lot!
해결책
Use Spy++. Look at the target window. I am sure that the target edit control has the style ES_UPPERCASE! So this tells you why the characters are converted.
You may do a dirty hack in using SetWindowLong(GWL_STYLE) and remove this style.
다른 팁
The other program is converting your text to upper case. There's nothing you can do from your end. You'll need to get help from the developer of the other program.