本文介绍了真的需要SendMessage WM_GETCONTROLNAME的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在另一个窗口中获取编辑框的控件名称。


以下代码设置值MyPassword在密码EditBox

但它无法返回EditBox的控件名称。我确定

问题是我使用sendmessage API的方式,返回字符串和

lParam返回0 ....是否有人有线索?任何sendmessage api

专家在这里?


[DllImport(" User32.dll")]

public static extern Int32 FindWindow (String lpClassName,String

lpWindowName);

[DllImport(" user32.dll",CharSet = CharSet.Auto)]

public static extern int SendMessage(int hWnd,int msg,int wParam,

IntPtr lParam);

[DllImport(" user32.dll",SetLastError = true)]

public static extern IntPtr FindWindowEx(IntPtr parentHandle,IntPtr

childAfter,string className,string windowTitle);

[DllImport(" user32.dll" ;)]

public static extern UInt32

RegisterWindowMessage([MarshalAs(UnmanagedType.LPTStr)] String

lpString);

// ....


int hwnd = 0;

IntPtr hwndChild = IntPtr.Zero;

hwnd = FindWindow(null," Login");

hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero," TEdit" ,");

SetControlText((int)hwndChild,WM_SETTEXT,0," MyPassword");


//以下不是按预期工作以获得控制名称

uint SendMsg;

SendMsg = RegisterWindowMessage(" WM_GETCONTROLNAME");

long ReturnMsg;

IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(IntPt r)));

Marshal.WriteIntPtr(ptr,IntPtr.Zero);

ReturnMsg = SendMessage((int)hwndChild,(int)SendMsg,65536,ptr);

IntPtr CtrlName = Marshal.ReadIntPtr(ptr);

MessageBox.Show (CtrlName.ToString());

MessageBox.Show(ReturnMsg.ToString());

Marshal.FreeCoTaskMem(ptr);

解决方案




我仍​​然我不知道答案。



I still don''t know the answer.



这篇关于真的需要SendMessage WM_GETCONTROLNAME的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 00:41