Solved

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

Posted on 2004-09-29
5
1,210 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
  • 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 22
How to know only "File created" with EventLog 3 29
no14 challenge 14 57
zeroMAx challenge 20 76
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video discusses moving either the default database or any database to a new volume.

760 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

26 Experts available now in Live!

Get 1:1 Help Now