views:

50

answers:

1

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  A: 

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

Lorenzo
I added the code I'm using to get and set the hwndOwner, but it still doesn't work even when hwndOwner is not NULL. Maybe this is more of an SDL question now.
JDS
Hmm tomorrow I'll try myself (in plain C+WinAPI as I don't know SDL) and I'll let you know...
Lorenzo
I know this works in a normal Win32 app running in full-screen. I have no idea about SDL, but I don't know what it could be doing different.
casablanca