🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
13 messages
13 total messages Started by MR Sun, 06 Aug 2006 06:20
Is checking a window's dwStyle-value ' WS_VISIBLE' not sufficent to find out, if a window is currently visible on the screen?
#3224
Author: MR
Date: Sun, 06 Aug 2006 06:20
28 lines
2002 bytes
To find out, if a certain window (hwnd) is overlapped by some other
windows, my application 'MyApp' uses the api-function
  GetNextWindow(hwnd, GW_HWNDPREV))
to get all windows which have higher z-order priority that hwnd and
compare their rect-values to find out, if they have some common
regions.

Also I check the window's dwStyle-property for having the bit
WS_VISIBLE set.

Now I have the strange case, that a window with the title 'Myapp' is
found (which is not(!) the 'Caption' of my main-window, but has
something to do with it. (In the Start-bar an entry with this
window-title also occurs and closing it, closes my application.) Even
if this window is not visible on the screen, it's WS_VISIBLE flag is
set.  

In my case, the result is, that my function did not work correctly,
because it seems that the hwnd-window is overlapped by the
'Myapp'-windowi, what is not the case, because this strange window is
not visible at all (and especially not at the rect-posiition  it seems
to).

So, is there perhaps another dwStyle-flag I can check?

Thanks, 

Michael
Re: Is checking a window's dwStyle-value ' WS_VISIBLE' not sufficent to find out, if a window is currently visible on the screen...
#3228
Author: Bob Gonder
Date: Sun, 06 Aug 2006 13:43
36 lines
2448 bytes
<MR> wrote:

>To find out, if a certain window (hwnd) is overlapped by some other
>windows, my application 'MyApp' uses the api-function

You didn't say why you want to know this. If you just need to keep
your stuff visible, you might try the WS_EX_TOPMOST style.

>Also I check the window's dwStyle-property for having the bit
>WS_VISIBLE set.

IsWindowVisible()

>Now I have the strange case, that a window with the title 'Myapp' is
>found (which is not(!) the 'Caption' of my main-window, but has
>something to do with it. (In the Start-bar an entry with this
>window-title also occurs and closing it, closes my application.) Even
>if this window is not visible on the screen, it's WS_VISIBLE flag is
>set.  

You might try using   IsIconic( hwnd)

>In my case, the result is, that my function did not work correctly,
>because it seems that the hwnd-window is overlapped by the
>'Myapp'-windowi, what is not the case, because this strange window is
>not visible at all (and especially not at the rect-posiition  it seems
>to).
>
>So, is there perhaps another dwStyle-flag I can check?

Are you using VCL?
You might want to start your window search with Application->Handle ?

Again, it might be helpful to explain what you are trying to
accomplish, because this sounds like you are trying too hard to do
something simple.
Re: Is checking a window's dwStyle-value ' WS_VISIBLE' not sufficent to find out, if a window is currently visible on the screen...
#3232
Author: MR
Date: Sun, 06 Aug 2006 14:37
54 lines
2779 bytes
Bob Gonder <notbg@notmindspring.invalid> schrieb:

>IsWindowVisible()
>You might try using   IsIconic( hwnd)

Again strange: This found 'Myapp'-window delivers 
  true for IsWindowVisible()
and 
  false for IsIconic(),
but
  it isn't visible at the GetWindowRect()-rectangle.

My application's main-window, which is really visible returns the same
results with the functions above.

I finally evaluated the dwStyle of the invisible/visible Myapp-window
and has a value of 
//                    More exactly: this window has the flags
$94CA0000 (<=>
'WS_POPUP|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CAPTION(=WS_BORDER|WS_DLGFRAME)|WS_SYSMENU|WS_GROUP'

I compated this with my app's main-window and there the 
  WS_POPUP-flag 
is not set in the dwStyle-property.

So my test for the rectangle of a window is really visible is now 
  (win_info.dwStyle&WS_VISIBLE)!<=0 && (win_info.dwStyle&WS_POPUP)==0)
where
  win_info 
is the result of GetWindowInfo(hwnd, &win_info) .

This seems to work, but I'm not really happy about it as long as I do
not understand why. So why do the functions above return values, that
signalize the window is visible at it's GetRect()-area?

Thanks,

Michael


P.S. 
 
>Again, it might be helpful to explain what you are trying to
>accomplish, because this sounds like you are trying too hard to do
>something simple.

It's about capturing a window in the background, without wanting to
set the window to be captured in the foreground, because this would
disturb working with other programs in the meantime.  So if the window
is overlapped there is some acustic signal, so the user can move his
window beside. 

So, if you know how to capture an overlapped window, I would really
prefer this solution ;-) 
Re: Is checking a window's dwStyle-value ' WS_VISIBLE' not sufficent to find out, if a window is currently visible on the screen...
#3235
Author: MR
Date: Mon, 07 Aug 2006 06:51
34 lines
2068 bytes
>This seems to work, but I'm not really happy about it as long as I do
>not understand why. So why do the functions above return values, that
>signalize the window is visible at it's GetRect()-area?

It was correct, that I was not happy about the ''solution' I used.
This test
  win_info.dwStyle&WS_VISIBLE)!<=0 && (win_info.dwStyle&WS_POPUP)==0
