是否可以在全屏应用程序中创建 GetOpenFileName 对话框?

发布于 2024-09-08 12:07:27 字数 941 浏览 10 评论 0原文

我有一个用 C++ 编写的全屏应用程序,想打开一个对话框窗口,以便用户可以选择要打开的文件,而应用程序不会脱离全屏模式。

在 Windows 上,要以全屏模式运行,我调用 ChangeDisplaySettings(&settings, CDS_FULLSCREEN)。 (从技术上讲,我使用的是 SDL,但这是它使用的调用。)

要打开文件对话框,我使用以下代码:

HWND hWnd = NULL;
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
if( SDL_GetWMInfo(&wmInfo) ) {
    hWnd = wmInfo.window; // Note: This is sucessful, and hWnd != NULL
}

OPENFILENAMEW ofn;
wchar_t fileName[MAX_PATH] = L"";
ZeroMemory(&ofn, sizeof(ofn));

ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFile = fileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST;

if( GetOpenFileNameW( &ofn ) ) {
    DoSomethingWith( fileName );
}

运行时,hWnd 不为 NULL,但创建此对话框时,它将窗口焦点转移到该对话框会脱离全屏应用程序,类似于全屏时通过 Alt-Tab 键切换到另一个窗口。选择文件并关闭“打开文件”对话框后,我必须手动切换回全屏应用程序。

是否可以使用现有的 Windows 对话框执行我想要的操作,或者我是否必须编写自己的应用内文件浏览系统或仅在窗口模式下运行?

I have a fullscreen application wrtten in C++ and would like to open a dialog window so the user can select a file to be opened without the app breaking out of fullscreen mode.

On Windows, to run in fullscreen mode, I call ChangeDisplaySettings(&settings, CDS_FULLSCREEN). (Technically, I am using SDL, but this is the call it uses.)

To open the file dialog, I use the following code:

HWND hWnd = NULL;
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
if( SDL_GetWMInfo(&wmInfo) ) {
    hWnd = wmInfo.window; // Note: This is sucessful, and hWnd != NULL
}

OPENFILENAMEW ofn;
wchar_t fileName[MAX_PATH] = L"";
ZeroMemory(&ofn, sizeof(ofn));

ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFile = fileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST;

if( GetOpenFileNameW( &ofn ) ) {
    DoSomethingWith( fileName );
}

When run, hWnd is not NULL, but when this dialog is created, it shifts the window focus to the dialog, which breaks out of the fullscreen app, similar to alt-tabbing to another window while in fullscreen. Once the file is selected and the Open File dialog closes, I have to manually switch back to the fullscreen app.

Is it possible to do what I want using existing Windows dialogs, or do I have to write my own in-app file browsing system or run in windowed mode only?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

死开点丶别碍眼 2024-09-15 12:07:27

当然...您只需将全屏窗口的 HWND 作为“打开文件”公共对话框的父级传递(它是 OPENFILENAME 结构中的 hwndOwner 参数,传递给 GetOpenFileName)。

Sure... you just have to pass the HWND of the full screen window as the parent of the Open File common dialog (it is the hwndOwner parameter in the OPENFILENAME structure that is passed to GetOpenFileName).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文