Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6751443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:55:41+00:00 2026-05-26T12:55:41+00:00

I have a Windows app that houses a web browser (Internet explorer) embedded in

  • 0

I have a Windows app that houses a web browser (Internet explorer) embedded in it. The app can be closed from another process by means of IPC. It works just fine except the situation when the embedded web browser may be displaying a pop-up dialog window (say, during saving of contents). In that case my app crashes when it tries to close from an outside request via IPC. (Internally it simply posts the WM_CLOSE message to itself.)

In light of that I thought to come up with a way to enumerate all windows that belong to my process and close them first before closing my process itself. The question is, how do you enumerate all windows belonging to my process for the purpose of closing them?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:55:42+00:00Added an answer on May 26, 2026 at 12:55 pm

    OK, I guess I got it myself. Here’s if someone is interested:

    #define SIZEOF(f) (sizeof(f) / sizeof(f[0]))
    typedef struct _ENUM_POPUPS_INFO{
        DWORD dwProcID;
        HWND hThisWnd;
        int nNextHWNDIndex;
        HWND hFoundHWNDs[256];
    }ENUM_POPUPS_INFO;
    
    void CloseAllOpenPopups(HWND hWnd, int dwmsWait)
    {
        //'hWnd' = our main window handle (we won't close it)
        //'dwmsWait' = maximum wait time in milliseconds, or -1 to wait for as long as needed
        ENUM_POPUPS_INFO epi = {0};
        BOOL bR;
        int i, iIteration;
        HWND hWndRoot, hWndActivePopup;
    
        DWORD dwmsTickBegin = GetTickCount();
    
        for(iIteration = 0;; iIteration = 1)
        {
            //Get our process ID
            memset(&epi, 0, sizeof(epi));
            epi.hThisWnd = hWnd;
            epi.dwProcID = GetCurrentProcessId();
    
            bR = EnumWindows(EnumPopupWindowsProc, (LPARAM)&epi);
    
            //Did we get any
            if(epi.nNextHWNDIndex == 0)
                break;
    
            //Wait on a second and later iteration
            if(iIteration > 0)
            {
                if(dwmsWait != -1)
                {
                    DWORD dwmsTick = GetTickCount();
                    int nmsDiff = abs((long)(dwmsTick - dwmsTickBegin));
                    if(nmsDiff >= dwmsWait)
                    {
                            //Timed out
                    break;
                    }
    
                    //Wait
                    Sleep(min(100, dwmsWait - nmsDiff));
                }
                else
                {
                    //Wait
                    Sleep(100);
                }
            }
    
            //Go through all windows found
                for(i = 0; i < epi.nNextHWNDIndex; i++)
            {
                //Get root owner
                hWndRoot = GetAncestor(epi.hFoundHWNDs[i], GA_ROOTOWNER);
                if(!hWndRoot)
                    continue;
    
                //Get it's active popup
                hWndActivePopup = GetLastActivePopup(hWndRoot);
                if(!hWndActivePopup)
                    continue;
    
                //Close it
                PostMessage(hWndActivePopup, WM_CLOSE, 0, 0);
            }
        }
    }    
    
    
    BOOL CALLBACK EnumPopupWindowsProc(HWND hWnd, LPARAM lParam)
    {
        ENUM_POPUPS_INFO* pEPI = (ENUM_POPUPS_INFO*)lParam;
    
        //Get process ID of the window
        DWORD dwProcID = 0;
        GetWindowThreadProcessId(hWnd, &dwProcID);
    
        //We need this window only if it's our process
        if(dwProcID == pEPI->dwProcID &&
            pEPI->hThisWnd != hWnd &&
            ((GetWindowLongPtr(hWnd, GWL_STYLE) & (WS_VISIBLE | WS_POPUP | WS_CAPTION)) == (WS_VISIBLE | WS_POPUP | WS_CAPTION)))
        {
            if(pEPI->nNextHWNDIndex >= SIZEOF(pEPI->hFoundHWNDs))
            {
                //Stop, we're full
                return FALSE;
            }
    
            //Add it
            pEPI->hFoundHWNDs[pEPI->nNextHWNDIndex] = hWnd;
            pEPI->nNextHWNDIndex++;
        }
    
        return TRUE;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Windows app that contains a browser control that loads pages from
I have a Windows Form app (4.0) that calls a Web Service (WCF) but
I have a Windows C++ app that crashes on user computers from time to
i have a windows phone 7 app that communicates with a web service. i've
I have an AIR/Flex app that can have multiple windows (s:Window instances) open at
I have a windows console app (that accepts parameters) and runs a process. I
I have an In-house windows form app that I would like to use Spell
I have a windows app that runs correctly in my PC that is 96DPI
This is the situation. I have a windows form app that uses an access
I have a windows mobile app (mymobiler) that i am trying to install and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.