Sizable "open archive" window (fix for #353)

This commit is contained in:
Alexey 'Cluster' Avdyukhin 2021-06-15 13:32:09 +03:00
parent 2837e929d0
commit a50fdb64aa
2 changed files with 70 additions and 1 deletions

View File

@ -18,6 +18,11 @@
//it would be nonreadable because we wouldnt actually decompress the contents
static FCEUARCHIVEFILEINFO *currFileSelectorContext;
static RECT oldWindowRect;
static RECT newWindowRect;
// Minimum window size
static const int MIN_WIDTH = 250;
static const int MIN_HEIGHT = 150;
DEFINE_GUID(CLSID_CFormat_07,0x23170F69,0x40C1,0x278A,0x10,0x00,0x00,0x01,0x10,0x07,0x00,0x00);
@ -261,6 +266,37 @@ public:
}
};
//used to move all child items in the dialog when you resize (except for the dock fill controls which are resized)
BOOL CALLBACK ArchiveEnumWindowsProc(HWND hwnd, LPARAM lParam)
{
RECT crect;
HWND parent = GetParent(hwnd);
GetWindowRect(hwnd, &crect); //Get rect of current child to be resized
ScreenToClient(parent, (LPPOINT)&crect); //Convert rect coordinates to client area coordinates
ScreenToClient(parent, ((LPPOINT)&crect) + 1);
int plusWidth = (newWindowRect.right - newWindowRect.left) - (oldWindowRect.right - oldWindowRect.left);
int plusHeight = (newWindowRect.bottom - newWindowRect.top) - (oldWindowRect.bottom - oldWindowRect.top);
switch (GetDlgCtrlID(hwnd))
{
case IDC_LIST1:
// horizontal and vertical stretch
SetWindowPos(hwnd, 0, crect.left, crect.top,
crect.right - crect.left + plusWidth, crect.bottom - crect.top + plusHeight,
SWP_NOZORDER);
break;
case IDOK:
case IDCANCEL:
// movement only
SetWindowPos(hwnd, 0, crect.left + plusWidth, crect.top + plusHeight,
crect.right - crect.left, crect.bottom - crect.top,
SWP_NOZORDER);
break;
}
return TRUE;
}
class LibRef
{
@ -275,6 +311,7 @@ public:
}
};
// Callback for resizing child controls
static INT_PTR CALLBACK ArchiveFileSelectorCallback(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
@ -287,6 +324,7 @@ static INT_PTR CALLBACK ArchiveFileSelectorCallback(HWND hwndDlg, UINT uMsg, WPA
std::string& name = (*currFileSelectorContext)[i].name;
SendMessage(hwndListbox, LB_ADDSTRING, 0, (LPARAM)name.c_str());
}
GetWindowRect(hwndDlg, &oldWindowRect);
}
break;
@ -309,6 +347,32 @@ static INT_PTR CALLBACK ArchiveFileSelectorCallback(HWND hwndDlg, UINT uMsg, WPA
return TRUE;
}
break;
case WM_SIZE:
{
GetWindowRect(hwndDlg, &newWindowRect); // Get new size
// Limit window size
bool fixSize = false;
if (newWindowRect.right - newWindowRect.left < MIN_WIDTH)
{
newWindowRect.right = newWindowRect.left + MIN_WIDTH;
fixSize = true;
}
if (newWindowRect.bottom - newWindowRect.top < MIN_HEIGHT)
{
newWindowRect.bottom = newWindowRect.top + MIN_HEIGHT;
fixSize = true;
}
if (fixSize)
{
SetWindowPos(hwndDlg, 0, newWindowRect.left, newWindowRect.top,
newWindowRect.right - newWindowRect.left, newWindowRect.bottom - newWindowRect.top, 0);
}
// Initiate callback for resizing child controls
EnumChildWindows(hwndDlg, ArchiveEnumWindowsProc, 0);
InvalidateRect(hwndDlg, 0, TRUE);
UpdateWindow(hwndDlg);
oldWindowRect = newWindowRect; // Store for future calculations
}
}
return FALSE;
}

View File

@ -1355,7 +1355,7 @@ BEGIN
END
ARCHIVECHOOSERDIALOG DIALOGEX 0, 0, 265, 159
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MAXIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Choose File From Archive"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
@ -2314,6 +2314,11 @@ BEGIN
0
END
ARCHIVECHOOSERDIALOG AFX_DIALOG_LAYOUT
BEGIN
0
END
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////