_last_foreground_wnd = 0;
}
- // fill task bar with buttons for enumerated top level windows
-BOOL CALLBACK TaskBar::EnumWndProc(HWND hwnd, LPARAM lparam)
+TaskBar::~TaskBar()
{
- TaskBar* pThis = (TaskBar*)lparam;
-
- DWORD style = GetWindowStyle(hwnd);
- DWORD ex_style = GetWindowExStyle(hwnd);
-
- if ((style&WS_VISIBLE) && !(ex_style&WS_EX_TOOLWINDOW) &&
- !GetParent(hwnd) && !GetWindow(hwnd,GW_OWNER)) {
- TBBUTTON btn = {-2/*I_IMAGENONE*/, 0, TBSTATE_ENABLED/*|TBSTATE_ELLIPSES*/, BTNS_BUTTON, {0, 0}, 0, 0};
-
- TaskBarMap::iterator found = pThis->_map.find(hwnd);
- int last_id = 0;
-
- if (found != pThis->_map.end()) {
- last_id = found->second._id;
-
- if (!last_id)
- found->second._id = pThis->_next_id++;
- } else {
- HICON hicon = get_window_icon(hwnd);
- HBITMAP hbmp = create_bitmap_from_icon(hicon, pThis->_htoolbar, GetSysColorBrush(COLOR_BTNFACE));
-
- TBADDBITMAP ab = {0, (UINT_PTR)hbmp};
- int bmp_idx = SendMessage(pThis->_htoolbar, TB_ADDBITMAP, 1, (LPARAM)&ab);
-
- TaskBarEntry bmp = {pThis->_next_id++, hbmp, bmp_idx, 0, 0};
-
- pThis->_map[hwnd] = bmp;
- found = pThis->_map.find(hwnd);
- }
-
- TaskBarEntry& entry = found->second;
-
- ++entry._used;
- btn.idCommand = entry._id;
-
- // create new toolbar buttons for new windows
- if (!last_id) {
- if (hwnd == GetForegroundWindow())
- btn.fsState |= TBSTATE_PRESSED/*|TBSTATE_MARKED*/;
-
- TCHAR title[BUFFER_LEN];
-
- if (!GetWindowText(hwnd, title, BUFFER_LEN))
- title[0] = '\0';
-
- if (title[0])
- btn.iString = (INT_PTR)title;
-
- btn.iBitmap = entry._bmp_idx;
- entry._btn_idx = SendMessage(pThis->_htoolbar, TB_BUTTONCOUNT, 0, 0);
-
- SendMessage(pThis->_htoolbar, TB_INSERTBUTTON, entry._btn_idx, (LPARAM)&btn);
- }
- }
-
- return TRUE;
+ //DeinstallShellHook();
}
LRESULT TaskBar::Init(LPCREATESTRUCT pcs)
_next_id = IDC_FIRST_APP;
+ //InstallShellHook(_hwnd, WM_SHELLHOOK_NOTIFY);
+
Refresh();
- SetTimer(_hwnd, 0, 1000, NULL);
+ SetTimer(_hwnd, 0, 200, NULL);
return 0;
}
SendMessage(_htoolbar, WM_SIZE, 0, 0);
break;
- case WM_TIMER: // could be optimized by using WH_CBT hooks instead of timer
+ case WM_TIMER:
Refresh();
return 0;
+ case WM_SHELLHOOK_NOTIFY: {
+ int code = lparam;
+/*
+ switch(code) {
+ case HSHELL_WINDOWCREATED:
+ case HSHELL_WINDOWDESTROYED:
+ case HSHELL_WINDOWACTIVATED:
+ case HSHELL_WINDOWREPLACED:
+ Refresh();
+ break;
+ } */
+ Refresh();
+ break;}
+
default:
return super::WndProc(nmsg, wparam, lparam);
}
HWND hwnd = found->first;
if (hwnd==GetForegroundWindow() || hwnd==_last_foreground_wnd) {
- ShowWindow(hwnd, SW_MINIMIZE);
+ ShowWindowAsync(hwnd, SW_MINIMIZE);
_last_foreground_wnd = 0;
} else {
// switch to selected application window
- SetForegroundWindow(hwnd);
-
if (IsIconic(hwnd))
- ShowWindow(hwnd, SW_RESTORE);
+ ShowWindowAsync(hwnd, SW_RESTORE);
+
+ SetForegroundWindow(hwnd);
_last_foreground_wnd = hwnd;
}
return super::Command(id, code);
}
+ // fill task bar with buttons for enumerated top level windows
+BOOL CALLBACK TaskBar::EnumWndProc(HWND hwnd, LPARAM lparam)
+{
+ TaskBar* pThis = (TaskBar*)lparam;
+
+ DWORD style = GetWindowStyle(hwnd);
+ DWORD ex_style = GetWindowExStyle(hwnd);
+
+ if ((style&WS_VISIBLE) && !(ex_style&WS_EX_TOOLWINDOW) &&
+ !GetParent(hwnd) && !GetWindow(hwnd,GW_OWNER)) {
+ TBBUTTON btn = {-2/*I_IMAGENONE*/, 0, TBSTATE_ENABLED/*|TBSTATE_ELLIPSES*/, BTNS_BUTTON, {0, 0}, 0, 0};
+
+ TaskBarMap::iterator found = pThis->_map.find(hwnd);
+ int last_id = 0;
+
+ if (found != pThis->_map.end()) {
+ last_id = found->second._id;
+
+ if (!last_id)
+ found->second._id = pThis->_next_id++;
+ } else {
+ HICON hicon = get_window_icon(hwnd);
+ HBITMAP hbmp = create_bitmap_from_icon(hicon, pThis->_htoolbar, GetSysColorBrush(COLOR_BTNFACE));
+
+ TBADDBITMAP ab = {0, (UINT_PTR)hbmp};
+ int bmp_idx = SendMessage(pThis->_htoolbar, TB_ADDBITMAP, 1, (LPARAM)&ab);
+
+ TaskBarEntry bmp = {pThis->_next_id++, hbmp, bmp_idx, 0, 0};
+
+ pThis->_map[hwnd] = bmp;
+ found = pThis->_map.find(hwnd);
+ }
+
+ TaskBarEntry& entry = found->second;
+
+ ++entry._used;
+ btn.idCommand = entry._id;
+
+ TCHAR title[BUFFER_LEN];
+
+ if (!GetWindowText(hwnd, title, BUFFER_LEN))
+ title[0] = '\0';
+
+ //@@ refresh window titles
+
+ // create new toolbar buttons for new windows
+ if (!last_id) {
+ if (hwnd == GetForegroundWindow())
+ btn.fsState |= TBSTATE_PRESSED/*|TBSTATE_MARKED*/;
+
+ if (title[0])
+ btn.iString = (INT_PTR)title;
+
+ btn.iBitmap = entry._bmp_idx;
+ entry._btn_idx = SendMessage(pThis->_htoolbar, TB_BUTTONCOUNT, 0, 0);
+
+ SendMessage(pThis->_htoolbar, TB_INSERTBUTTON, entry._btn_idx, (LPARAM)&btn);
+ }
+
+ // move iconic windows out of sight
+ if (IsIconic(hwnd)) {
+ RECT rect;
+ GetWindowRect(hwnd, &rect);
+
+ if (rect.bottom > 0)
+ SetWindowPos(hwnd, 0, -32000, -32000, 0, 0, SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
+ }
+ }
+
+ return TRUE;
+}
+
void TaskBar::Refresh()
{
for(TaskBarMap::iterator it=_map.begin(); it!=_map.end(); ++it)