Board index » cppbuilder » Send WM-msgs to an app

Send WM-msgs to an app


2005-08-04 02:53:53 PM
cppbuilder25
Hello,
I try to find a way to make sure that my main app never lost the focus, because it is driven by a wheel only which only generates KeyUp and down messages and The Enter msg.
Sometimes it may happen that a background app like pcAnywhere grabs the focus and the main app is then not longer accessible.
At the moment the main app is started and controlled by a second app,so I can control some start conditions and I can watch the main app if it is alive.
My suggestion is to use this second app to send some 'vitual mouse clicks?to the main app when some other app has stolen the focus. I already obtained the processID of the main app and create the handle using OpenProcess to use the handle in SendMessage. But my main app does not receive these messages.
Does anybody know the right way to send some WM_ messages to another app or does someone have another better idea to prevent my app from losing the focus. (The settings of TwaekUIXP do not solve the problem.)
Roland
 
 

Re:Send WM-msgs to an app

"Roland" < XXXX@XXXXX.COM >wrote in message
Quote
I try to find a way to make sure that my main app never lost the focus,
because it is driven by a wheel only which only generates KeyUp and down
messages and The Enter msg.Sometimes it may happen that a background
app like pcAnywhere grabs the focus and the main app is then not longer
accessible.

At the moment the main app is started and controlled by a second
app,so I can control some start conditions and I can watch the main app
if it is
alive.

My suggestion is to use this second app to send some 'vitual mouse clicks?
to the main app when some other app has stolen the focus. I already
obtained
the processID of the main app and create the handle using OpenProcess to
use
the handle in SendMessage. But my main app does not receive these
messages.

Does anybody know the right way to send some WM_ messages to another app
or does someone have another better idea to prevent my app from losing
the focus. (The settings of TwaekUIXP do not solve the problem.)
Maybe using TApplication::OnDeactivate would help. Like this:
// In the form's constructor.
Application->OnDeactivate = HandleDeactivate;
void __fastcall TForm1::HandleDeactivate( TObject *Sender )
{
PostMessage( Handle, WM_APP + 1001, 0, 0 );
}
void __fastcall TForm1::WndProc( TMessage &Message )
{
if( Message.Msg == WM_APP + 1001 )
{
Application->BringToFront();
}
}
HTH
Jonathan
 

Re:Send WM-msgs to an app

"Jonathan Benedicto" < XXXX@XXXXX.COM >wrote:
Quote
"Roland" < XXXX@XXXXX.COM >wrote in message
news:42f1bb81$ XXXX@XXXXX.COM ...
>I try to find a way to make sure that my main app never lost the focus,
>because it is driven by a wheel only which only generates KeyUp and down
>messages and The Enter msg.Sometimes it may happen that a background
>app like pcAnywhere grabs the focus and the main app is then not longer
>accessible.
>
>At the moment the main app is started and controlled by a second
>app,so I can control some start conditions and I can watch the main app
>if it is
>alive.
>
>My suggestion is to use this second app to send some 'vitual mouse clicks?
>to the main app when some other app has stolen the focus. I already
>obtained
>the processID of the main app and create the handle using OpenProcess to
>use
>the handle in SendMessage. But my main app does not receive these
>messages.
>
>Does anybody know the right way to send some WM_ messages to another app
>or does someone have another better idea to prevent my app from losing
>the focus. (The settings of TwaekUIXP do not solve the problem.)


// In the form's constructor.
Application->OnDeactivate = HandleDeactivate;

void __fastcall TForm1::HandleDeactivate( TObject *Sender )
{
PostMessage( Handle, WM_APP + 1001, 0, 0 );
}

void __fastcall TForm1::WndProc( TMessage &Message )
{
if( Message.Msg == WM_APP + 1001 )
{
Application->BringToFront();
}
}

HTH

Jonathan


Hello Jonathan,
I've done it in principe in this way. Before I tell my second app that the main app has lost the focus I transmitt the name of the last topmost window of the main app and the the 'Lost focus' message ... it runs.
 

{smallsort}