gpt4 book ai didi

api - SetWindowLongPtr(GWL_HWNDPARENT) 和 SetParent 有什么区别?

转载 作者:行者123 更新时间:2023-12-04 09:06:47 28 4
gpt4 key购买 nike

我需要为桌面上的一些应用程序窗口创建一个水印窗口(markHwnd),水印窗口样式为:

            uint dwStyle = Win32API.WS_CLIPSIBLINGS |
Win32API.WS_CLIPCHILDREN |
Win32API.WS_POPUP;
uint dwExStyle = Win32API.WS_EX_LAYERED |
Win32API.WS_EX_TRANSPARENT |
Win32API.WS_EX_NOACTIVATE |
Win32API.WS_EX_NOPARENTNOTIFY |
Win32API.WS_EX_TOOLWINDOW;
markHwnd = Win32API.CreateWindowEx(dwExStyle, wndclassRegResult, ti.ToString(), dwStyle, 0, 0, 0, 0,IntPtr.Zero, IntPtr.Zero, wndclasshInstance, IntPtr.Zero);
然后我将它设置为应用程序窗口(targetHwnd)的一个拥有的窗口,有两种选择:
  • SetWindowLongPtr(markHwnd, (int)Win32API.GWL.GWL_HWNDPARENT,
    目标Hwnd);
  • SetParent(markHwnd, targetHwnd);

  • 推荐哪一个?

    最佳答案

    SetWindowLongPtr() 文档说:

    Do not call SetWindowLongPtr with the GWLP_HWNDPARENT index to change the parent of a child window. Instead, use the SetParent function.


    该文档所暗示的是 GWLP_HWNDPARENT实际上更改了顶级窗口的所有者,而不是子窗口的父级。根据雷蒙德陈的说法:
    A window can have a parent or an owner but not both

    Now, a window can have a parent, or it can have an owner, or it can have neither, but it can never have both.


    他继续解释 CreateWindow/Ex()根据新窗口是否有 WS_CHILD 分配所有者与父级。风格与否。
    SetParent() 文档说:

    For compatibility reasons, SetParent does not modify the WS_CHILD or WS_POPUP window styles of the window whose parent is being changed. 


    所以, SetWindowLongPtr(GWLP_HWNDPARENT)用于更改顶级窗口的所有者, SetParent()用于更改子窗口的父级。

    关于api - SetWindowLongPtr(GWL_HWNDPARENT) 和 SetParent 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63423266/

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