Settled OpenFile() modality issues on Windows.

This commit is contained in:
Pietro Gagliardi 2014-08-25 21:03:17 -04:00
parent e25831c609
commit a952cfcc58
1 changed files with 29 additions and 6 deletions

View File

@ -3,17 +3,40 @@
#include "winapi_windows.h" #include "winapi_windows.h"
#include "_cgo_export.h" #include "_cgo_export.h"
static LRESULT CALLBACK dialogSubProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR data)
{
switch (uMsg) {
case WM_COMMAND:
// we must re-enable other windows in the right order (see http://blogs.msdn.com/b/oldnewthing/archive/2004/02/27/81155.aspx)
if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDCANCEL)
SendMessageW(msgwin, msgEndModal, 0, 0);
break; // let the dialog handle it now
case WM_NCDESTROY:
if ((*fv_RemoveWindowSubclass)(hwnd, dialogSubProc, id) == FALSE)
xpanic("error removing dialog subclass (which was for its own event handler)", GetLastError());
}
return (*fv_DefSubclassProc)(hwnd, uMsg, wParam, lParam);
}
// this should be reasonable // this should be reasonable
#define NFILENAME 4096 #define NFILENAME 4096
static UINT_PTR CALLBACK openSaveFileHook(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) static UINT_PTR CALLBACK openSaveFileHook(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
// the hook procedure is documented as being the dialog procedure for a special child dialog box, not the main one if (uMsg == WM_INITDIALOG) {
// as such, the WM_DESTROY here is for that child dialog box, not for the main one HWND parent;
// I /think/ this would be perfect for re-enabling other windows in the right order (see http://blogs.msdn.com/b/oldnewthing/archive/2004/02/27/81155.aspx)
// TODO THIS DOES NOT WORK parent = GetParent(hwnd);
if (uMsg == WM_DESTROY) if (parent == NULL)
SendMessageW(msgwin, msgEndModal, 0, 0); xpanic("error gettign parent of OpenFile() dialog for event handling", GetLastError());
if ((*fv_SetWindowSubclass)(parent, dialogSubProc, 0, (DWORD_PTR) NULL) == FALSE)
xpanic("error subclassing OpenFile() dialog to give it its own event handler", GetLastError());
} else if (uMsg == WM_NOTIFY) {
OFNOTIFY *of = (OFNOTIFY *) lParam;
if (of->hdr.code == CDN_FILEOK)
SendMessageW(msgwin, msgEndModal, 0, 0);
}
return 0; return 0;
} }