views:

660

answers:

3

I'm trying to make a Windows app that checks some things in the background, and inform the user via a systray icon.

The app is made with Not managed C++ and there is no option to switch to .net or Java.

If the user wants to stop the app, he will use the tray icon.

The app can't be a Service because of the systray side and because it must run without installing anything on the user computer ( it's a single .exe )

Using the typical Win32 program structure ( RegisterClass, WndProc and so on ) i dont know how can i place some code to run apart the window message loop. Maybe i have to use CreateProcess() or CreateThread()? Is It the correct way to handle the Multithreading environment?

If i have to use CreateProcess()/CreateThread(), how can i comunicate between the two threads?

Thanks ;)

A: 

I doubt you want to create new processes to do this, you want to create a thread in your application. The API to do this is CreateThread. But if you are using C++, you should really be investigating the use of frameworks and class libraries to do this, not writing what will effectively be C code from scratch.

All threads belonging to an application share the global variables of the application, which can thus be used for communication. You will need to protect such multi-threaded access with something like a critical section.

anon
Indeed i need to create one Thread, and i'm very tight linked to win32 api. I think that CreateThread() could do the job. But how can I comunicate between the two threads?
HyLian
+2  A: 

As for the system tray icon, you'll need Shell_NotifyIcon.

See http://msdn.microsoft.com/en-us/library/bb762159.aspx

RaphaelSP
Thanks, the the systray icon side was more clear than the threading issue :)
HyLian
A: 

Well, first I'd consider whether you really need to run your monitoring code on a separate thread. If you're just polling some values or system state periodically, then you could probably run everything on your main thread using a timer. Assuming that's not an option, create a separate worker thread using CreateThread as has already been suggested. Create an invisible message window on your main thread. When the worker needs to update the main thread, it should post a message to your window. The main thread will respond by updating the system tray icon as needed.

Peter Ruderman