是否可以在全屏应用程序中创建 GetOpenFileName 对话框?
我有一个用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然...您只需将全屏窗口的 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 theOPENFILENAME
structure that is passed toGetOpenFileName
).