Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Message Handling in Console Applications?

9 views
Skip to first unread message

prunesqallor

unread,
Oct 11, 2008, 6:05:35 AM10/11/08
to
This is probably a dumb question, but is there a way for console
applications to get system messages?

I'm trying to write an application to detect when the system returns from
standby. I can do this easily with a VCL app with a hdden window, minimized,
but the whole lot compiles to 460KB with everything linked in (which is the
way we do it here). An equivalent console app is only 50KB, so I tried
putting together the following as a demo:

//---------------------------------------------------------------------------

#include <windows.h>
#pragma hdrstop
#include <winuser.h>

//---------------------------------------------------------------------------

#pragma argsused
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow)
{
MSG msg;
HWND hWnd = NULL;
UINT filterMin = 0;
UINT filterMax = 0;
bool getOut = false;
int messageValue;

while (!getOut) {
messageValue = GetMessage(&msg, hWnd, filterMin, filterMax);
if (messageValue == 0) { getOut = true; }
if (messageValue >0) {
if (msg.wParam == PBT_APMRESUMESUSPEND) {
int messBoxID = MessageBox(
NULL,
(LPCTSTR)"Back from suspend.",
(LPCTSTR)"Suspension",
MB_ICONWARNING | MB_CANCELTRYCONTINUE);
}
}
}


return 0;
}
//---------------------------------------------------------------------------

Unfortunately, it doesn't work. The documentation states that the
WM_POWERBROADCAST is sent to all applications, but does it actually mean all
Windowed applications? Or am I just doing something silly?

Thanks,

John B

Lafi

unread,
Oct 11, 2008, 6:56:39 AM10/11/08
to
prunesqallor wrote:
> This is probably a dumb question, but is there a way for console
> applications to get system messages?

You can ask on specialized Win32 api newsgroup :
news://194.177.96.26/comp.os.ms-windows.programmer.win32
where it has already been discussed...

prunesqallor

unread,
Oct 12, 2008, 6:21:34 AM10/12/08
to
Thanks, I'll have a look.

JB
"Lafi" <la...@lst.com> wrote in message
news:gcq0p6$l9g$1...@news.albasani.net...

0 new messages