Board index » cppbuilder » Interesting "Feature" anoyes me!!

Interesting "Feature" anoyes me!!

Hello!
I have noticed a weird thing and I guess its normal behavior but it
really plays
on my nerves....
I have two apps. A that configures B. In A I have a button that calls B.

In B uppon cloing I check with FindWindow if A is running. If it is I
kill
it and restart it. All that works fine outside the ide. But when bcb is
running and my project is opened FindWIndow returs a handle on the Form
in the ide(cause its name is the same).. So when B closes A it actually
close the Form in the ide
and starts another instance of A!!!!!!!
Did you follow me ?   ;-)
So my question is : is there any simple way of preventing this ?
Is it a bug ?

Thanx for all your answers !!!

MatzTheWolf.

 

Re:Interesting "Feature" anoyes me!!


Quote
: MatzTheWolf <matz_the_w...@videotron.ca> wrote:
>In B uppon cloing I check with FindWindow if A is running.
...
>Did you follow me ?   ;-)

Sure.

Quote
>So my question is : is there any simple way of preventing this ?

Sure. Don't use FindWindow but a global atom (GlobalAddAtom)

Quote
>Is it a bug ?

Yep. In "A" and "B". A design bug.

--
Stefan Hoffmeister (TeamB)     http://www.econos.de/
Please do apply judgement when sending email.

Re:Interesting "Feature" anoyes me!!


Quote
"Stefan Hoffmeister (TeamB)" wrote:
> : MatzTheWolf <matz_the_w...@videotron.ca> wrote:

> >In B uppon cloing I check with FindWindow if A is running.
> ...
> >Did you follow me ?   ;-)

> Sure.

> >So my question is : is there any simple way of preventing this ?

> Sure. Don't use FindWindow but a global atom (GlobalAddAtom)

> >Is it a bug ?

> Yep. In "A" and "B". A design bug.

    Why is it so ? What is the purpose of FindWindow if I cant use it ?
I know that FindWindow is not the most reliable way of finding a running
app on my
system but its very simple of use and works fine as long as I have
unique names
for all my forms(ie: MySuper Duper App Server V1.9.666 - Running)...
    And why would a app that calls another app be a design error ?
I'm writing a file server and need some configurations. The server is a
Nt service
with almost no gui. I use scripts (a la Unix) to configure my app and it
works
very well.
     I need the user to be able to call the configuration from the app
or from the
start menu. I need to apply those changes right away. So I need to
restart my app
automagically.
    If you find this to be a design error please suggest me a better
solution. I respect
your experience and wisdom very much Stefan and I'm looking forward to
your answer.

MatzTheWolf.

Re:Interesting "Feature" anoyes me!!


On Tue, 21 Sep 1999 15:41:07 -0400, MatzTheWolf

Quote
<matz_the_w...@videotron.ca> wrote:
>So my question is : is there any simple way of preventing this ?

How about add a suffix to  your  form caption when it is created ?
something like if the name is form1, in Form create

Caption = Caption + "_";

In your program just  add the same suffix and your FindWindow
will never return the form in design mode...

Gerard

Re:Interesting "Feature" anoyes me!!


Quote
: MatzTheWolf <matz_the_w...@videotron.ca> wrote:

[Design bug in the code]

Quote
>    Why is it so ? What is the purpose of FindWindow if I cant use it ?

You can use it. That's why I didn't say implementation bug, but design
bug.

Quote
>I know that FindWindow is not the most reliable way of finding a running
>app on my system but its very simple of use

Well, you should check GlobalAddAtom then. Much more reliable. Perhaps
even easier to use. No design bug.

Quote
>    And why would a app that calls another app be a design error ?

Your use of FindWindow for that particular task is a design bug.

Quote
>    If you find this to be a design error please suggest me a better
>solution.

I did. Global atoms.

--
Stefan Hoffmeister (TeamB)     http://www.econos.de/
Please do apply judgement when sending email.

