This a quote from client:
"B. When I left the program running all night long, when I came back in the
next morning and "woke" the computer up by moving the mouse, the program
would not respond. This was also on the Windows XP system which went into
screensaver mode and then into a sleep mode."
Info on program operation:
My program uses a thread to capture signals from the serial port, and when
data arrives passes it to the main thread to be processed. I am thinking
that if Windows goes to sleep (and doesn't have serial port wakeup enabled)
that the information is buffered and/or lost; possibly freezing up the
application.
--
Charles Savage
Software Engineer
HWI Manufacturing
WM_POWERBROADCAST. Test the wParam parameter for PBT_APMQUERYSUSPEND.
> Also, is there a way to trap it and keep Windows from entering a
> sleep state programaticaly?
Simply return BROADCAST_QUERY_DENY when handling the message.
Gambit
I'm still learning the basics of Messages and sending them, etc.
I wrote this...
in header...
class TfrmMain : public TForm
{
__published: // IDE-managed Components
private: // User declarations
void __fastcall ProcessMessage(TMsg &message, bool &handled);
public: // User declarations
__fastcall TfrmMain(TComponent* Owner);
};
in .cpp
void __fastcall TfrmMain::ProcessMessage(TMsg &message, bool &handled)
{
switch( message.message )
{
case WM_POWERBROADCAST:
switch( message.wParam )
{
case PBT_APMQUERYSUSPEND:
handled = true;
break;
default:
handled = false;
break;
}
break;
case WM_SYSCOMMAND:
switch( message.wParam )
{
case SC_SCREENSAVE:
handled = true;
break;
default:
handled = false;
break;
}
break;
default:
handled = false;
break;
}
}
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
: TForm(Owner)
{
Application->OnMessage = ProcessMessage;
}
Any help would be appreciated.
Gambit
"Chuck Savage" <csa...@hwimfg.com> wrote in message
news:3c64437b$1_1@dnews...
void __fastcall TfrmMain::WndProc(Messages::TMessage &Message)
{
// my code here
TForm::WndProc(Message);
}
Each example I see has WndProc as defined as returning void. And the
MessageMap's defined as returning void. For a refference I'm looking at
Borland C++ Builder 4 Unleashed, pgs 68 & 69. Plus the C++ Builder How-To
book pg 337.
(Reffering to my previous post) I've found the message definitions in
winuser.h, but is there a book that describes when to use what?
Gambit
"Chuck Savage" <csa...@hwimfg.com> wrote in message
news:3c644a3a_2@dnews...
> Each example I see has WndProc as defined as returning void. And the
> MessageMap's defined as returning void.
Correct. However, both WndProc() and MESSAGE_MAP handlers pass message
information in a TMessage-derived structure. Such structures have a Result
value that you can assign return values in.
In the case of the issue at hand, the code would look something like this:
// via WndProc()
void __fastcall TfrmMain::WndProc(TMessage &Message)
{
if(Message.Msg == WM_POWERBROADCAST)
{
if((Message.WParam == PBT_APMQUERYSUSPEND) &&
(!SomeConditionToAllowTheSuspend))
{
Message.Result = BROADCAST_QUERY_DENY;
return;
}
}
// pass the message to default processing
TForm::WndProc(Message);
}
// via MESSAGE_MAP
class TfrmMain : public TForm
{
private:
void __fastcall WMPowerBroadcast(TMessage &Message);
public:
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(WM_POWERBROADCAST, TMessage,
WMPowerBroadcast)
END_MESSAGE_MAP(TForm)
};
void __fastcall TfrmMain::WMPowerBroadcast(TMessage &Message)
{
if((Message.WParam == PBT_APMQUERYSUSPEND) &&
(!SomeConditionToAllowTheSuspend))
{
Message.Result = BROADCAST_QUERY_DENY;
return;
}
// pass the message to default processing
TForm::Dispatch(&Message);
}
Gambit
A dialog box pops up saying that the system cannot suspend becase a device
or program has prevented it. Close all applications and try again. Thing
is, this is a medical applicaiton that needs to be up and running at all
times. Anyway to disable that dialog box, because it takes control away
from the program. Clicking ok, would just reenable the timer that would
eventually re-popup the dialog box.
Gambit
"Chuck Savage" <csa...@hwimfg.com> wrote in message
news:3c682e77_2@dnews...
"Remy Lebeau" <gamb...@gte.net> wrote in message news:3c683f5d$1_1@dnews...
Perhaps the settings for the Power schemes are in the registry somewhere?
Not sure. But if they were, then you could try modifying the registry to
enable/disable it.
Gambit
"Chuck Savage" <csa...@hwimfg.com> wrote in message
news:3c684a06$1_1@dnews...