Board index » cppbuilder » Trapping Messages Sent to a Service App

Trapping Messages Sent to a Service App


2005-02-22 09:31:36 AM
cppbuilder44
Hi,
This should be very simple, but I am not able to make it
work. Thus, some help would be very appreciated.
I am simply trying to trap messages in a service app. Thus if
WM_QUERYENDSESSION or WM_ENDSESSION is sent, I would like
to know so as to stop the user.
The code implementation I am trying is as follows:
In the ServiceStart function I am doing :
if( !FHandle )
{
FHandle = AllocateHWnd(MyWndProc);
}
In the ServiceStop function I am doing:
if( Fhandle )
DeallocateHWnd(FHandle);
FHandle = NULL;
Finally MyWndProc is defined and implemented as:
void __fastcall TLogOffSrv::MyWndProc(Messages::TMessage &Message) {
if( Message.Msg == WM_QUERYENDSESSION || Message.Msg == WM_ENDSESSION )
{
if( !FLogOffAllowed)
{
AnsiOutputDebug("Not Allowed " + IntToHex((int)Message.Msg, 2) );
Message.Result = 1;
}
}
else
{
AnsiOutputDebug("Other Message " + IntToHex((int)Message.Msg, 2) );
Message.Result = 0;
}
}
Thank you
danieL.
 
 

Re:Trapping Messages Sent to a Service App

"Daniel" < XXXX@XXXXX.COM >wrote in message
Quote
Finally MyWndProc is defined and implemented as:
You are catching the messages in the wrong place. The messages are not sent
to the window you created. They are sent it the hidden TApplication window
instead. Use TApplication::HookMainWindow() to catch the messages.
Gambit
 

Re:Trapping Messages Sent to a Service App

Gambit
Could you elaborate some more please. As I have tried your solution, bit I
am not able to get it to work.
Thank you
danieL.
Quote
"Daniel" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>Finally MyWndProc is defined and implemented as:

You are catching the messages in the wrong place. The messages are not
sent
to the window you created. They are sent it the hidden TApplication
window
instead. Use TApplication::HookMainWindow() to catch the messages.


Gambit
 

{smallsort}

Re:Trapping Messages Sent to a Service App

"Daniel" < XXXX@XXXXX.COM >wrote in message
Quote
Could you elaborate some more please. As I have tried your solution,
bit I am not able to get it to work.
Just saying it does not work says nothing at all about the actual problem
you are having. Please show your actual code, and provide specific details
about what EXACTLY you are trying to accomplish, what you expect the code to
do, what it is actually doing instead, and any errors that are occuring.
Gambit