]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
GUI sub window handling improvements.
authorToni Wilen <twilen@winuae.net>
Fri, 29 Dec 2023 15:50:10 +0000 (17:50 +0200)
committerToni Wilen <twilen@winuae.net>
Fri, 29 Dec 2023 15:50:10 +0000 (17:50 +0200)
od-win32/hardfile_win32.cpp
od-win32/resources/winuae.rc
od-win32/win32gui.cpp
od-win32/win32gui.h
od-win32/win32gui_extra.cpp

index a4a763a0b900b41c09031f30524306a2bb94a21c..897a98e35dfa7aec5694cfa37fea7f7b7dd3cf80 100644 (file)
@@ -437,20 +437,15 @@ int isharddrive (const TCHAR *name)
 
 static const TCHAR *hdz[] = { _T("hdz"), _T("zip"), _T("rar"), _T("7z"), NULL };
 
-static int progressdialogreturn;
-static int progressdialogactive;
-
 static INT_PTR CALLBACK ProgressDialogProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
 {
        switch(msg)
        {
        case WM_DESTROY:
-               PostQuitMessage (0);
-               progressdialogactive = 0;
+               PostQuitMessage(0);
                return TRUE;
        case WM_CLOSE:
-               if (progressdialogreturn < 0)
-                       progressdialogreturn = 0;
+               CustomDialogClose(hDlg, 0);
                return TRUE;
        case WM_INITDIALOG:
                return TRUE;
@@ -458,7 +453,7 @@ static INT_PTR CALLBACK ProgressDialogProc (HWND hDlg, UINT msg, WPARAM wParam,
                switch (LOWORD(wParam))
                {
                case IDCANCEL:
-                       progressdialogreturn = 0;
+                       CustomDialogClose(hDlg, 0);
                        return TRUE;
                }
                break;
@@ -696,7 +691,7 @@ static TCHAR *bintotextline(TCHAR *out, uae_u8 *data, int size)
        return out + _tcslen(out);
 }
 
-static int chsdialogactive, chs_secs, chs_cyls, chs_heads;
+static int chs_secs, chs_cyls, chs_heads;
 static TCHAR *parse_identity(uae_u8 *data, struct ini_data *ini, TCHAR *s)
 {
        uae_u16 v;
@@ -896,21 +891,19 @@ static bool hd_get_meta_hack_realtek(HWND hDlg, HANDLE h, uae_u8 *data, uae_u8 *
                infotxt = _T("Realtek hack, remove and insert the card.");
        }
 
-       progressdialogreturn = -1;
-       progressdialogactive = 1;
-       struct newresource *res;
-       HWND hwnd = CustomCreateDialog(&res, IDD_PROGRESSBAR, hDlg, ProgressDialogProc);
-       if (hwnd == NULL)
+       SAVECDS;
+       HWND hwnd = CustomCreateDialog(IDD_PROGRESSBAR, hDlg, ProgressDialogProc, &cdstate);
+       if (hwnd == NULL) {
+               RESTORECDS;
                return false;
+       }
        HWND hwndprogress = GetDlgItem (hwnd, IDC_PROGRESSBAR);
        ShowWindow(hwndprogress, SW_HIDE);
        HWND hwndprogresstxt = GetDlgItem (hwnd, IDC_PROGRESSBAR_TEXT);
        ShowWindow(hwnd, SW_SHOW);
 
        int tcnt = 0;
-       for (;;) {
-               if (progressdialogreturn >= 0)
-                       break;
+       while(cdstate.active) {
                MSG msg;
                SendMessage (hwndprogresstxt, WM_SETTEXT, 0, (LPARAM)infotxt);
                while (PeekMessage (&msg, hwnd, 0, 0, PM_REMOVE)) {
@@ -936,9 +929,8 @@ static bool hd_get_meta_hack_realtek(HWND hDlg, HANDLE h, uae_u8 *data, uae_u8 *
                        tcnt = 0;
                }
        }
-       freescaleresource(res);
 
-       if (progressdialogactive) {
+       if (cdstate.active) {
                DestroyWindow (hwnd);
                MSG msg;
                while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) {
@@ -946,6 +938,7 @@ static bool hd_get_meta_hack_realtek(HWND hDlg, HANDLE h, uae_u8 *data, uae_u8 *
                        DispatchMessage (&msg);
                }
        }
+       RESTORECDS;
 
        memset(data, 0, 512);
        memcpy(cmd, realtek_read, sizeof(realtek_read));
@@ -1360,8 +1353,7 @@ static INT_PTR CALLBACK CHSDialogProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
                PostQuitMessage(0);
                return TRUE;
        case WM_CLOSE:
-               chsdialogactive = 0;
-               DestroyWindow(hDlg);
+               CustomDialogClose(hDlg, 0);
                return TRUE;
        case WM_INITDIALOG:
                SetDlgItemInt(hDlg, IDC_CHS_SECTORS, chs_secs, FALSE);
@@ -1381,12 +1373,10 @@ static INT_PTR CALLBACK CHSDialogProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
                        chs_heads = GetDlgItemInt(hDlg, IDC_CHS_HEADS, NULL, FALSE);
                        break;
                case IDOK:
-                       chsdialogactive = -1;
-                       DestroyWindow(hDlg);
+                       CustomDialogClose(hDlg, 1);
                        return TRUE;
                case IDCANCEL:
-                       chsdialogactive = 0;
-                       DestroyWindow(hDlg);
+                       CustomDialogClose(hDlg, 0);
                        return TRUE;
                }
                break;
@@ -1403,7 +1393,8 @@ static int gethdfchs(HWND hDlg, struct uae_driveinfo *udi, HANDLE h, int *cylsp,
        DWORD err = 0;
        HFONT font;
        HWND hwnd;
-       struct newresource *res;
+
+       SAVECDS;
 
        memset(data, 0, 512);
        memset(cmd, 0, sizeof(cmd));
@@ -1430,8 +1421,7 @@ static int gethdfchs(HWND hDlg, struct uae_driveinfo *udi, HANDLE h, int *cylsp,
                parse_identity(udi->identity, NULL, NULL);
        }
 
-       chsdialogactive = 1;
-       hwnd = CustomCreateDialog(&res, IDD_CHSQUERY, hDlg, CHSDialogProc);
+       hwnd = CustomCreateDialog(IDD_CHSQUERY, hDlg, CHSDialogProc, &cdstate);
        if (hwnd == NULL) {
                err = -15;
                goto end;
@@ -1439,7 +1429,7 @@ static int gethdfchs(HWND hDlg, struct uae_driveinfo *udi, HANDLE h, int *cylsp,
        font = CreateFont(getscaledfontsize(-1, hDlg), 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Lucida Console"));
        if (font)
                SendMessage(GetDlgItem(hwnd, IDD_CHSQUERY), WM_SETFONT, WPARAM(font), FALSE);
-       while (chsdialogactive == 1) {
+       while (cdstate.active) {
                MSG msg;
                int ret;
                WaitMessage();
@@ -1452,9 +1442,10 @@ static int gethdfchs(HWND hDlg, struct uae_driveinfo *udi, HANDLE h, int *cylsp,
                        }
                }
        }
-       freescaleresource(res);
-       DeleteObject(font);
-       if (chsdialogactive == 0) {
+       if (font) {
+               DeleteObject(font);
+       }
+       if (cdstate.status == 0) {
                err = -100;
                goto end;
        }
@@ -1470,6 +1461,7 @@ static int gethdfchs(HWND hDlg, struct uae_driveinfo *udi, HANDLE h, int *cylsp,
                goto end;
        }
 end:
+       RESTORECDS;
        VirtualFree(data, 0, MEM_RELEASE);
        if (cylsp)
                *cylsp = cyls;
@@ -1481,7 +1473,6 @@ end:
 }
 
 
-static int stringboxdialogactive;
 static TCHAR geometry_file[MAX_DPATH];
 static struct ini_data *hdini;
 static INT_PTR CALLBACK StringBoxDialogProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
@@ -1492,8 +1483,7 @@ static INT_PTR CALLBACK StringBoxDialogProc (HWND hDlg, UINT msg, WPARAM wParam,
                PostQuitMessage (0);
                return TRUE;
        case WM_CLOSE:
-               stringboxdialogactive = 0;
-               DestroyWindow (hDlg);
+               CustomDialogClose(hDlg, 0);
                return TRUE;
        case WM_INITDIALOG:
                ShowWindow(GetDlgItem (hDlg, IDC_SAVEBOOTBLOCK), SW_SHOW);
@@ -1512,12 +1502,11 @@ static INT_PTR CALLBACK StringBoxDialogProc (HWND hDlg, UINT msg, WPARAM wParam,
                        break;
                }
                case IDOK:
-                       stringboxdialogactive = -1;
+                       CustomDialogClose(hDlg, 1);
                        DestroyWindow (hDlg);
                        return TRUE;
                case IDCANCEL:
-                       stringboxdialogactive = 0;
-                       DestroyWindow (hDlg);
+                       CustomDialogClose(hDlg, 0);
                        return TRUE;
                }
                break;
@@ -1538,7 +1527,6 @@ void hd_get_meta(HWND hDlg, int idx, TCHAR *geometryfile)
        bool atapi = false;
        HWND hwnd;
        bool empty = true;
-       struct newresource *res;
 
        geometryfile[0] = 0;
        text = xcalloc(TCHAR, 100000);
@@ -1665,15 +1653,15 @@ doout:
                _tcscat(geometry_file, _T(".geo"));
        makesafefilename(geometry_file, true);
 
-       stringboxdialogactive = 1;
+       SAVECDS;
        hdini = ini;
-       hwnd = CustomCreateDialog(&res, IDD_DISKINFO, hDlg, StringBoxDialogProc);
+       hwnd = CustomCreateDialog(IDD_DISKINFO, hDlg, StringBoxDialogProc, &cdstate);
        if (hwnd != NULL) {
                HFONT font = CreateFont (getscaledfontsize(-1, hDlg), 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Lucida Console"));
                if (font)
                        SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETFONT, WPARAM(font), FALSE);
                SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETTEXT, 0, (LPARAM)text);
-               while (stringboxdialogactive == 1) {
+               while (cdstate.active) {
                        MSG msg;
                        int ret;
                        WaitMessage ();
@@ -1685,12 +1673,12 @@ doout:
                                        DispatchMessage (&msg);
                                }
                        }
-                       if (stringboxdialogactive == -1)
-                               break;
                }
-               DeleteObject (font);
-               freescaleresource(res);
+               if (font) {
+                       DeleteObject (font);
+               }
        }
+       RESTORECDS;
 
 end:
        if (ini)
@@ -3659,15 +3647,18 @@ int harddrive_to_hdf (HWND hDlg, struct uae_prefs *p, int idx)
        TCHAR path[MAX_DPATH], tmp[MAX_DPATH], tmp2[MAX_DPATH];
        DWORD retcode = 0;
        HWND hwnd, hwndprogress, hwndprogresstxt;
-       struct newresource *res;
        MSG msg;
-       int pct, cnt;
+       int pct;
        DWORD r;
        bool chsmode = false;
        DWORD erc = 0;
        int cyls = 0, heads = 0, secs = 0;
        int cyl = 0, head = 0;
        int specialaccessmode = 0;
+       int progressdialogreturn = 0;
+       int seconds = -1;
+
+       SAVECDS;
 
        cache = VirtualAlloc (NULL, COPY_CACHE_SIZE, MEM_COMMIT, PAGE_READWRITE);
        if (!cache)
@@ -3733,22 +3724,24 @@ int harddrive_to_hdf (HWND hDlg, struct uae_prefs *p, int idx)
        SetFilePointer (hdst, 0, &li.HighPart, FILE_BEGIN);
        li.QuadPart = 0;
        SetFilePointer (h, 0, &li.HighPart, FILE_BEGIN);
-       progressdialogreturn = -1;
-       progressdialogactive = 1;
-       hwnd = CustomCreateDialog(&res, IDD_PROGRESSBAR, hDlg, ProgressDialogProc);
+       hwnd = CustomCreateDialog(IDD_PROGRESSBAR, hDlg, ProgressDialogProc, &cdstate);
        if (hwnd == NULL)
                goto err;
        hwndprogress = GetDlgItem (hwnd, IDC_PROGRESSBAR);
        hwndprogresstxt = GetDlgItem (hwnd, IDC_PROGRESSBAR_TEXT);
        ShowWindow (hwnd, SW_SHOW);
        pct = 0;
-       cnt = 1000;
        sizecnt = 0;
        written = 0;
+       
        for (;;) {
+               progressdialogreturn = cdstate.active > 0 ? -1 : 0;
                if (progressdialogreturn >= 0)
                        break;
-               if (cnt >= 100) {
+               SYSTEMTIME t;
+               GetLocalTime(&t);
+               if (t.wSecond != seconds) {
+                       seconds = t.wSecond;
                        SendMessage (hwndprogress, PBM_SETPOS, (WPARAM)pct, 0);
                        if (chsmode) {
                                _stprintf(tmp2, _T("Cyl %d/%d Head %d/%d"), cyl, cyls, head, heads);
@@ -3763,7 +3756,6 @@ int harddrive_to_hdf (HWND hDlg, struct uae_prefs *p, int idx)
                                        DispatchMessage (&msg);
                                }
                        }
-                       cnt = 0;
                }
                got = gotdst = 0;
                li.QuadPart = sizecnt;
@@ -3827,12 +3819,10 @@ int harddrive_to_hdf (HWND hDlg, struct uae_prefs *p, int idx)
                        progressdialogreturn = 2;
                        break;
                }
-               cnt++;
                sizecnt += got;
                pct = (int)(sizecnt * 100 / size);
        }
-       freescaleresource(res);
-       if (progressdialogactive) {
+       if (cdstate.active) {
                DestroyWindow (hwnd);
                while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) {
                        TranslateMessage (&msg);
@@ -3860,6 +3850,7 @@ err:
        }
 
 ok:
+       RESTORECDS;
        if (h != INVALID_HANDLE_VALUE)
                CloseHandle (h);
        if (cache)
index a5cb574a051189c03bb3ba92c3965099e64198e7..edcd9f04d8d5bb3b7d7644cb80537d67b0ae4cbd 100644 (file)
@@ -883,11 +883,11 @@ BEGIN
     CONTROL         "Disable sound output",IDC_AVIOUTPUT_NOSOUNDOUTPUT,
                     "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,114,176,10
     CONTROL         "Disable sound sync",IDC_AVIOUTPUT_NOSOUNDSYNC,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,210,114,171,10
-    CONTROL         "AVI output enabled",IDC_AVIOUTPUT_ACTIVATED,"Button",BS_AUTORADIOBUTTON | BS_PUSHLIKE | BS_FLAT,15,129,144,14
+    CONTROL         "AVI output enabled",IDC_AVIOUTPUT_ACTIVATED,"Button",BS_AUTOCHECKBOX | BS_PUSHLIKE | BS_FLAT,15,129,144,14
     GROUPBOX        "Ripper",IDC_STATIC,1,155,393,65
     PUSHBUTTON      "Save screenshot",IDC_SCREENSHOT,28,169,87,14
     PUSHBUTTON      "Pro Wizard 1.62",IDC_PROWIZARD,162,169,87,14,WS_DISABLED
-    CONTROL         "Sample ripper",IDC_SAMPLERIPPER_ACTIVATED,"Button",BS_AUTORADIOBUTTON | BS_PUSHLIKE | BS_FLAT,280,169,87,14
+    CONTROL         "Sample ripper",IDC_SAMPLERIPPER_ACTIVATED,"Button",BS_AUTOCHECKBOX | BS_PUSHLIKE | BS_FLAT,280,169,87,14
     CONTROL         "Take screenshot before filtering",IDC_SCREENSHOT_ORIGINALSIZE,
                     "Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,192,130,10
     CONTROL         "Create 256 color palette indexed screenshot if possible",IDC_SCREENSHOT_PALETTED,
@@ -895,8 +895,8 @@ BEGIN
     CONTROL         "Autoclip screenshot",IDC_SCREENSHOT_CLIP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,210,192,169,10
     CONTROL         "Continuous screenshots",IDC_SCREENSHOT_AUTO,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,210,206,169,10
     GROUPBOX        "Re-recorder",IDC_STATIC,1,227,393,70
-    CONTROL         "Play recording",IDC_STATEREC_PLAY,"Button",BS_AUTORADIOBUTTON | BS_PUSHLIKE | BS_FLAT,53,239,87,14
-    CONTROL         "Re-recording enabled",IDC_STATEREC_RECORD,"Button",BS_AUTORADIOBUTTON | BS_PUSHLIKE | BS_FLAT,214,239,118,14
+    CONTROL         "Play recording",IDC_STATEREC_PLAY,"Button",BS_AUTOCHECKBOX | BS_PUSHLIKE | BS_FLAT,53,239,87,14
+    CONTROL         "Re-recording enabled",IDC_STATEREC_RECORD,"Button",BS_AUTOCHECKBOX | BS_PUSHLIKE | BS_FLAT,214,239,118,14
     CONTROL         "Automatic replay",IDC_STATEREC_AUTOPLAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,54,262,129,10
     PUSHBUTTON      "Save recording",IDC_STATEREC_SAVE,214,257,118,14
     RTEXT           "Recording rate (seconds):",IDC_STATIC,15,280,121,10,SS_CENTERIMAGE | WS_TABSTOP
@@ -1302,7 +1302,7 @@ BEGIN
 END
 
 IDD_INFOBOX DIALOGEX 0, 0, 420, 68
-STYLE DS_LOCALEDIT | DS_SETFONT | DS_MODALFRAME | DS_CENTERMOUSE | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+STYLE DS_LOCALEDIT | DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_CENTERMOUSE | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "Scanning ROM image files..."
 FONT 8, "MS Sans Serif", 0, 0, 0x0
 BEGIN
@@ -1314,9 +1314,9 @@ BEGIN
 END
 
 IDD_LIST DIALOGEX 0, 0, 316, 206
-STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | DS_CENTERMOUSE | WS_POPUP | WS_CAPTION | WS_SYSMENU
+STYLE DS_LOCALEDIT | DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_CENTERMOUSE | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
 CAPTION "Options"
-FONT 8, "MS Shell Dlg", 400, 0, 0x1
+FONT 8, "MS Sans Serif", 0, 0, 0x0
 BEGIN
     DEFPUSHBUTTON   "OK",IDOK,205,185,50,14
     PUSHBUTTON      "Cancel",IDCANCEL,259,185,50,14
index 32171950879b9a4f9add17eb0105c4ec57021fbd..048018d6cae1cb8e15986eb6d5ee3d2ee7549b83 100644 (file)
@@ -142,10 +142,8 @@ static HMODULE hHtmlHelp;
 pathtype path_type;
 
 int externaldialogactive;
-static int stringboxdialogactive;
-static int customdialogactive;
-static struct newresource *customdialogres;
-static HWND customdialoghwnd;
+
+struct customdialogstate cdstate;
 
 static int CustomCreateDialogBox(int templ, HWND hDlg, DLGPROC proc);
 
@@ -322,13 +320,13 @@ static void CALLBACK gui_control_cb(HWND h, UINT v, UINT_PTR v3, DWORD v4)
                if (ha) {
                        HWND p = GetParent(ha);
                        HWND mainhwnd = AMonitors[0].hAmigaWnd;
-                       if (p && (p == customdialoghwnd || p == guiDlg || p == mainhwnd)) {
+                       if (p && (p == cdstate.hwnd || p == guiDlg || p == mainhwnd)) {
                                process_gui_control(ha, NULL);
                        }
                }
-       } else if (customdialogactive > 0 && customdialogres && customdialoghwnd) {
-               if (ha == customdialoghwnd) {
-                       process_gui_control(customdialoghwnd, customdialogres);
+       } else if (cdstate.active) {
+               if (ha == cdstate.hwnd) {
+                       process_gui_control(cdstate.hwnd, cdstate.res);
                }
        } else {
                if (ha == h) {
@@ -490,7 +488,7 @@ static INT_PTR CALLBACK StringBoxDialogProc (HWND hDlg, UINT msg, WPARAM wParam,
                PostQuitMessage (0);
                return TRUE;
        case WM_CLOSE:
-               stringboxdialogactive = 0;
+               CustomDialogClose(hDlg, 0);
                DestroyWindow (hDlg);
                return TRUE;
        case WM_INITDIALOG:
@@ -499,12 +497,10 @@ static INT_PTR CALLBACK StringBoxDialogProc (HWND hDlg, UINT msg, WPARAM wParam,
                switch (LOWORD (wParam))
                {
                case IDOK:
-                       stringboxdialogactive = -1;
-                       DestroyWindow (hDlg);
+                       CustomDialogClose(hDlg, 1);
                        return TRUE;
                case IDCANCEL:
-                       stringboxdialogactive = 0;
-                       DestroyWindow (hDlg);
+                       CustomDialogClose(hDlg, 0);
                        return TRUE;
                }
                break;
@@ -1829,8 +1825,6 @@ static int isromext (const TCHAR *path, bool deepscan)
        return 0;
 }
 
-static bool infoboxdialogstate;
-static HWND infoboxhwnd;
 static INT_PTR CALLBACK InfoBoxDialogProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
 {
        bool handled;
@@ -1843,18 +1837,16 @@ static INT_PTR CALLBACK InfoBoxDialogProc (HWND hDlg, UINT msg, WPARAM wParam, L
        {
        case WM_DESTROY:
                PostQuitMessage (0);
-               infoboxdialogstate = false;
+               CustomDialogClose(hDlg, 1);
                return TRUE;
        case WM_CLOSE:
-               DestroyWindow (hDlg);
-               infoboxdialogstate = false;
+               CustomDialogClose(hDlg, 1);
        return TRUE;
        case WM_COMMAND:
                switch (LOWORD (wParam))
                {
                case IDCANCEL:
-                       infoboxdialogstate = false;
-                       DestroyWindow (hDlg);
+                       CustomDialogClose(hDlg, 1);
                        return TRUE;
                }
                break;
@@ -1864,7 +1856,9 @@ static INT_PTR CALLBACK InfoBoxDialogProc (HWND hDlg, UINT msg, WPARAM wParam, L
 static bool scan_rom_hook (const TCHAR *name, int line)
 {
        MSG msg;
-       if (!infoboxhwnd)
+       if (cdstate.status)
+               return false;
+       if (!cdstate.active)
                return true;
        if (name != NULL) {
                const TCHAR *s = NULL;
@@ -1875,15 +1869,15 @@ static bool scan_rom_hook (const TCHAR *name, int line)
                        if (s)
                                s++;
                }
-               SetWindowText (GetDlgItem (infoboxhwnd, line == 1 ? IDC_INFOBOX_TEXT1 : (line == 2 ? IDC_INFOBOX_TEXT2 : IDC_INFOBOX_TEXT3)), s ? s : name);
+               SetWindowText (GetDlgItem (cdstate.hwnd, line == 1 ? IDC_INFOBOX_TEXT1 : (line == 2 ? IDC_INFOBOX_TEXT2 : IDC_INFOBOX_TEXT3)), s ? s : name);
        }
-       while (PeekMessage (&msg, infoboxhwnd, 0, 0, PM_REMOVE)) {
-               if (!IsDialogMessage (infoboxhwnd, &msg)) {
+       while (PeekMessage (&msg, cdstate.hwnd, 0, 0, PM_REMOVE)) {
+               if (!IsDialogMessage (cdstate.hwnd, &msg)) {
                        TranslateMessage (&msg);
                        DispatchMessage (&msg);
                }
        }
-       return infoboxdialogstate;
+       return cdstate.active;
 }
 
 static int scan_rom_2 (struct zfile *f, void *vrsd)
@@ -2111,7 +2105,7 @@ int scan_roms (HWND hDlg, int show)
        UAEREG *fkey, *fkey2;
        TCHAR *paths[MAX_ROM_PATHS];
        MSG msg;
-       struct newresource *res = NULL;
+       HWND hwnd = NULL;
 
        if (recursive)
                return 0;
@@ -2119,18 +2113,18 @@ int scan_roms (HWND hDlg, int show)
 
        ret = 0;
 
+       SAVECDS;
+
        regdeletetree (NULL, _T("DetectedROMs"));
        fkey = regcreatetree (NULL, _T("DetectedROMs"));
        if (fkey == NULL)
                goto end;
 
-       infoboxdialogstate = true;
-       infoboxhwnd = NULL;
+
        if (!rp_isactive ()) {
-               HWND hwnd = CustomCreateDialog(&res, IDD_INFOBOX, hDlg, InfoBoxDialogProc);
+               hwnd = CustomCreateDialog(IDD_INFOBOX, hDlg, InfoBoxDialogProc, &cdstate);
                if (!hwnd)
                        goto end;
-               infoboxhwnd = hwnd;
        }
 
        cnt = 0;
@@ -2181,16 +2175,16 @@ int scan_roms (HWND hDlg, int show)
        }
 
 end:
-       if (infoboxhwnd) {
-               HWND hwnd = infoboxhwnd;
-               infoboxhwnd = NULL;
+       if (hwnd) {
                DestroyWindow (hwnd);
                while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE)) {
                        TranslateMessage (&msg);
                        DispatchMessage (&msg);
                }
-               FreeResource(res);
        }
+
+       RESTORECDS;
+
        read_rom_list(false);
        if (show)
                show_rom_list ();
@@ -2623,35 +2617,31 @@ static void eject_cd (void)
 
 void gui_infotextbox(HWND hDlg, const TCHAR *text)
 {
-       stringboxdialogactive = 1;
-       struct newresource *res;
-       HWND hwnd = CustomCreateDialog(&res, IDD_DISKINFO, hDlg ? hDlg : hGUIWnd, StringBoxDialogProc);
-       if (hwnd == NULL)
-               return;
-
-       HFONT font = CreateFont (getscaledfontsize(-1, hDlg), 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Lucida Console"));
-       if (font)
-               SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETFONT, WPARAM(font), FALSE);
-       SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETTEXT, 0, (LPARAM)text);
-       while (stringboxdialogactive == 1) {
-               MSG msg;
-               int ret;
-               WaitMessage ();
-               while ((ret = GetMessage (&msg, NULL, 0, 0))) {
-                       if (ret == -1)
-                               break;
-                       if (!IsWindow (hwnd) || !IsDialogMessage (hwnd, &msg)) {
-                               TranslateMessage (&msg);
-                               DispatchMessage (&msg);
+       SAVECDS;
+       HWND hwnd = CustomCreateDialog(IDD_DISKINFO, hDlg ? hDlg : hGUIWnd, StringBoxDialogProc, &cdstate);
+       if (hwnd != NULL) {
+               HFONT font = CreateFont (getscaledfontsize(-1, hDlg), 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Lucida Console"));
+               if (font)
+                       SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETFONT, WPARAM(font), FALSE);
+               SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETTEXT, 0, (LPARAM)text);
+               while (cdstate.active) {
+                       MSG msg;
+                       int ret;
+                       WaitMessage();
+                       while ((ret = GetMessage(&msg, NULL, 0, 0))) {
+                               if (ret == -1)
+                                       break;
+                               if (!IsWindow(hwnd) || !IsDialogMessage(hwnd, &msg)) {
+                                       TranslateMessage(&msg);
+                                       DispatchMessage(&msg);
+                               }
                        }
-                       if (stringboxdialogactive == -1)
-                               break;
+               }
+               if (font) {
+                       DeleteObject(font);
                }
        }
-       freescaleresource(res);
-       if (font) {
-               DeleteObject(font);
-       }
+       RESTORECDS;
 }
 
 static void infofloppy (HWND hDlg, int n)
@@ -2659,7 +2649,6 @@ static void infofloppy (HWND hDlg, int n)
        struct diskinfo di;
        TCHAR tmp2[MAX_DPATH], tmp1[MAX_DPATH], tmp3[MAX_DPATH];
        TCHAR text[20000];
-       struct newresource *res;
 
        DISK_examine_image (&workprefs, n, &di, true, tmp3);
        DISK_validate_filename(&workprefs, workprefs.floppyslots[n].df, n, tmp1, 0, NULL, NULL, NULL);
@@ -2722,32 +2711,31 @@ static void infofloppy (HWND hDlg, int n)
                _tcscat (text, _T("\r\n"));
        }
 
-       stringboxdialogactive = 1;
-       HWND hwnd = CustomCreateDialog(&res, IDD_DISKINFO, hDlg, StringBoxDialogProc);
-       if (hwnd == NULL)
-               return;
-
-       HFONT font = CreateFont (getscaledfontsize(-1, hDlg), 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Lucida Console"));
-       if (font)
-               SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETFONT, WPARAM(font), FALSE);
-       SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETTEXT, 0, (LPARAM)text);
-       while (stringboxdialogactive == 1) {
-               MSG msg;
-               int ret;
-               WaitMessage ();
-               while ((ret = GetMessage (&msg, NULL, 0, 0))) {
-                       if (ret == -1)
-                               break;
-                       if (!IsWindow (hwnd) || !IsDialogMessage (hwnd, &msg)) {
-                               TranslateMessage (&msg);
-                               DispatchMessage (&msg);
+       SAVECDS;
+       HWND hwnd = CustomCreateDialog(IDD_DISKINFO, hDlg, StringBoxDialogProc, &cdstate);
+       if (hwnd != NULL) {
+               HFONT font = CreateFont (getscaledfontsize(-1, hDlg), 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Lucida Console"));
+               if (font)
+                       SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETFONT, WPARAM(font), FALSE);
+               SendMessage (GetDlgItem (hwnd, IDC_DISKINFOBOX), WM_SETTEXT, 0, (LPARAM)text);
+               while (cdstate.active) {
+                       MSG msg;
+                       int ret;
+                       WaitMessage ();
+                       while ((ret = GetMessage (&msg, NULL, 0, 0))) {
+                               if (ret == -1)
+                                       break;
+                               if (!IsWindow (hwnd) || !IsDialogMessage (hwnd, &msg)) {
+                                       TranslateMessage (&msg);
+                                       DispatchMessage (&msg);
+                               }
                        }
-                       if (stringboxdialogactive == -1)
-                               break;
+               }
+               if (font) {
+                       DeleteObject(font);
                }
        }
-       freescaleresource(res);
-       DeleteObject (font);
+       RESTORECDS;
 }
 
 static void ejectfloppy (int n)
@@ -18571,39 +18559,38 @@ static void values_to_inputdlg (HWND hDlg)
 static int askinputcustom (HWND hDlg, TCHAR *custom, int maxlen, DWORD titleid)
 {
        HWND hwnd;
-       struct newresource *res;
        TCHAR txt[MAX_DPATH];
 
-       stringboxdialogactive = 1;
-       hwnd = CustomCreateDialog(&res, IDD_STRINGBOX, hDlg, StringBoxDialogProc);
-       if (hwnd == NULL)
-               return 0;
-       if (titleid != 0) {
-               LoadString (hUIDLL, titleid, txt, MAX_DPATH);
-               SetWindowText (hwnd, txt);
-       }
-       txt[0] = 0;
-       SendMessage (GetDlgItem (hwnd, IDC_STRINGBOXEDIT), WM_SETTEXT, 0, (LPARAM)custom);
-       while (stringboxdialogactive == 1) {
-               MSG msg;
-               int ret;
-               WaitMessage ();
-               while ((ret = GetMessage (&msg, NULL, 0, 0))) {
-                       if (ret == -1)
-                               break;
-                       if (!IsWindow (hwnd) || !IsDialogMessage (hwnd, &msg)) {
-                               TranslateMessage (&msg);
-                               DispatchMessage (&msg);
+       SAVECDS;
+       hwnd = CustomCreateDialog(IDD_STRINGBOX, hDlg, StringBoxDialogProc, &cdstate);
+       if (hwnd != NULL) {
+               if (titleid != 0) {
+                       LoadString (hUIDLL, titleid, txt, MAX_DPATH);
+                       SetWindowText (hwnd, txt);
+               }
+               txt[0] = 0;
+               SendMessage (GetDlgItem (hwnd, IDC_STRINGBOXEDIT), WM_SETTEXT, 0, (LPARAM)custom);
+               while (cdstate.active) {
+                       MSG msg;
+                       int ret;
+                       WaitMessage ();
+                       while ((ret = GetMessage (&msg, NULL, 0, 0))) {
+                               if (ret == -1)
+                                       break;
+                               if (!IsWindow (hwnd) || !IsDialogMessage (hwnd, &msg)) {
+                                       TranslateMessage (&msg);
+                                       DispatchMessage (&msg);
+                               }
+                               SendMessage (GetDlgItem (hwnd, IDC_STRINGBOXEDIT), WM_GETTEXT, sizeof txt / sizeof (TCHAR), (LPARAM)txt);
                        }
-                       SendMessage (GetDlgItem (hwnd, IDC_STRINGBOXEDIT), WM_GETTEXT, sizeof txt / sizeof (TCHAR), (LPARAM)txt);
                }
-               if (stringboxdialogactive == -1) {
-                       _tcscpy (custom, txt);
-                       freescaleresource(res);
+               if (cdstate.status == 1) {
+                       _tcscpy(custom, txt);
+                       RESTORECDS;
                        return 1;
                }
        }
-       freescaleresource(res);
+       RESTORECDS;
        return 0;
 }
 
@@ -19566,9 +19553,7 @@ static INT_PTR CALLBACK RemapSpecialsProc(HWND hDlg, UINT msg, WPARAM wParam, LP
 
 static void input_remapspecials(HWND hDlg)
 {
-       struct newresource *res;
-       CustomCreateDialog(&res, IDD_LIST, hDlg, RemapSpecialsProc);
-       freescaleresource(res);
+       CustomCreateDialogBox(IDD_LIST, hDlg, RemapSpecialsProc);
 }
 
 static INT_PTR CALLBACK InputMapDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
@@ -19588,7 +19573,7 @@ static INT_PTR CALLBACK InputMapDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPA
        switch (msg)
        {
        case WM_CLOSE:
-               DestroyWindow (hDlg);
+               CustomDialogClose(hDlg, 1);
                return TRUE;
        case WM_INITDIALOG:
        {
@@ -19659,7 +19644,7 @@ static INT_PTR CALLBACK InputMapDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPA
                        case IDOK:
                        case IDC_INPUTMAP_EXIT:
                        pages[INPUTMAP_ID] =  NULL;
-                       DestroyWindow (hDlg);
+                       CustomDialogClose(hDlg, 1);
                        recursive--;
                        return TRUE;
                        case IDC_INPUTMAP_TEST:
@@ -19735,37 +19720,37 @@ static INT_PTR CALLBACK InputMapDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPA
 
 static void ports_remap (HWND hDlg, int port, int sub)
 {
-       struct newresource *res;
+       SAVECDS;
        inputmap_port = port;
        if (sub < 0) {
                sub = 0;
        }
        inputmap_port_sub = sub;
-       HWND dlg = CustomCreateDialog(&res, IDD_INPUTMAP, hDlg, InputMapDlgProc);
-       if (dlg == NULL)
-               return;
-       MSG msg;
-       for (;;) {
-               DWORD ret = GetMessage (&msg, NULL, 0, 0);
-               if (ret == -1 || ret == 0)
-                       break;
-               if (rawmode) {
-                       if (msg.message == WM_INPUT) {
-                               handlerawinput (msg.hwnd, msg.message, msg.wParam, msg.lParam);
-                               continue;
+       HWND dlg = CustomCreateDialog(IDD_INPUTMAP, hDlg, InputMapDlgProc, &cdstate);
+       if (dlg != NULL) {
+               MSG msg;
+               while(cdstate.active) {
+                       DWORD ret = GetMessage (&msg, NULL, 0, 0);
+                       if (ret == -1 || ret == 0)
+                               break;
+                       if (rawmode) {
+                               if (msg.message == WM_INPUT) {
+                                       handlerawinput (msg.hwnd, msg.message, msg.wParam, msg.lParam);
+                                       continue;
+                               }
+                               // eat all accelerators
+                               if (msg.message == WM_KEYDOWN || msg.message == WM_MOUSEMOVE || msg.message == WM_MOUSEWHEEL
+                                       || msg.message == WM_MOUSEHWHEEL || msg.message == WM_LBUTTONDOWN)
+                                       continue;
                        }
-                       // eat all accelerators
-                       if (msg.message == WM_KEYDOWN || msg.message == WM_MOUSEMOVE || msg.message == WM_MOUSEWHEEL
-                               || msg.message == WM_MOUSEHWHEEL || msg.message == WM_LBUTTONDOWN)
+                       // IsDialogMessage() eats WM_INPUT messages?!?!
+                       if (!rawmode && IsDialogMessage (dlg, &msg))
                                continue;
+                       TranslateMessage (&msg);
+                       DispatchMessage (&msg);
                }
-               // IsDialogMessage() eats WM_INPUT messages?!?!
-               if (!rawmode && IsDialogMessage (dlg, &msg))
-                       continue;
-               TranslateMessage (&msg);
-               DispatchMessage (&msg);
        }
-       freescaleresource(res);
+       RESTORECDS;
 }
 
 static void input_togglesetmode (void)
@@ -20009,7 +19994,6 @@ static void input_qualifiers (HWND hDlg)
        int evt;
        TCHAR name[256];
        TCHAR custom[MAX_DPATH];
-       struct newresource *res;
        
        if (input_selected_device < 0 || input_selected_widget < 0)
                return;
@@ -20018,8 +20002,7 @@ static void input_qualifiers (HWND hDlg)
        if (evt <= 0)
                name[0] = 0;
        
-       CustomCreateDialog(&res, IDD_LIST, hDlg, QualifierProc);
-       freescaleresource(res);
+       CustomCreateDialogBox(IDD_LIST, hDlg, QualifierProc);
 #if 0
        int item = genericpopupmenu (hDlg, names, mflags, MAX_INPUT_QUALIFIERS * 2);
        if (item >= 0)
@@ -21700,12 +21683,16 @@ static INT_PTR CALLBACK AVIOutputDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LP
                        break;
 #endif
                case IDC_SAMPLERIPPER_ACTIVATED:
-                       sampleripper_enabled = !sampleripper_enabled;
-                       audio_sampleripper (-1);
+                       if (ischecked(hDlg, IDC_AVIOUTPUT_ACTIVATED) != (sampleripper_enabled != 0)) {
+                               sampleripper_enabled = !sampleripper_enabled;
+                               audio_sampleripper (-1);
+                       }
                        break;
 
                case IDC_AVIOUTPUT_ACTIVATED:
-                       AVIOutput_Toggle (!avioutput_requested, false);
+                       if (ischecked(hDlg, IDC_AVIOUTPUT_ACTIVATED) != (avioutput_requested != 0)) {
+                               AVIOutput_Toggle (!avioutput_requested, false);
+                       }
                        break;
                case IDC_SCREENSHOT:
                        screenshot(-1, 1, 0);
@@ -23098,9 +23085,13 @@ struct newresource *getresource (int tmpl)
        if (!size)
                return NULL;
        nr = xcalloc (struct newresource, 1);
+       if (!nr)
+               return NULL;
        newres = (LPCDLGTEMPLATEW)xmalloc (uae_u8, size);
-       if (!newres)
+       if (!newres) {
+               xfree(nr);
                return NULL;
+       }
        memcpy ((void*)newres, resdata, size);
        nr->sourceresource = newres;
        nr->sourcesize = size;
@@ -23111,13 +23102,15 @@ struct newresource *getresource (int tmpl)
 
 void CustomDialogClose(HWND hDlg, int status)
 {
-       if (hGUIWnd) {
-               EnableWindow(hGUIWnd, TRUE);
+       if (cdstate.parent) {
+               EnableWindow(cdstate.parent, TRUE);
+               cdstate.parent = NULL;
        }
-       customdialogactive = status;
-       customdialoghwnd = NULL;
-       freescaleresource(customdialogres);
-       customdialogres = NULL;
+       cdstate.status = status;
+       cdstate.active = 0;
+       cdstate.hwnd = NULL;
+       freescaleresource(cdstate.res);
+       cdstate.res = NULL;
        DestroyWindow(hDlg);
 }
 
@@ -23140,41 +23133,68 @@ INT_PTR CustomDialogBox(int templ, HWND hDlg, DLGPROC proc)
        return h;
 }
 
-HWND CustomCreateDialog(struct newresource **resp, int templ, HWND hDlg, DLGPROC proc)
+static HWND getparent(HWND owner)
+{
+       for (;;) {
+               if (GetWindowLongW(owner, GWL_STYLE) & WS_POPUP) {
+                       return owner;
+               }
+               owner = GetParent(owner);
+               if (!owner || owner == GetDesktopWindow())
+                       break;
+       }
+       return NULL;
+}
+
+HWND CustomCreateDialog(int templ, HWND hDlg, DLGPROC proc, struct customdialogstate *cds)
 {
        struct newresource *res;
        struct dlgcontext dctx;
        HWND h = NULL;
 
-       *resp = NULL;
-       res = getresource (templ);
+       memset(cds, 0, sizeof(customdialogstate));
+       res = getresource(templ);
        if (!res)
                return h;
-       if (scaleresource (res, &dctx, hDlg, -1, 0, 0, -1)) {
+       HWND parent = getparent(hDlg);
+       if (scaleresource(res, &dctx, hDlg, -1, 0, 0, -1)) {
                res->parent = panelresource;
+               cds->parent = parent;
+               if (parent) {
+                       EnableWindow(parent, FALSE);
+               }
                h = x_CreateDialogIndirectParam(res->inst, res->resource, hDlg, proc, NULL, res);
+               if (!h) {
+                       if (parent) {
+                               EnableWindow(parent, TRUE);
+                       }
+                       freescaleresource(res);
+                       res = NULL;
+               }
+       }
+       if (h) {
+               cds->res = res;
+               cds->active = 1;
+               cds->hwnd = h;
        }
-       *resp = res;
        return h;
 }
 
 static int CustomCreateDialogBox(int templ, HWND hDlg, DLGPROC proc)
 {
-       struct newresource *res;
-       customdialogactive = 1;
-       if (hGUIWnd) {
-               EnableWindow(hGUIWnd, FALSE);
-       }
-       HWND hwnd = CustomCreateDialog(&res, templ, hDlg, proc);
+       struct customdialogstate prevstate;
+       memcpy(&prevstate, &cdstate, sizeof(customdialogstate));
+
+       memset(&cdstate, 0, sizeof(customdialogstate));
+       cdstate.active = 1;
+       HWND hwnd = CustomCreateDialog(templ, hDlg, proc, &cdstate);
        if (!hwnd) {
-               if (hGUIWnd) {
-                       EnableWindow(hGUIWnd, TRUE);
-               }
                return 0;
        }
-       customdialogres = res;
-       customdialoghwnd = hwnd;
-       while (customdialogactive == 1) {
+       if (!IsWindowVisible(hwnd)) {
+               ShowWindow(hwnd, SW_SHOW);
+       }
+       while (cdstate.active) {
                MSG msg;
                int ret;
                WaitMessage();
@@ -23191,16 +23211,11 @@ static int CustomCreateDialogBox(int templ, HWND hDlg, DLGPROC proc)
                        if (!IsWindow(hwnd)) {
                                break;
                        }
-                       if (customdialogactive == -1)
-                               break;
                }
        }
-       if (hGUIWnd) {
-               if (!IsWindowEnabled(hGUIWnd)) {
-                       EnableWindow(hGUIWnd, TRUE);
-               }
-       }
-       return customdialogactive;
+       int ret = cdstate.status;
+       memcpy(&cdstate, &prevstate, sizeof(customdialogstate));
+       return ret;
 }
 
 static int init_page (int tmpl, int icon, int title,
index b7ad6a4b89e4c57869cae5f06ab7a717b53c2828..256f988c16421ecaad40c0faa7f6a2e21557a04f 100644 (file)
@@ -121,6 +121,21 @@ extern int dialog_inhibit;
 extern int gui_control;
 extern int externaldialogactive;
 
+struct customdialogstate
+{
+       int active;
+       int status;
+       struct newresource *res;
+       HWND hwnd;
+       HWND parent;
+};
+extern struct customdialogstate cdstate;
+#define SAVECDS \
+       struct customdialogstate old_cds; \
+       memcpy(&old_cds, &cdstate, sizeof(cdstate));
+#define RESTORECDS \
+       memcpy(&cdstate, &old_cds, sizeof(cdstate));
+
 HWND x_CreateDialogIndirectParam(HINSTANCE hInstance, LPCDLGTEMPLATE lpTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM lParamInit, struct newresource*);
 void x_DestroyWindow(HWND, struct newresource*);
 void getguipos(int *xp, int *yp);
@@ -128,7 +143,7 @@ extern int scaleresource(struct newresource*, struct dlgcontext *dctx, HWND, int
 extern void rescaleresource(struct newresource*, bool);
 extern void freescaleresource (struct newresource*);
 extern void scaleresource_setsize (int w, int h, int fs);
-extern HWND CustomCreateDialog (struct newresource **, int templ, HWND hDlg, DLGPROC proc);
+extern HWND CustomCreateDialog(int templ, HWND hDlg, DLGPROC proc, struct customdialogstate *cds);
 extern void CustomDialogClose(HWND, int);
 extern INT_PTR CustomDialogBox (int templ, HWND hDlg, DLGPROC proc);
 extern struct newresource *getresource (int tmpl);
index f8d67158f5d0006d623bbd39c95a42ab0374eecd..034ccf711e65d48ced8de304e43847727263319a 100644 (file)
@@ -1202,9 +1202,9 @@ int scaleresource (struct newresource *res, struct dlgcontext *dctx, HWND parent
 
 void freescaleresource (struct newresource *ns)
 {
-       if (!ns->resource)
+       if (!ns)
                return;
-       xfree ((void*)ns->resource);
+       xfree((void*)ns->resource);
        ns->resource = NULL;
        ns->size = 0;
 }