My program consists of one window, created as follows:
/* handle for window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
WM_TASKBAR = RegisterWindowMessageA("TaskbarCreated");
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof(WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MyProg));
wincl.hIconSm = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MyProg));
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
wincl.hbrBackground = (HBRUSH)(CreateSolidBrush(RGB(200, 200, 200)));
MainWindowHandle = CreateWindowEx(
0, /* Extended possibilites for variation */
szClassName, /* Classname */
szClassName, /* Title Text */
(WS_OVERLAPPED), /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
500, /* The programs width */
400, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
At the start (WM_CREATE) and when a
WM_SYSCOMMAND SC_MINIMIZE OR SC_CLOSE
occurs, I call
ShowWindow(MainWindowHandle, SW_HIDE);
And using a callback from the systray icon I show the window using the next line, or hide it again using the above:
ShowWindow(MainWindowHandle, SW_SHOW);
This all works fine, the window is hidden and the taskbar icon disappears and vice versa. Unless the program is started before the windows taskbar is visible. This happens when windows 10 is 'shut down' and started again, instead of going through a proper restart loop. Even though then the window is hidden properly at startup, the taskbar icon remains visible. The only way to get rid of it is to show and hide the window, causing the window to flash on screen for a short period, which I don't want to happen, or at least not when not necessary. Is there any way to check if the taskbar icon is visible while the window is hidden, or maybe to know when the program is started before the taskbar is visible and then wait for the taskbar and do a quick popup-flash to hide the icon?
I use the
s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
callback as follows:
LRESULT CALLBACK WindowProcedure(HWND MainWindowHandle, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == s_uTaskbarRestart && !IsWindowVisible(MainWindowHandle))
{
restore();
minimize();
visible = false;
return 0;
}
}
But that doesn't work. It would if I didn't check for the window being visible, but that would cause the window to flash every time the taskbar restarts.
This kind of demonstrates the problem.. The window is invisible, but it is shown in the taskbar as if it is visible.