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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 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