instead of 
  win_info.dwStyle&WS_VISIBLE)!<=0
excluded some other windows too from being checked and so some
overlappings weren't recognized.

My even worse, but functioning solution was to exclude this 'Myapp'
-window explicitely with
  char title[100];
  GetWindowText(hwnd, title, sizeof(title));
  if(strcmp(title, "Myapp")==0)
    goto overlap_check_passed;

~~~~~~~~~~~~~~~~~~

There are two main-issues I do not understand:

(1) Where does this Myapp-window comes from. It is none of the forms I
created with BDS2006 (VCL)?

(2) Why does the IsWindowVisible()-function delivers true, but  is not
visible at it's GetWindowRect()-posiitions; it just appears in the
task-bar.

Thanks,

Michael
 
Re: Is checking a window's dwStyle-value ' WS_VISIBLE' not sufficent to find out, if a window is currently visible on the screen...
#3238
Author: JD
Date: Mon, 07 Aug 2006 09:38
56 lines
2741 bytes
<MR> wrote:
>
>    goto overlap_check_passed;

You have got to kidding! A goto?

> Where does this Myapp-window comes from.

VCL applications all have a hidden TApplication window. In
addition, if you're running it from within the IDE, that can
also be an issue depending on how you're searching for windows
because there will be a copy of the main form in the IDE.
However, it's impossible to determine what the problem is with
the code that you posted. You need to post a more complete
sample.

> Why does the IsWindowVisible()-function delivers true,

Again, you didn't post enough code but since you're using the
VCL, why not check the form's Visible property instead? For
example:

    std::vector < HWND   > vZOrder;
    std::vector < TForm* > vForms;

    vZOrder.clear();
    vForms.clear();
    for( int x = 0; x < Screen->FormCount; ++x )
      {
          if( Screen->Forms[x]->Visible )
            {
                vForms.push_back( Screen->Forms[x] );
            }
      }

    HWND hWnd = ::GetTopWindow( Application->MainForm->Handle );
    while( hWnd )
      {
          vZOrder.push_back( hWnd );
          hWnd = ::GetNextWindow( hWnd, GW_HWNDNEXT );
      }

Now you have a vector of the visible forms and a vector of
the same form's (reference by there Handle [hWnd]) in the
correct Z-Order. All you need to do is match them up.

> it just appears in the task-bar.

That is an issue that I would expect to be seperate from the
other problem but the code that's causing it may be embedded
with the other code. Are you overriding the CreateParams
method or using the win32 API SetWindow or SetWindowLong or
related functions?

