Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

public static bool ComboBox_GetCueBannerText(HWND hwnd, out string lpwText, int cchText) 这个有测试过吗, 报内存访问限制 #8

Open
icetech233 opened this issue Oct 17, 2024 · 3 comments

Comments

@icetech233
Copy link

用来读取, ComboBox 的编辑框的 文本

@icetech233
Copy link
Author

comctl32.dll 系统这个报错了

@kkwpsv
Copy link
Owner

kkwpsv commented Oct 21, 2024

我这边测试没问题,贴下你的用法?

using Lsj.Util.Win32;
using Lsj.Util.Win32.BaseTypes;
using Lsj.Util.Win32.Enums;
using Lsj.Util.Win32.Macros;
using Lsj.Util.Win32.Marshals;
using Lsj.Util.Win32.NativeUI;
using Lsj.Util.Win32.NativeUI.Controls;
using System;
using System.Threading.Tasks;

namespace TestAppWin32
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            HWND comboxBoxHandle = IntPtr.Zero;
            var uiThreadManager = new UIThreadManager();
            await uiThreadManager.InvokeAsync(() =>
            {
                var win = new Win32Window();
                var comboBox = new ComboBox("text", 0, 0, 300, 20, (ComboBoxStyles)(int)WindowStyles.WS_CHILD, win.Handle);
                comboBox.Show();
                comboxBoxHandle = comboBox.Handle;

                StringHandle str = "TestCueBanner";
                var ret = User32.SendMessage(comboBox.Handle, (WindowMessages)ComboBoxControlMessages.CB_SETCUEBANNER, 0, str.Handle);
                Console.WriteLine($"CB_SETCUEBANNER ret: {ret}");

                win.Show();
            }
            );

            var ret = ComboBoxControlMacros.ComboBox_GetCueBannerText(comboxBoxHandle, out var str, 100);
            Console.WriteLine($"ComboBox_GetCueBannerText ret: {ret} result: {str}");

            await Task.Delay(-1);
        }
    }
}

image

PS: app.manifest 需要指定 Microsoft.Windows.Common-Controls 版本,CueBanner才有效果。

  <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>

@icetech233
Copy link
Author

我这边测试没问题,贴下你的用法?

using Lsj.Util.Win32;
using Lsj.Util.Win32.BaseTypes;
using Lsj.Util.Win32.Enums;
using Lsj.Util.Win32.Macros;
using Lsj.Util.Win32.Marshals;
using Lsj.Util.Win32.NativeUI;
using Lsj.Util.Win32.NativeUI.Controls;
using System;
using System.Threading.Tasks;

namespace TestAppWin32
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            HWND comboxBoxHandle = IntPtr.Zero;
            var uiThreadManager = new UIThreadManager();
            await uiThreadManager.InvokeAsync(() =>
            {
                var win = new Win32Window();
                var comboBox = new ComboBox("text", 0, 0, 300, 20, (ComboBoxStyles)(int)WindowStyles.WS_CHILD, win.Handle);
                comboBox.Show();
                comboxBoxHandle = comboBox.Handle;

                StringHandle str = "TestCueBanner";
                var ret = User32.SendMessage(comboBox.Handle, (WindowMessages)ComboBoxControlMessages.CB_SETCUEBANNER, 0, str.Handle);
                Console.WriteLine($"CB_SETCUEBANNER ret: {ret}");

                win.Show();
            }
            );

            var ret = ComboBoxControlMacros.ComboBox_GetCueBannerText(comboxBoxHandle, out var str, 100);
            Console.WriteLine($"ComboBox_GetCueBannerText ret: {ret} result: {str}");

            await Task.Delay(-1);
        }
    }
}

image

PS: app.manifest 需要指定 Microsoft.Windows.Common-Controls 版本,CueBanner才有效果。

  <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>

你电脑里面有没有这个文件

comctl32.dll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants