Create a background process with system tray icon

非 Y 不嫁゛ 提交于 2019-12-30 10:38:33

问题


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


回答1:


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

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




回答2:


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.



来源:https://stackoverflow.com/questions/1188133/create-a-background-process-with-system-tray-icon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!