[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只有传入一个句柄,就会返回需要的CationC#通过窗体句柄获取窗体的Caption
最新推荐文章于 2026-04-28 05:31:12 发布
本文提供了一个使用Workflow(WF)获取指定窗口标题的活动代码实现,通过传入窗口句柄,该代码能够返回窗口的标题字符串。

449

被折叠的 条评论
为什么被折叠?



