Hide another app's window

Posted on 2000-04-10
Last Modified: 2013-11-20
I have a database application running as a Win95 service. When it starts, the database engine also starts, which brings up the database engine window. Since my app runs as a service, I hide its main window. And I'd like to hide the database engine window too. But it's not successful. I tried finding db engine window first then hiding it by calling ShowWindow(SW_HIDE). But it doesn't work because the db engine window starts as minimized. Anyone have any idea?
Question by:shibai
  • 2
  • 2

Expert Comment

ID: 2702797

Follow the following steps.

1. Declare the global callback function as
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM     lparam);

2. Wherever U want to kill explorer call the following function
EnumWindows((WNDENUMPROC)EnumWindowsProc , 0);

3. Write the callback function as

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lparam)
//Declare storage for Window Title
char l_chTitle[300];
memset(l_chTitle, 0, 300);
::GetWindowText(hwnd, l_chTitle, 200);

CString l_strTitle = l_chTitle;

//Is it database engine!?
if(l_strTitle.Find("database - ") != -1) //see bellow
//Yes Then Close it.
PostMessage(hwnd, WM_SHOWWINDOW, FALSE, 0);

return 1;

Here I am comparing with the titke text 'database'. But what U have to do is, just note the title text of that window, then compare with that.

Thats it.

Hope it helps.


Author Comment

ID: 2704428
Your code doesn't work. It doesn't even work for windows that are not minimized. The way I tried, finding the window then calling ShowWindow(SW_HIDE), works for windows not minimized, but doesn't work for minimized windows.

Accepted Solution

VinExpert earned 200 total points
ID: 2705309

Yeap :(, I thought, it will work. Sorry, But PostMessage works perfectly for the WM_CLOSE, but not for the WM_SHOWWINDOW.

Instead of the PostMessage call, put the following code. It will work fine though it is minimised.

CWnd *wnd = new CWnd;
wnd->m_hWnd = hwnd;
delete wnd;
wnd = NULL;

Hope this helps.


Expert Comment

ID: 2707851
Can you restore the window for a brief moment and then hide it?

Author Comment

ID: 2707906
It does work. Thanks.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 94
Expand LInux Boot partition remotly 3 96
MaxSpan challenge 9 105
Excel file not created as expected 7 79
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question