home *** CD-ROM | disk | FTP | other *** search
Wrap
// TaskTrackerWnd.cpp: implementation of the CTaskTrackerWnd class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "TaskTrackerWnd.h" BOOL CALLBACK WndEnumProc(HWND hWnd, LPARAM lParam); ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CTaskTrackerWnd::CTaskTrackerWnd() { m_vWnds.resize(0); m_hSwitcherWnd = NULL; } CTaskTrackerWnd::~CTaskTrackerWnd() { if(m_hWnd) { DestroyWindow(m_hWnd); m_hWnd = NULL; } UnregisterClass(m_pWindowClass,m_hInstance); } unsigned long int CTaskTrackerWnd::Init(HWND hParent,char *pWindowName, unsigned long int dwExStyle,unsigned long int dwStyle, int x, int y,int nWidth, int nHeight, HMENU hMenu, int nCmdShow) {// begin Init unsigned long int nRtnVal = CMyWindow::Init(hParent,pWindowName,dwExStyle,dwStyle,x,y,nWidth,nHeight,hMenu,nCmdShow); // set refresh timer SetTimer(m_hWnd,1,500,NULL); return nRtnVal; }// end Init LRESULT CTaskTrackerWnd::WndProc(HWND hWnd,UINT nMessage,WPARAM wParam,LPARAM lParam) {// begin WndProc switch(nMessage) {// begin nMessage switch case WM_TIMER: OnTimer(); break; case WM_DESTROY: OnDestroy(); break; }// end nMessage swtich return CMyWindow::WndProc(hWnd, nMessage, wParam, lParam); }// end WndProc bool CTaskTrackerWnd::InList(HWND hWnd) {// begin InList for(int i = m_vWnds.size()-1;i > -1;i--) { if(m_vWnds[i] == hWnd) return true; } return false; }// end InList BOOL CALLBACK WndEnumProc(HWND hWnd, LPARAM lParam) {// begin WndEnumProc CTaskTrackerWnd *pttmWnd = (CTaskTrackerWnd *)lParam; // check if the window is already in the open window list if(IsWindowVisible(hWnd)) {// begin visible // check to see if the owner is visible if(GetWindow(hWnd,GW_OWNER)) return TRUE; // check to see if the window is a toolwindow LONG nExStyles = GetWindowLong(hWnd,GWL_EXSTYLE); if(nExStyles & WS_EX_TOOLWINDOW) return TRUE; if(!pttmWnd->InList(hWnd)) {// begin add to the list // add it pttmWnd->Add(hWnd); // notify control window PostMessage(pttmWnd->GetSwitcherHwnd(),WM_ADDTASK,(WPARAM)hWnd,0); }// end add to the list }// end visible return TRUE; }// end WndEnumProc void CTaskTrackerWnd::Add(HWND hWnd) {// begin Add m_vWnds.resize(m_vWnds.size()+1); m_vWnds[m_vWnds.size()-1] = hWnd; }// end Add HWND CTaskTrackerWnd::SetSwitcherHwnd(HWND hWnd) {// begin SetSwitcherHwnd HWND hOld = m_hSwitcherWnd; m_hSwitcherWnd = hWnd; return m_hSwitcherWnd; }// end SetSwitcherHwnd HWND CTaskTrackerWnd::GetSwitcherHwnd() {// begin GetSwitcherHwnd return m_hSwitcherWnd; }// end GetSwitcherHwnd void CTaskTrackerWnd::OnTimer() {// begin OnTimer // update new windows EnumWindows(WndEnumProc,(LPARAM)this); // remove any closed/hidden ones for(int i = 0;i < m_vWnds.size();i++) {// begin search if(!IsWindow(m_vWnds[i]) || !IsWindowVisible(m_vWnds[i])) {// begin remove // save it HWND hDeleteWnd = m_vWnds[i]; // remove it m_vWnds.erase(&m_vWnds[i]); // decrement so the next window isn't skipped over i--; // notify the switcher window of the change PostMessage(m_hSwitcherWnd,WM_DELETETASK,(WPARAM)hDeleteWnd,0); }// end remove }// end search }// end OnTimer void CTaskTrackerWnd::OnDestroy() {// begin OnDestroy // stop the timer KillTimer(m_hWnd,1); // empty the vector m_vWnds.clear(); m_vWnds.resize(0); }// end OnDestroy