gpt4 book ai didi

delphi - HWND 在 ShellExecute 中起什么作用?

转载 作者:行者123 更新时间:2023-12-03 14:57:33 24 4
gpt4 key购买 nike

我使用 ShellExecute 来做某事,第一个参数是 HWND ,MSDN 上的 documentation 说:

A handle to the parent window used for displaying a UI or error messages. This value can be NULL if the operation is not associated with a window.

但我发现无论哪个 HWND 值都会得到相同的结果。

例如:

ShellExecute(0, 'open', 'c:\', nil, nil, SW_SHOWNORMAL);

ShellExecute(Self.Handle, 'open', 'c:\', nil, nil, SW_SHOWNORMAL);

ShellExecute(123456, 'open', 'c:\', nil, nil, SW_SHOWNORMAL);

只是得到相同的东西(打开C盘),所以我想知道使用不同的HWND有什么用?

顺便问一下,当'HWND = 0'时使用DeskTop的Handle?

最佳答案

HWND 用作因调用 ShellExecute 而显示的任何 UI 的所有者窗口。例如,任何错误消息对话框都将归该窗口所有。

MSDN documentation 中描述了拥有窗口的含义。 。关键摘录:

Being owned places several constraints on a window.

  • An owned window is always above its owner in the z-order.
  • The system automatically destroys an owned window when its owner is destroyed.
  • An owned window is hidden when its owner is minimized.

重要的是第一个。如果您从 GUI 应用程序调用 ShellExecute,那么您希望应用程序中当前事件的窗口拥有所有窗口。因此,传递MyForm.Handle

如果您的应用程序中没有 GUI,则传递 0。

在代码示例中,对 ShellExecute 的调用根本不显示任何 UI。所以你通过什么并不重要。但是,如果您的调用导致显示错误对话框,那么您传递的窗口句柄将变得相关。

关于delphi - HWND 在 ShellExecute 中起什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13642211/

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