2013-10-30 124 views
0

我已经制作了一个程序C#从电子身份证(比利时)获取数据信息,没有问题做到这一点但我需要把这些信息放在程序的注册表中......这就是我遇到的一些问题......user32.dll SendMessage:发送字符串转换为大写字符...但区分大小写的字符串

我成功地用spy ++来识别窗口和文本框(并且通过FindWindowFindWindowEx方法),但问题是,当我使用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

有何想法?

非常感谢!

回答

0

使用Spy ++。看看目标窗口。我确信目标编辑控件具有ES_UPPERCASE样式!所以这告诉你为什么字符被转换。

你可能会在使用SetWindowLong(GWL_STYLE)时做一个蹩脚的黑客攻击并删除这种风格。

+0

非常感谢,它工作得很好:) – Zin

0

其他程序正在将您的文本转换为大写。你从来没有做过任何事情。您需要从其他程序的开发人员那里获得帮助。

相关问题