From 9c6fe40c1c2e379d8640b7276ae80b55c336ad64 Mon Sep 17 00:00:00 2001 From: Brady McDermott Date: Mon, 21 Oct 2024 16:06:39 -0600 Subject: [PATCH] Solve issue #11 --- progmgr/progmgr.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/progmgr/progmgr.c b/progmgr/progmgr.c index 3ba8d95..86f8441 100644 --- a/progmgr/progmgr.c +++ b/progmgr/progmgr.c @@ -69,12 +69,13 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, HANDLE hAccel; HMENU hMenu; HMENU hSystemMenu; + HWND hOldProgMgr; WNDCLASS wc = { 0 }; WCHAR szBuffer[MAX_PATH]; RECT rcRoot; POINT ptOffset = { 0 }; - // Initialize the instance + // Grab the instance g_hAppInstance = hInstance; // Create Strings @@ -82,6 +83,16 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, LoadString(g_hAppInstance, IDS_APPTITLE, g_szAppTitle, ARRAYSIZE(g_szAppTitle)); LoadString(g_hAppInstance, IDS_WEBSITE, g_szWebsite, ARRAYSIZE(g_szWebsite)); + // Lazily search for another instance of Program Manager + // If we find one, switch focus to it and then abort. + hOldProgMgr = FindWindowEx(NULL, NULL, g_szClass, NULL); + + if (hOldProgMgr != NULL) + { + SwitchToThisWindow(hOldProgMgr, FALSE); + return FALSE; + } + // Get Desktop background color //CreateSolidBrush(GetBackgroundColor