You can do this by running the mouse cursor over the dead icon. I found a function that does this from my KillProcess utility.
Code:
void refreshTray() {
HWND hTaskbar, hNotify, hTray;
RECT rc;
int xPos, yPos;
// Obtain task tray window handle by drilling down
hTaskbar = FindWindow(TEXT("Shell_TrayWnd"), NULL);
hNotify = FindWindowEx(hTaskbar, NULL, TEXT("TrayNotifyWnd"), NULL);
hTray = FindWindowEx(hNotify, NULL, TEXT("ToolbarWindow32"), NULL);
if (hTray == NULL || GetClientRect( hTray, &rc ) == 0) return;
// Simulate mouse moving along task icons
// This will kill dead icons
for (yPos = 0;yPos < rc.bottom; yPos += 4) {
for (xPos = 0;xPos < rc.right; xPos += 4) {
PostMessage( hTray, WM_MOUSEMOVE, 0, MAKELONG(xPos, yPos) );
}
}
}