~ JD
Re: Is checking a window's dwStyle-value ' WS_VISIBLE' not sufficent to find out, if a window is currently visible on the screen...
#3239
Author: MR
Date: Mon, 07 Aug 2006 10:27
42 lines
2678 bytes
>> Where does this Myapp-window comes from.
>
>VCL applications all have a hidden TApplication window. In
>addition, if you're running it from within the IDE, that can
>also be an issue depending on how you're searching for windows
>because there will be a copy of the main form in the IDE.
>However, it's impossible to determine what the problem is with
>the code that you posted. You need to post a more complete
>sample.

Ok, here a little compressed sample-program:

void __fastcall TForm1::FormShow(TObject *Sender)
{
  for(HWND hwnd=GetTopWindow(NULL); hwnd!=NULL;
hwnd=GetNextWindow(hwnd, GW_HWNDNEXT)) {
    char title[100];
    GetWindowText(hwnd, title, sizeof(title));
    if(strcmp(title, "Myapp")==0) {
      bool is_visible=IsWindowVisible(hwnd);
      assert(!is_visible); // !!! assertion failure
    }
  }
}

My app is called MyApp and it just runs through all the windows and if
it gets to the application window 'Myapp' (with exactly this name) it
checks for this window to be visible or not. Strangely windows says it
is visible, even if it is hidden (as you said) . So the assertion
fails.

The main question is: How can I find out for any HWND-window value, if
this window is really visible (i.e. not hidden) or not. The example
shows that checking for IsWindowVisible() is obviously not sufficent.

If it would concern only the main-window of my current application the
hack (with the 'bad' goto) would be sufficent, but there might run
other applications with such a hidden window. 

Thanks,

Michael
Re: Is checking a window's dwStyle-value ' WS_VISIBLE' not sufficent to find out, if a window is currently visible on the screen...
#3246
Author: Remy Lebeau (TeamB)
Date: Mon, 07 Aug 2006 18:14
33 lines
2321 bytes
<MR> wrote in message news:b91bd2dnjukqfkdkpgtnths0nbltohne89@4ax.com...

