Retrieving handle of the app main window that was active before my app


I would like to retrieve the title of the application that was active at the time when my inactive application gets focus.  All I need is the window handle of the previously active app. Once I have it I can retrieve the title.

Scenario: my application is running but inactive. I have other applications started but the currently active is Netscape Messenger. When my inactive app gets the focus or gets reactivated I would like to display the title: Netscape Messanger or whatever happens to be in the Messenger's main window title bar.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I assume you are talking about Windows programming.

Capture the WM_ACTIVATE message sent to your main window.

fActive = LOWORD(wParam);           // activation flag
fMinimized = (BOOL) HIWORD(wParam); // minimized flag
hwndPrevious = (HWND) lParam;       // window handle

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lendvayAuthor Commented:
Hi Chensu,

Sorry for being late responding to your suggestion. You were very quick answering my problem but I were away for a couple of days from my work.

Actually, I was very silly asking a C++ question because I was writing a VB program. But I was able to use your logic anyway and that's what counts.

Thanks again,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.