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 7683223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:44:48+00:00 2026-05-31T18:44:48+00:00

I am a beginner in C++ (always been a C#) and I was put

  • 0

I am a beginner in C++ (always been a C#) and I was put in to troublshooting/update on of our legacy program written in C++.

I have a process name “setup.exe” that runs on window and I knew how to find its HANDLE and DWORD process id. I know it has a window for sure but I can’t seem to find out how to bring this window to a foreground and that is what I am trying to do: To bring a window to a foreground using its process name.

Upon reading on the internet I came to the following algorithm which i’m also not sure is the proper way to do it:

  1. Find the process ID from the process name.
  2. Enumerate all the windows which belong to this process ID using EnumWindows
  3. the above step will give me the window handle(s) variable of type – HWND
  4. I can set focus or set the foreground by passing in this HWND variable.

My problem here is syntax wise, I don’t really know how to begin to write up enumwindows, can anybody point me toward a set of sample code or if you have any pointer to how I should approach this issue?

Thank you.

  • 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-31T18:44:49+00:00Added an answer on May 31, 2026 at 6:44 pm

    The EnumWindows procedure evaluates all top level windows. If you are sure the window you are looking for is top level, you can use this code:

    #include <windows.h>
    
    // This gets called by winapi for every window on the desktop
    BOOL CALLBACK EnumWindowsProc(HWND windowHandle, LPARAM lParam)  {
        DWORD searchedProcessId = (DWORD)lParam;  // This is the process ID we search for (passed from BringToForeground as lParam)
        DWORD windowProcessId = 0;
        GetWindowThreadProcessId(windowHandle, &windowProcessId); // Get process ID of the window we just found
        if (searchedProcessId == windowProcessId)  {  // Is it the process we care about?
          SetForegroundWindow(windowHandle);  // Set the found window to foreground
          return FALSE;  // Stop enumerating windows
        }
        return TRUE;  // Continue enumerating
    }
    
    void BringToForeground(DWORD processId)  {
       EnumWindows(&EnumWindowsProc, (LPARAM)processId);
    }
    

    Then just call BringToForeground with the process ID you want.

    DISCLAIMER: not tested but should work 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've always been curious about audio conversion software, but I have never seen a
I am a beginner C++ learner and I always have a problem on if
As a beginner in programming it always bugs me when I run into a
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
Absolute beginner question: I have a template file index.html that looks like this: ...
Up until now, we've all been hosting our mercurial repositories and pulling directly from
Beginner here, I have a simple question. In Android what would be the best
i'm a beginner in mef and so i have a question :) i have
I have a beginner level Json question with MVC.net (I've never really used jquery
I'm a JS beginner. My question is do we always need to use a

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.