Google 網路論壇不再支援新的 Usenet 貼文或訂閱項目,但過往內容仍可供查看。

Window's Sleep mode

瀏覽次數:9 次
跳到第一則未讀訊息

Chuck Savage

未讀,
2002年2月7日 下午6:19:472002/2/7
收件者:
What message is sent when Windows enters sleep mode? Also, is there a way
to trap it and keep Windows from entering a sleep state programaticaly?

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


Remy Lebeau

未讀,
2002年2月7日 晚上8:01:162002/2/7
收件者:

"Chuck Savage" <csa...@hwimfg.com> wrote in message
news:3c630b69$1_2@dnews...

> What message is sent when Windows enters sleep mode?

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


Chuck Savage

未讀,
2002年2月8日 下午4:31:172002/2/8
收件者:
Cool thanks! Just how do I return the...

> Simply return BROADCAST_QUERY_DENY when handling the message.

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.


Remy Lebeau

未讀,
2002年2月8日 下午4:50:412002/2/8
收件者:
You can't use OnMessage for it, because OnMessage does not provide any way
to return your own values in response to messages. You need to intercept
the message on the form level instead, either 1) overriding WndProc() or 2)
using a MESSAGE_MAP


Gambit

"Chuck Savage" <csa...@hwimfg.com> wrote in message

news:3c64437b$1_1@dnews...

Chuck Savage

未讀,
2002年2月8日 下午5:00:042002/2/8
收件者:
Question on the different Messages that are sent. Is there a SDK out there
with all the different names? IE how would I look up as you gave me,
WM_POWERBROADCAST and the different wParam's that it has, such as the one
you gave me (PBT_APMQUERYSUSPEND).


Chuck Savage

未讀,
2002年2月8日 下午6:01:472002/2/8
收件者:
Thanks for your help so far Remy, can you give a more definite example? The
books I'm reading show WndProc to be setup something like...

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?


Bob Gonder

未讀,
2002年2月8日 晚上7:57:092002/2/8
收件者:
"Chuck Savage" <csa...@hwimfg.com> wrote:

Open up Win32.hlp
Click on Index.
Type WM
There you are.


Remy Lebeau

未讀,
2002年2月8日 晚上8:46:392002/2/8
收件者:
Builder comes with the Win32 API reference. When you install Builder, do a
Custom install, then you'll see the option to install the reference. Or you
can grab the files off of your Builder CD directly. Or you can do a search
at http://msdn.microsoft.com/search


Gambit

"Chuck Savage" <csa...@hwimfg.com> wrote in message

news:3c644a3a_2@dnews...

Remy Lebeau

未讀,
2002年2月8日 晚上8:53:572002/2/8
收件者:

"Chuck Savage" <csa...@hwimfg.com> wrote in message
news:3c6458b2_1@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


Chuck Savage

未讀,
2002年2月11日 下午3:50:422002/2/11
收件者:
Ok, that worked. But another problem appears as a result.

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.


Remy Lebeau

未讀,
2002年2月11日 下午5:03:342002/2/11
收件者:
If you right-click on the Desktop and go to Properties (or open the Control
Panel and go to Display), the go to the Screen Saver tab and click on the
"Settings" button in the EnergyStar section, are you running under the
"Always On" power scheme? Try playing around with those settings a little,
maybe you won't even need to deal with catching WM_POWERBROADCAST at all
then.


Gambit

"Chuck Savage" <csa...@hwimfg.com> wrote in message

news:3c682e77_2@dnews...

Chuck Savage

未讀,
2002年2月11日 下午5:48:172002/2/11
收件者:
I understand this, and it will definitly be a part of the install
instructions. I wanted to try and keep it transparent to the enduser.

"Remy Lebeau" <gamb...@gte.net> wrote in message news:3c683f5d$1_1@dnews...

Remy Lebeau

未讀,
2002年2月11日 下午6:17:572002/2/11
收件者:
I don't know why that dialog box is displayed or where it's controlled from.
I've never actually done anything with the power management stuff before, I
know just enough to get the notifications for it, not what happens
afterwards.

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...

0 則新訊息