Tech Support > Microsoft Windows > Development Resources > WndProc and windowless app
WndProc and windowless app
Posted by Ritchie on July 23rd, 2003


Hi All,
Bear in mind I've only ever written console apps in the past. My latest app
does not require a console or a window so basically I changed 'main' to
'WinMain' and altered a few projects settings - so far things are working fine.

How can my windowless app know when it is being asked to close (say a user is
killing it from task manager) in order that it may clean up after itself?

I understand that a WndProc is required to trap a CLOSE/DESTROY message, must I
implement a hidden window in order to register a WndProc?

--
Ritchie


Posted by Alex Blekhman on July 24th, 2003


"Ritchie" <qiournvdlirhjgiuhdiuh345@hotmail.com> wrote in message
news:bfn0d1$gflib$1@ID-156657.news.uni-berlin.de...
It's a well known issue with windowless apps. Actually, if you want to
be 100% kosher in this respect, then you should write full blown
service. However, very often it's just overkill, so practical people
do following:

1. Create invisible window with following parameters:
- parent is Desktop window;
- style: WS_OVERLAPPED
- extended style: WS_EX_TOOLWINDOW (to avoid icon in task bar)

Caption of this window will appear in Task Manager. This window exists
with single purpose: to let user stop the application when needed.
Select it in Task Manager and press "End Task" button. System will
post to it WM_CLOSE message.

2. In this window handle useful messages such as WM_CLOSE or
WM_QUERYENDSESSION. Stop application when these messages are received.



Posted by Alex Blekhman on July 24th, 2003


"Alex Blekhman" <tkfx.NOSPAM@yahoo.com> wrote in message
news:bfo14a$h49ta$1@ID-54051.news.uni-berlin.de...

Just second thoughts..

3. Create simplest possible invisible window and put icon in system
tray. Then control your application from there. I noticed that many
windowless applications put their icons in system tray, so user can
easily stop them or configure their options, etc..



Posted by Ritchie on July 24th, 2003


"Anaz" <anaz_k_k@yahoo.com> wrote in message news:cbd9c011.0307232211.773d7300@posting.google.c om...
This is the part I'm having difficulty with. I figured that I can't have a
WndProc since the WndProc addresss is given to the O/S when a window, which
my app does not have, also why would my app be sent a WM_DESTROY message if
it doesnt' have a window!

Next I figured I might be able to have a GetMessage loop in my WinMain
waiting for a WM_QUIT message, something like:-

WinMain(.....
{
// Load my hook

MSG msg;
while(GetMessage(&msg, NULL, 0, 0 ));

// Unload my hook
}

Unsuprisingly this doesn't work as the code lacks a mechanism to send
itself a WM_QUIT message. Am I missing something obvious here? How can
my windowless app know when it is being asked to terminate?

--
Ritchie





Posted by Ritchie on July 24th, 2003


"Alex Blekhman" <tkfx.NOSPAM@yahoo.com> wrote in message news:bfo1ss$gsb8c$1@ID-54051.news.uni-berlin.de...
Hi Alex, thanks for the pointers. I'll go with the hidden window for now
and consider writing a service later on (if I ever come across a *C* tutorial
that I can understand).

--
Ritchie



Posted by Lucian Wischik on July 24th, 2003


Ritchie wrote:
Create a window!

This operating system is called "Windows".
It uses them everywhere.
Not just for user-interface windows.
It also uses them for system-level tasks, like DDE and receiving
multimedia notifications and communicating between applications and
displaying an entry in the Task Manager.

So, create an invisible window. That way your app will appear in the
Task Manager. Also, because you have created a window, you will have a
WndProc. And you'll need to have a message-loop in your app, of
course.

--
Lucian

Posted by Tim Robinson on July 25th, 2003


"Alex Blekhman" <tkfx.NOSPAM@yahoo.com> wrote in message
news:bfo1ss$gsb8c$1@ID-54051.news.uni-berlin.de...
No! Don't use the system tray (officially known as the System Notification
Area) as a substitute for the taskbar. It is for status indicators only, not
miscellaneous items; hence the name. If your app shows the user something
via the icon, then put it there by all means, but don't just use it as a way
of exiting background apps. Write a service for that.

--
Tim Robinson (MVP, Windows SDK)
http://www.themobius.co.uk/



Posted by Alex Blekhman on July 27th, 2003


"Tim Robinson" <tim.at.gaat.freeserve.co.uk@invalid.com> wrote in
message news:bfqvqb$hsd9j$1@ID-103400.news.uni-berlin.de...
Yes, it was designed for status indications. However, System
Notification Area outgrew the original aim quite immediately. Hence
the well known and widely accepted name: System Tray. For example,
look at little yellow loud-speaker. It's used for adjusting sound
volume of system. It also, changes its icon, when "mute" option is
selected. The same about eventually every icon there - it has handy
menu to change program's configuration (including start/exit).

I think it's little bit orthodox to demand strictly notification from
icon in SNA.




Similar Posts