ShellExecute()的句柄-父窗口? [英] Handle for ShellExecute() - Parent Window?

查看:178
本文介绍了ShellExecute()的句柄-父窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use ShellExecute to open a file in Excel. I was reading about the function on MSDN forums, and I found the folowing information about the handle, which is the first parameter:

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

"hwnd [in] A handle to the owner window used for displaying a user interface (UI) or error messages. This value can be NULL if the operation is not associated with a window."

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

I have also heard this referred to as the handle to the parent window. What is the parent/owner window? As you see below I am using NULL for the handle, but since the operation is indeed associated with a window, I probably need a handle, but I don't know what to use for the handle.

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

推荐答案

通常为 0

hwnd:将接收可能的消息框的父窗口.此参数通常为0.

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

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

It refers to the top-level window: the window you are opening does not have any parent, and is the main window for the application being executed.

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

When you are switching between applications (ALT-TAB), you are displaying the next top-level window (the next app with a parent handle equals to 0) in the z-order (for instance).

当然,您的应用程序的父不能桌面窗口本身:

Of course, the parent to your app can not be the Desktop Window itself:

如果创建一个父窗口为GetDesktopWindow()的子窗口,则该窗口现在将粘贴到桌面窗口.如果您的窗口随后调用了诸如MessageBox()之类的内容,那么这是一个模式对话框,然后启动上述规则,桌面将被禁用,机器将被吐司.

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.

对于路径,我建议使用双引号将简单引号引起来:'...'"

For the path, I would advice double quotes surrounding simple quotes: " ' ... ' "

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

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

Could work also (untested) with double double quotes : " "" ... "" "

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

,如该线程.

实际上,正如您的其他问题中所述/andy>安迪,并通过 Mesidin

Actually, as mentioned in your other question by Andy and by Mesidin, and in ShellExecute Function manual, you can open the file, and pass its path in parameter.

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

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

That means Excel is the default application for opening .xls extension files though.

这篇关于ShellExecute()的句柄-父窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