[System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "SendMessageW")]
public static extern int SendMessageW2([System.Runtime.InteropServices.InAttribute()] System.IntPtr hWnd, uint Msg, uint wParam, IntPtr lParam);
public const int WM_GETTEXT = 13;
[RequiredArgument]
public InArgument<IntPtr> WindowsHandle { get; set; }
[RequiredArgument]
public OutArgument<String> WindowsCaption { get; set; }
protected override void RealExecute(CodeActivityContext context)
{
IntPtr windowsHandle = context.GetValue(this.WindowsHandle);
int maxLength = 100;
IntPtr buffer = Marshal.AllocHGlobal((maxLength + 1) * 2);
SendMessageW2(windowsHandle, WM_GETTEXT, 100, buffer);
string w = Marshal.PtrToStringUni(buffer);
Marshal.FreeHGlobal(buffer);
context.SetValue<String>(this.WindowsCaption, w.ToString());
}
这个是wf中的ActivtyCode只有传入一个句柄,就会返回需要的Cation
C#通过窗体句柄获取窗体的Caption
最新推荐文章于 2021-10-29 09:16:36 发布