1
votes

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?

1

1 Answers

1
votes

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).