Solved

Hide another app's window

Posted on 2000-04-10
5
250 Views
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?
0
Comment
Question by:shibai
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 2702797
Hi,

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.

VinExpert
0
 

Author Comment

by:shibai
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.
0
 
LVL 8

Accepted Solution

by:
VinExpert earned 200 total points
ID: 2705309
Hi,

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->FromHandle(hwnd);
wnd->m_hWnd = hwnd;
wnd->ShowWindow(SW_HIDE);
if(wnd)
{
delete wnd;
wnd = NULL;
}

Hope this helps.

VinExpert
0
 
LVL 3

Expert Comment

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

Author Comment

by:shibai
ID: 2707906
It does work. Thanks.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
method notes when mouse over in eclipse 5 86
zeroFront challenge 7 95
wordappend challenge 8 172
Sed question 2 83
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now