gpt4 book ai didi

ShellExecute() 的句柄 - 父窗口?

转载 作者:行者123 更新时间:2023-12-02 01:16:30 26 4
gpt4 key购买 nike

我正在尝试使用ShellExecute在 Excel 中打开文件。我在MSDN论坛上阅读了有关该函数的信息,发现了以下有关句柄的信息,即第一个参数:

“hwnd [in] 用于显示用户界面 (UI) 或错误消息的所有者窗口的句柄。如果操作不与窗口关联,则该值可以为 NULL。”

我还听说这被称为父窗口的句柄。什么是父/所有者窗口?正如您在下面看到的,我使用 NULL 作为句柄,但由于该操作确实与窗口相关联,因此我可能需要一个句柄,但我不知道该句柄使用什么。

ShellExecute(NULL, "open" ,"Excel.exe", 
"C:\\Documents and Settings\\Lab1\\My Documents\\Test.xls",
NULL, SW_SHOWNORMAL);

最佳答案

usually 0

hwnd : parent window that will receive a possible messagebox. This parameter is usually 0.

它指的是顶层窗口:您打开的窗口没有任何父窗口,并且是正在执行的应用程序的主窗口。

当您在应用程序之间切换(ALT-TAB)时,您将按 z 顺序(例如)显示下一个顶级窗口(父句柄等于 0 的下一个应用程序)。

当然,您的应用程序的父级 can not be the Desktop Window itself :

If you create a child window whose parent is GetDesktopWindow(), your window is now glued to the desktop window. If your window then calls something like MessageBox(), well that's a modal dialog, and then the rules above kick in and the desktop gets disabled and the machine is toast.

对于路径,我建议在简单引号周围使用双引号:"' ... ' "

"'C:\\Documents and Settings\\Lab1\\My Documents\\Test.xls'"

也可以使用双双引号(未经测试):"""... """

"""C:\\Documents and Settings\\Lab1\\My Documents\\Test.xls"""

,如 this thread 所示.

<小时/>

实际上,正如 your other question 中提到的通过 AndyMesidin ,以及 ShellExecute Function manual ,您可以打开该文件,并在参数中传递其路径。

ShellExecute( NULL, "open", 
"Test.xls", "C:\\Documents and Settings\\Lab1\\My Documents\\",
NULL, SW_SHOWNORMAL);

这意味着 Excel 是打开 .xls 扩展文件的默认应用程序。

关于ShellExecute() 的句柄 - 父窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/315527/

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