我已经制作了一个C#
从电子身份证(比利时)获取数据信息的程序,这样做没有问题,但我需要将这些信息放入程序的注册表中......这就是我得到一些问题...
我成功地使用 spy++ 识别窗口和文本框(并通过FindWindow
andFindWindowEx
方法选择它)但问题是当我使用SendMessage
(或 SendMessageW)方法发送字符串时,我的字符串包含大写和小写字符在我的软件中完全以大写字符出现在另一个程序中...我真的需要有大写小写字符以及重音字符...我尝试将字符集放在 Unicode 或 Ansi 中,它没有改变任何东西......有人能解决我的问题吗?非常感谢你的帮助!
这是使用的代码:
[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");
这是我在注册表中得到的信息:
编辑:
感谢您的回答...我使用了 xMRi 的方法,并且效果很好...
以防万一,这是用于执行此操作的代码(因为那里有很多不起作用的代码):
[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);
将数据放入其他程序的唯一问题是“编辑”但链接到 sysmonthcal32 ...我尝试以不同的形式发送它,覆盖只读样式,...似乎没有任何效果...
所有其他“编辑”都充满了我的软件发送的字符串......
http://i.stack.imgur.com/dRaS8.png
有任何想法吗?
非常感谢!