Skip to content

Commit

Permalink
Do not open multiple Settings Windows
Browse files Browse the repository at this point in the history
- Do not allow more than one settings menu to be opened

Signed-off-by: Selva Nair <selva.nair@gmail.com>
  • Loading branch information
selvanair committed Jan 20, 2023
1 parent 71c0a25 commit 939cbfd
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ options_t o;
/* Workaround for ASLR on Windows */
__declspec(dllexport) char aslr_workaround;

/* globals */
static HWND settings_window; /* Handle of Settings window */

static int
VerifyAutoConnections()
{
Expand Down Expand Up @@ -758,12 +761,31 @@ AboutDialogFunc(UNUSED HWND hDlg, UINT msg, UNUSED WPARAM wParam, LPARAM lParam)
return FALSE;
}

static int CALLBACK
SettingsPsCallback(HWND hwnd, UINT msg, UNUSED LPARAM lParam)
{
switch(msg)
{
case PSCB_INITIALIZED:
settings_window = hwnd;
break;
}

return 0;
}

static void
ShowSettingsDialog()
{
PROPSHEETPAGE psp[4];
int page_number = 0;
PROPSHEETPAGE psp[4];
int page_number = 0;

if (settings_window && IsWindow(settings_window))
{
SetForegroundWindow(settings_window);
ShowWindow(settings_window, SW_SHOW);
return;
}

/* General tab */
psp[page_number].dwSize = sizeof(PROPSHEETPAGE);
Expand Down Expand Up @@ -807,15 +829,15 @@ ShowSettingsDialog()

PROPSHEETHEADER psh;
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.dwFlags = PSH_USEHICON | PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW | PSH_NOCONTEXTHELP;
psh.dwFlags = PSH_USEHICON | PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW | PSH_NOCONTEXTHELP | PSH_USECALLBACK;
psh.hwndParent = o.hWnd;
psh.hInstance = o.hInstance;
psh.hIcon = LoadLocalizedIcon(ID_ICO_APP);
psh.pszCaption = LoadLocalizedString(IDS_SETTINGS_CAPTION);
psh.nPages = page_number;
psh.nStartPage = 0;
psh.ppsp = (LPCPROPSHEETPAGE) &psp;
psh.pfnCallback = NULL;
psh.pfnCallback = SettingsPsCallback;

PropertySheet(&psh);
}
Expand Down

0 comments on commit 939cbfd

Please sign in to comment.