gpt4 book ai didi

.net - SetWindowLong悬挂

转载 作者:行者123 更新时间:2023-12-04 18:48:19 26 4
gpt4 key购买 nike

为什么SetWindowLong(myForm.hWnd, GWL_HWNDPARENT, parentHwnd)挂起?

通过执行这三个步骤,我可以始终如一地重现此问题。

  • 创建.NET表单
  • 初始化WaitWindow COM对象,并在传递.NET Forms Handle的同时调用COM对象上的ShowWindow
  • 在VB6中调用SetWindowLong方法

  • C#Windows应用程序(挂起)
    private static void Main(string[] args)
    {
    Form form = new Form();
    form.Show();

    Interop.WaitWindow waitWindow = new Interop.WaitWindow();
    waitWindow.ShowWindow(form.Handle.ToInt32(), Language.RISEnglish);
    }

    C#控制台应用程序(不挂起)
    private static void Main(string[] args)
    {
    IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;

    Interop.WaitWindow waitWindow = new Interop.WaitWindow();
    waitWindow.ShowWindow(handle.ToInt32(), Language.RISEnglish);
    }

    VB6代码段
    Public Sub ShowWindow(ByVal parentHwnd As Long, ByVal language As Language)

    SetWindowLong(myForm.hWnd, GWL_HWNDPARENT, parentHwnd) 'Hangs Here
    CenterWindow (parentHwnd)

    myForm.ShowRetrieving (language)
    myForm.Show (vbModal)
    End Sub

    真的会感谢您的帮助:)

    编辑

    我确实知道不应调用SetWIndowLong来更改父级,但是我试图理解为什么只有在使用.NET窗体句柄时它才会挂起。

    EDIT2

    我现在认为问题与SetWindowLong无关,而与实际的句柄本身有关。我仍在调查中,但是当我从.NET调用VB6代码时,它似乎创建了一个RPC线程。我不确定,但是我感觉到它与跨线程问题有关。

    最佳答案

    MSDN文档明确指出

    You must not call SetWindowLong with the GWL_HWNDPARENT index to change the parent of a child window. Instead, use the SetParent function.

    关于.net - SetWindowLong悬挂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10216414/

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