0

I am creating a no UI no console program in C++ to run in the background. Everything's working fine. But I want to have an icon of the program in the taskbar hidden icons.

Also is there a way I could add options to the icon in taskbar (like settings, exit, etc)

Details: Compiler: MinGW 64 OS: WIndows 10

drescherjm
  • 10,365
  • 5
  • 44
  • 64
Aniruddh Anna
  • 43
  • 1
  • 8
  • 3
    Any help: https://stackoverflow.com/questions/54332515/c-system-tray-only-program ? – user4581301 Nov 04 '20 at 13:25
  • Maybe post parts of your program, to make it clear which technology you are using? You can [edit] your question to post relevant info. – anatolyg Nov 04 '20 at 13:26

2 Answers2

0

In case you use Qt, this would do the job:

MyClass::MyClass(QWidget *parent)
: QDialog(parent)
{
  hide();   // Gui is hidden
  createTrayMenu();
}


void MyClass::createTrayMenu()
{
  QAction* settingsAction = new QAction(tr("&Settings"), this);
  connect(settingsAction, SIGNAL(triggered()), this, SLOT(showSettings()));

  QAction* quitAction = new QAction(tr("&Exit"), this);
  connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));

  QMenu * trayIconMenu = new QMenu(this);         // Qt parent takes care of freeing
  trayIconMenu->addAction(settingsAction);
  trayIconMenu->addSeparator();
  trayIconMenu->addAction(quitAction);

  // Create Icon and add to Tray
  QSystemTrayIcon* trayIcon = new QSystemTrayIcon(this);
  trayIcon->setIcon( setIcon(QIcon(QPixmap("Icon.png"))) );
  trayIcon->setContextMenu(trayIconMenu);
}

hide() removes the GUI. trayIcon should be best a class-member, so you can change the Icon easily to reflect the state of your Program.

SteveXP
  • 26
  • 4
0

Having a tray icon actually makes your application a GUI application, even if it also still has a console. You can use GUI frameworks for this like Qt or wxWidgets, but you could also give this project a go which does only the tray icon without a complete GUI framework: https://github.com/zserge/tray

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40