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?
chensuConnect With a Mentor Commented:
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
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,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.