我已經制作了一個程序C#
從電子身份證(比利時)獲取數據信息,沒有問題做到這一點但我需要把這些信息放在程序的註冊表中......這就是我遇到的一些問題......user32.dll SendMessage:發送字符串轉換爲大寫字符...但區分大小寫的字符串
我成功地用spy ++來識別窗口和文本框(並且通過FindWindow
和FindWindowEx
方法),但問題是,當我使用SendMessage
(或SendMessageW)方法發送字符串時,我的軟件中包含大小寫字符的字符串在其他程序中完全以大寫字符顯示。我真的需要擁有較高的成績ower-case字符以及重音字符......我試圖把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
有何想法?
非常感謝!
非常感謝,它工作得很好:) – Zin