> Now I have the strange case, that a window with the title 'Myapp'
> is found (which is not(!) the 'Caption' of my main-window, but has
> something to do with it. (In the Start-bar an entry with this window-title
> also occurs and closing it, closes my application.) Even if this window
> is not visible on the screen, it's WS_VISIBLE flag is set.

Sounds like you found the main TApplication window for your executable.
TForm is NOT the top-most main window of a VCL program.  TApplication is.
TApplication has a 0x0 pixel visible window.  That window controls the main
taskbar button for the program, amongst other things.

> In my case, the result is, that my function did not work correctly,

While searching for windows, you should be taking their class names into
account, so that you can skip past undesirable windows such as
TApplication's.

> because it seems that the hwnd-window is overlapped by the
> 'Myapp'-windowi, what is not the case

Actually, it could very well be the case.  The TApplication window is simply
too small to see with the human eye, but the computer still knows about it
and treats it like any other window.

> So, is there perhaps another dwStyle-flag I can check?

No.


Gambit
Re: Is checking a window's dwStyle-value ' WS_VISIBLE' not sufficent to find out, if a window is currently visible on the screen...
#3247
Author: Remy Lebeau (TeamB)
Date: Mon, 07 Aug 2006 18:18
31 lines
2047 bytes
<MR> wrote in message news:fqndd2p35upa7ajicoe59mnos65v8erlqu@4ax.com...

> My even worse, but functioning solution was to exclude this 'Myapp'
> -window explicitely with
>   char title[100];
>   GetWindowText(hwnd, title, sizeof(title));
>   if(strcmp(title, "Myapp")==0)
>     goto overlap_check_passed;

You should use GetClassName() instead, ie:

    char name[100];
    GetClassName(hwnd, name, sizeof(name));
    if( strcmp(name, "TApplication") ==0 )

This way, you can skip past the hidden window of other VCL programs that may
be overlapping your own.

> Where does this Myapp-window comes from. It is none of the forms
> I created with BDS2006 (VCL)?

See my other reply.

> Why does the IsWindowVisible()-function delivers true

Because the window really is visible, it is just too small for you to see
with your eye.


Gambit
Re: Is checking a window's dwStyle-value ' WS_VISIBLE' not sufficent to find out, if a window is currently visible on the screen...
#3248
Author: Remy Lebeau (TeamB)
Date: Mon, 07 Aug 2006 18:29
32 lines
2299 bytes
<MR> wrote in message news:5m4ed2tqvtmb1eh9nk6n4s4i4rfju6cjb7@4ax.com...

> My app is called MyApp and it just runs through all the windows and
> if it gets to the application window 'Myapp' (with exactly this name)

Then you are running up on the TApplication window for your project.

> it checks for this window to be visible or not. Strangely windows says
> it is visible, even if it is hidden (as you said) . So the assertion
fails.

Again, the TApplication window is actually visible.  That is why Windows
reports it has visible.  It is just really small, but still present
nentheless.

> How can I find out for any HWND-window value, if this window is
> really visible (i.e. not hidden) or not. The example shows that checking
for
> IsWindowVisible() is obviously not sufficent.

You already know the answer to that.

> If it would concern only the main-window of my current application
> the hack (with the 'bad' goto) would be sufficent, but there might run
> other applications with such a hidden window.

All the more reason to look at the window class names instead of the caption
titles when possible.


Gambit
Re: Is checking a window's dwStyle-value ' WS_VISIBLE' not sufficent to find out, if a window is currently visible on the screen...
#3250
Author: MR
Date: Mon, 07 Aug 2006 21:03
28 lines
1931 bytes
Thanks, Remy, for your answers.

>You should use GetClassName() instead, ie:
>
>    char name[100];
>    GetClassName(hwnd, name, sizeof(name));
>    if( strcmp(name, "TApplication") ==0 )
>
>This way, you can skip past the hidden window of other VCL programs that may
>be overlapping your own.

I tried this and - with the first tests - it seems to work fine...


>> Why does the IsWindowVisible()-function delivers true
>
>Because the window really is visible, it is just too small for you to see
>with your eye.

Oops, you are absolutely right!!!
That's the point!
I really should have seen that the extention of the window is 0, so it
would not disturb in any way and so I could just skip it... (and it's
quite irrelevant to check the dwStyle, etc.

Thanks a lot,

Michael
Re: Is checking a window's dwStyle-value ' WS_VISIBLE' not sufficent to find out, if a window is currently visible on the screen...
#3252
Author: MR
Date: Tue, 08 Aug 2006 04:46
10 lines
1400 bytes
B.t.w.

Is it possible to access to the application-window of the current
application in an easy way,  so I would like to change it's caption
(i.e. the title being shown in the tool-bar) e.g. from 'Myapp' to
'MyApp'.

Thanks, 

Michael
Re: Is checking a window's dwStyle-value ' WS_VISIBLE' not sufficent to find out, if a window is currently visible on the screen...
#3255
Author: Remy Lebeau (TeamB)
Date: Tue, 08 Aug 2006 17:54
14 lines
1717 bytes
<MR> wrote in message news:0i5gd2dc007adie9lhmscbarbaq8f69nms@4ax.com...

> Is it possible to access to the application-window of the current
> application in an easy way,  so I would like to change it's caption
> (i.e. the title being shown in the tool-bar) e.g. from 'Myapp' to
> 'MyApp'.

The TApplication Caption is set in the Project Options, which in turn sets
the TApplication::Title property in the WinMain() function at program
startup.


Gambit
Re: Is checking a window's dwStyle-value ' WS_VISIBLE' not sufficent to find out, if a window is currently visible on the screen...
#3266
Author: MR
Date: Fri, 11 Aug 2006 13:41
5 lines
1220 bytes
This works fine.

Thank you,

Michael
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads