Solved

Hide another app's window

Posted on 2000-04-10
5
257 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
[X]
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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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
iSeries DB2 Query 2 101
sumNumber challenge 16 145
sumHeights2  challenge 7 139
"Black Box" Testing of Control System Software 2 125
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…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

732 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