If you are adding after the start bar just as mentioned above, create a desktop icon and then pin to taskbar.
I wrote a sample based on your needs. It is to create a tray icon on the right side of the taskbar, with two options, and double-click the icon to exit.
Check that if it meets your needs.
#include<windows.h>
#include<cstdio>
#include<stdlib.h>
#include <windows.h>
#define IDR_PAUSE 12
#define IDR_START 13
#include <shellapi.h>
#pragma comment(lib, "shell32.lib")
LPCTSTR szAppName = TEXT("project");
LPCTSTR szWndName = TEXT("project");
HMENU hmenu;
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
NOTIFYICONDATA nid;
UINT WM_TASKBARCREATED;
POINT pt;//recive the cordinate of mouse
int xx;//recive the value
// do not modified TaskbarCreated
WM_TASKBARCREATED = RegisterWindowMessage(TEXT("TaskbarCreated"));
switch (message)
{
case WM_CREATE:
nid.cbSize = sizeof(nid);
nid.hWnd = hwnd;
nid.uID = 0;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.uCallbackMessage = WM_USER;
nid.hIcon = LoadIcon(NULL, IDI_APPLICATION);
lstrcpy(nid.szTip, szAppName);
Shell_NotifyIcon(NIM_ADD, &nid);
hmenu = CreatePopupMenu();
AppendMenu(hmenu, MF_STRING, IDR_PAUSE, "stop");//two option
AppendMenu(hmenu, MF_STRING, IDR_START, "go on");
break;
case WM_USER:
if (lParam == WM_LBUTTONDOWN)
MessageBox(hwnd, TEXT("Win32 API doubleclick exit!"), szAppName, MB_OK);
if (lParam == WM_LBUTTONDBLCLK)//doubleclick exit.
SendMessage(hwnd, WM_CLOSE, wParam, lParam);
if (lParam == WM_RBUTTONDOWN)
{
GetCursorPos(&pt);
::SetForegroundWindow(hwnd);
EnableMenuItem(hmenu, IDR_PAUSE, MF_GRAYED);//grey section 1
xx = TrackPopupMenu(hmenu, TPM_RETURNCMD, pt.x, pt.y, NULL, hwnd, NULL);
if (xx == IDR_PAUSE) MessageBox(hwnd, TEXT("section 1"), szAppName, MB_OK);
if (xx == IDR_START) MessageBox(hwnd, TEXT("section 2"), szAppName, MB_OK);
if (xx == 0) PostMessage(hwnd, WM_LBUTTONDOWN, NULL, NULL);
MessageBox(hwnd, TEXT("right click"), szAppName, MB_OK);
}
break;
case WM_DESTROY:
Shell_NotifyIcon(NIM_DELETE, &nid);
PostQuitMessage(0);
break;
default:
if (message == WM_TASKBARCREATED)
SendMessage(hwnd, WM_CREATE, wParam, lParam);
break;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR szCmdLine, int iCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
HWND handle = FindWindow(NULL, szWndName);
if (handle != NULL)
{
MessageBox(NULL, TEXT("Application is already running"), szAppName, MB_ICONERROR);
return 0;
}
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("This program requires Windows NT!"), szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindowEx(WS_EX_TOOLWINDOW,
szAppName, szWndName,
WS_POPUP,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
Caution, it must be launched as a Windows desktop program.