Re:Interesting "Feature" anoyes me!!


Quote
"Stefan Hoffmeister (TeamB)" wrote:
> : MatzTheWolf <matz_the_w...@videotron.ca> wrote:

> [Design bug in the code]

> >    Why is it so ? What is the purpose of FindWindow if I cant use it ?

> You can use it. That's why I didn't say implementation bug, but design
> bug.

Ok.... My fault..

Quote

> >I know that FindWindow is not the most reliable way of finding a running
> >app on my system but its very simple of use

> Well, you should check GlobalAddAtom then. Much more reliable. Perhaps
> even easier to use. No design bug.

I'll check it out....

Quote

> >    And why would a app that calls another app be a design error ?

> Your use of FindWindow for that particular task is a design bug.

Ok then... Your the pro.

Quote

> >    If you find this to be a design error please suggest me a better
> >solution.

> I did. Global atoms.

Your getting sarcastic now Stefan!   ;-)

Thanx for the help!
MatzTheWolf from rainy Montreal.

Re:Interesting "Feature" anoyes me!!


I actually already do this....
I was just wondering why all of this was possible. Because its an
annoyance that's visible only when I'm working on the project. Not in
normal day use.
Thanx for the suggestion!

MatzTheWolf.

Re:Interesting "Feature" anoyes me!!


On Wed, 22 Sep 1999 13:36:38 -0400, MatzTheWolf

Quote
<matz_the_w...@videotron.ca> wrote:
>I actually already do this....
>I was just wondering why all of this was possible.

Because  the form you see in the IDE is not a special object
separate from the real form; it is the same object, only in
a different mode.

Gerard

Re:Interesting "Feature" anoyes me!!


Hello Stefan!
I did check GlobalAddAtom() and its very simple to use. But!
How do I make it do the same as I did with FindWindow ?
How can I get a HANDLE ? It can check for the existence of my other app
but how do I kill it ? I still have to do FIndWIndow no ?

Thanx for your help!

Re:Interesting "Feature" anoyes me!!


Quote
: MatzTheWolf <matz_the_w...@videotron.ca> wrote:
>I did check GlobalAddAtom() and its very simple to use. But!
>How do I make it do the same as I did with FindWindow ?

Try using "GlobalFindAtom"

Quote
>It can check for the existence of my other app
>but how do I kill it ?

You never said that you wanted to actually KILL the OTHER app. In order to
use the GlobalAddAtom technique, the current application checks whether it
has any business of staying around. If it does not, too bad - good-bye.

If you want to kill another application, you ought to be using process
enumeration via the TlHlp32 libraries (CreateToolHelp32Snapshot and
friends) on Win9x and the PsApi library on Windows NT. There you enumerate
processes and kill the process.

Followup-to is set to .winapi, as this no longer has anything to do with
the .ide

--
Stefan Hoffmeister (TeamB)     http://www.econos.de/
Please do apply judgement when sending email.

Re:Interesting "Feature" anoyes me!!


The easier way to do this is to use registered messages. Look at
RegisterWindowMessage.

Both A and B register a message using the same character string. They
both get the same message number. When B terminates it does a
PoseMessage (HWND_BROADCAST, registered message number,...
This message is given to all top level windows in the system. In A,
catch the message and do what you will with it.

The other way, a little more complicated but also good, is to use
a global semaphore. A creates the semaphore and wait on it. When
is's done, B posts the semaphore.

    ++PLS

Quote
MatzTheWolf wrote:

> I actually already do this....
> I was just wondering why all of this was possible. Because its an
> annoyance that's visible only when I'm working on the project. Not in
> normal day use.
> Thanx for the suggestion!

> MatzTheWolf.

Re:Interesting "Feature" anoyes me!!


You can use EnumWindows() function to find a window with has a property
set ( SetProp()/GetProp() APIs )

HTH,
Alex

Quote
MatzTheWolf wrote:

[snip]

Other Threads