【发布时间】:2013-11-09 19:23:48
【问题描述】:
我在C# 制作了一个程序,从电子身份证(比利时)获取数据信息,这样做没问题,但我需要将这些信息放入程序的注册表中......这就是我遇到一些问题的地方......
我成功地使用 spy++ 识别窗口和文本框(并通过 FindWindow 和 FindWindowEx 方法选择它)但问题是当我使用 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");
Here 是我在注册表单上得到的:
编辑:
感谢您的回答...我使用了 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
有什么想法吗?
非常感谢!
【问题讨论】:
标签: c# winapi sendmessage user32