return 1;
_htoolbar = CreateToolbarEx(_hwnd,
- WS_CHILD|WS_VISIBLE|CCS_NODIVIDER|CCS_TOP|
- TBSTYLE_LIST|TBSTYLE_TOOLTIPS|TBSTYLE_WRAPABLE,
- IDW_TASKTOOLBAR, 0, 0, 0, NULL, 0, 0, 0, 16, 16, sizeof(TBBUTTON));
+ WS_CHILD|WS_VISIBLE|CCS_NODIVIDER|CCS_TOP|
+ TBSTYLE_LIST|TBSTYLE_TOOLTIPS|TBSTYLE_WRAPABLE,
+ IDW_TASKTOOLBAR, 0, 0, 0, NULL, 0, 0, 0, 16, 16, sizeof(TBBUTTON));
SendMessage(_htoolbar, TB_SETBUTTONWIDTH, 0, MAKELONG(80,160));
//SendMessage(_htoolbar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_MIXEDBUTTONS);
LRESULT TaskBar::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
{
switch(nmsg) {
-/* case WM_CLOSE:
- break; */
-
case WM_SIZE:
SendMessage(_htoolbar, WM_SIZE, 0, 0);
break;
TaskBarMap::iterator found = _map.find_id(id);
if (found != _map.end()) {
- HWND hwnd = found->first;
+ ActivateApp(found);
+ return 0;
+ }
- if (hwnd==GetForegroundWindow() || hwnd==_last_foreground_wnd) {
- ShowWindowAsync(hwnd, SW_MINIMIZE);
- _last_foreground_wnd = 0;
- } else {
- // switch to selected application window
- if (IsIconic(hwnd))
- ShowWindowAsync(hwnd, SW_RESTORE);
+ return super::Command(id, code);
+}
+
+int TaskBar::Notify(int id, NMHDR* pnmh)
+{
+ if (pnmh->hwndFrom == _htoolbar)
+ switch(pnmh->code) {
+ case NM_RCLICK: {
+ TaskBarMap::iterator it;
+ Point pt(GetMessagePos());
+ ScreenToClient(_htoolbar, &pt);
+
+ int idx = SendMessage(_htoolbar, TB_HITTEST, 0, (LPARAM)&pt);
- SetForegroundWindow(hwnd);
+ if (idx>=0 && (it=_map.find_by_idx(idx))!=_map.end()) {
+ TaskBarEntry& entry = it->second;
- _last_foreground_wnd = hwnd;
+ ActivateApp(it, false);
+ ShowAppSystemMenu(it);
+ }
+ break;}
+
+ default:
+ return super::Notify(id, pnmh);
}
- Refresh();
+ return 0;
+}
- return 0;
+
+void TaskBar::ActivateApp(TaskBarMap::iterator it, bool can_minimize)
+{
+ HWND hwnd = it->first;
+
+ if (can_minimize && (hwnd==GetForegroundWindow() || hwnd==_last_foreground_wnd)) {
+ ShowWindowAsync(hwnd, SW_MINIMIZE);
+ _last_foreground_wnd = 0;
+ } else {
+ // switch to selected application window
+ if (IsIconic(hwnd))
+ ShowWindowAsync(hwnd, SW_RESTORE);
+
+ SetForegroundWindow(hwnd);
+
+ _last_foreground_wnd = hwnd;
}
- return super::Command(id, code);
+ Refresh();
+}
+
+void TaskBar::ShowAppSystemMenu(TaskBarMap::iterator it)
+{
+ HMENU hmenu = GetSystemMenu(it->first, FALSE);
+
+ if (hmenu) {
+ POINT pt;
+
+ GetCursorPos(&pt);
+ int cmd = TrackPopupMenu(hmenu, TPM_LEFTBUTTON|TPM_RIGHTBUTTON|TPM_RETURNCMD, pt.x, pt.y, 0, _hwnd, NULL);
+
+ if (cmd)
+ PostMessage(it->first, WM_SYSCOMMAND, cmd, 0);
+ }
}
return end();
}
+
+TaskBarMap::iterator TaskBarMap::find_by_idx(int idx)
+{
+ for(iterator it=begin(); it!=end(); ++it)
+ if (it->second._btn_idx == idx)
+ return it;
+
+ return end();
+}
#define IDW_TASKTOOLBAR 100
+
/// internal task bar button management entry
struct TaskBarEntry
{
BYTE _fsState;
};
- /// map for managing the task bar buttons
+ /// map for managing the task bar buttons, mapped by application window handle
struct TaskBarMap : public map<HWND, TaskBarEntry>
{
~TaskBarMap();
iterator find_id(int id);
+ iterator find_by_idx(int idx);
};
-struct DesktopBar;
/// Taskbar window
struct TaskBar : public Window
LRESULT Init(LPCREATESTRUCT pcs);
LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
int Command(int id, int code);
+ int Notify(int id, NMHDR* pnmh);
+
+ void ActivateApp(TaskBarMap::iterator it, bool can_minimize=true);
+ void ShowAppSystemMenu(TaskBarMap::iterator it);
static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam);