Solved

On occasion calling IsWindowVisible returns FALSE even when the window is still open

Posted on 2004-09-29
5
1,234 Views
Last Modified: 2013-11-20
I have an activeX control that was created using C++.  This control will allow the opening of an existing file, MS Word document for example.  If a user saves changes to the document then once they close that document (or close MS Word) the control will prompt the user on what action to carry out next.

The Problem is, that on occasion a user opens a file using the control but as soon as they save (but not closing the document) the IsWindowVisible returns FALSE implying that the window is no longer available.  So despite the fact that the window is still open the control prompts the user to carry out the next step which shouldn't occur until such times as the user actually closes the document.  

To confirm that this is the problem I put a wait of a few seconds just after the statement while(IsWindowVisible(hWnd)) and then recall IsWindowVisible(hWnd) which it then returns TRUE implying correctly that the window is still open.

Example of steps to reproduce (however not consistently) are once the document is opened by the control the user :
1.  Clicks "Normal View" icon within MS Word
2.  Clicks View (menu) -> Header and Footer (option)
3.  Presses the 'space' button followed (quickly) by pressing CTRL-S to save the document.

Why is IsWindowVisible() returning the wrong result?  Is this a bug with the API call or am I missing something?

The CODE used is:-


void LaunchFile(...) {
...
while (IsWindowVisible(hWnd))
      {
            PumpMessages();
            Sleep(1);
      }
//Continue since window is now closed...
...
}

void PumpMessages()
{
      MSG msg;

      while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
      {
            ::TranslateMessage(&msg);
            ::DispatchMessage(&msg);
      }
}



Thanks in advance,
Martin Golden.
0
Comment
Question by:csf6gom
[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 12

Expert Comment

by:migel
ID: 12187230
Hi! May be IsWindow API may help you?
0
 
LVL 6

Expert Comment

by:Amritpal Singh
ID: 12187231
u can have a look at the following link
http://support.microsoft.com/default.aspx?scid=kb;en-us;820252&Product=winxp

for more info plz look for microsoft article
KB820252
0
 

Author Comment

by:csf6gom
ID: 12198590
Hi,
Firstly, by increasing the sleep time from 1ms seemed to reduce the issue however I had to increase it to 500ms before the issue seem to stop occurring.  

As for the IsWindow API it seems to do the trick (at least for MS Word), however, I've been warned that since the IsWindow checks if the handle is still valid then if the window has been closed the handle may still be available due to waiting for garbage collection.  The result here would be that the window appears to be actually closed however it hasn't actually been destroyed yet resulting in a delay until garbage collection has taking place.  I guess this garbage collection issue is probably specific to a particular type of application being used.  I'm not sure what application may work in this manner but since the user may be using any type of application then I can't be sure that using the IsWindow is a safe option.  Can anybody confirm this?  Thanks so far!

Finally, amrit_82, since I'm using Win2000 I don't think this KB issue is of any help.  Thank anyhow!

Thanks in advance!
0
 
LVL 12

Accepted Solution

by:
migel earned 250 total points
ID: 12200354
Okay You can install WH_CBT hook and catch window close event :-)
0
 

Author Comment

by:csf6gom
ID: 12215394
Hi Migel,

As my experience is fairly low with C++ API programming I'd appreciate if you could provide an example on using the WH_CBT in conjunction with IsWindow API!

Thanks in advance,
Martin
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create frequencies of a variable from SAS dataset? 10 139
repeatEnd java challenge 42 85
fizzArray  challenge 1 109
ShiftLeft challenge 21 89
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.

726 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