gpt4 book ai didi

c# - SB_GETTEXT 空填充 stringbuilder

转载 作者:太空宇宙 更新时间:2023-11-03 10:48:56 25 4
gpt4 key购买 nike

我正在尝试从另一个应用程序的状态栏的一部分获取文本。我可以获取句柄 OK,我只是无法从我的 stringbuilder 获取文本,当在消息框中显示时,它什么也不显示。

到目前为止的代码

[DllImport("user32.dll")]
static extern int SendMessage(IntPtr hwnd, int message, int wParam, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lParam);
[DllImport("user32.dll")]
static extern int SendMessage(IntPtr hwnd, int message, int wParam, int lParam);

IntPtr statbarhandle = IntPtr.Zero;
StringBuilder sbb = new StringBuilder(50);
StringBuilder classname = new StringBuilder(20);
classname.Append("msctls_statusbar32");
statbarhandle = FindWindowEx(gr3hwnd, IntPtr.Zero, classname, null);
int numofparts = SendMessage(statbarhandle, 0x406, 0, 0);
SendMessage(statbarhandle, 0x402, 3, sbb);
MessageBox.Show(sbb.ToString());

顺便说一句,SB_GETPARTS 工作得很好。谁能帮帮我?

最佳答案

这可能是因为您没有传递 SB_GETTEXT

在头文件中,SB_GETTEXT定义为(WM_USER+13)WM_USER定义为0x0400。因此,您应该在 SendMessage 中传递 0x040d。您正在传递 0x0402,即 TB_CHECKBUTTON

请参阅 http://www.pinvoke.net/default.aspx/user32/SB_GETTEXT.html 中的常量定义.

比这要复杂一点。我现在看到 SB_GETTEXTA(ANSI 版本)是 0x0402。 SB_GETTEXTW0x040d。你想要 SB_GETTEXTW

关于c# - SB_GETTEXT 空填充 stringbuilder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22264599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com