Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1296
  • Last Modified:

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

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
csf6gom
Asked:
csf6gom
  • 2
  • 2
1 Solution
 
migelCommented:
Hi! May be IsWindow API may help you?
0
 
Amritpal SinghCommented:
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
 
csf6gomAuthor Commented:
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
 
migelCommented:
Okay You can install WH_CBT hook and catch window close event :-)
0
 
csf6gomAuthor Commented:
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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now