HyLian
HyLian

Reputation: 5093

Create a background process with system tray icon

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 ;)

Upvotes: 3

Views: 4257

Answers (2)

anon
anon

Reputation:

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.

Upvotes: 0

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

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

Upvotes: 2

Related Questions