Solved

Hide another app's window

Posted on 2000-04-10
5
248 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

11 Experts available now in Live!

Get 1:1 Help Now