6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
40 } APPLICATION_PAGE_LIST_ITEM, *LPAPPLICATION_PAGE_LIST_ITEM;
42 HWND hApplicationPage; /* Application List Property Page */
43 HWND hApplicationPageListCtrl; /* Application ListCtrl Window */
44 HWND hApplicationPageEndTaskButton; /* Application End Task button */
45 HWND hApplicationPageSwitchToButton; /* Application Switch To button */
46 HWND hApplicationPageNewTaskButton; /* Application New Task button */
47 static int nApplicationPageWidth;
48 static int nApplicationPageHeight;
49 static HANDLE hApplicationPageEvent = NULL; /* When this event becomes signaled then we refresh the app list */
50 static BOOL bSortAscending = TRUE;
53 void SwitchToThisWindow (
54 HWND hWnd, /* Handle to the window that should be activated */
55 BOOL bRestore /* Restore the window if it is minimized */
59 static void ApplicationPageUpdate(void)
61 /* Enable or disable the "End Task" & "Switch To" buttons */
62 if (ListView_GetSelectedCount(hApplicationPageListCtrl))
64 EnableWindow(hApplicationPageEndTaskButton, TRUE);
65 EnableWindow(hApplicationPageSwitchToButton, TRUE);
69 EnableWindow(hApplicationPageEndTaskButton, FALSE);
70 EnableWindow(hApplicationPageSwitchToButton, FALSE);
73 /* If we are on the applications tab the the windows menu will */
74 /* be present on the menu bar so enable & disable the menu items */
75 if (TabCtrl_GetCurSel(hTabWnd) == 0)
80 hMenu = GetMenu(hMainWnd);
81 hWindowsMenu = GetSubMenu(hMenu, 3);
83 /* Only one item selected */
84 if (ListView_GetSelectedCount(hApplicationPageListCtrl) == 1)
86 EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
87 EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
88 EnableMenuItem(hWindowsMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
89 EnableMenuItem(hWindowsMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED);
90 EnableMenuItem(hWindowsMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
91 EnableMenuItem(hWindowsMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_ENABLED);
93 /* More than one item selected */
94 else if (ListView_GetSelectedCount(hApplicationPageListCtrl) > 1)
96 EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_ENABLED);
97 EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_ENABLED);
98 EnableMenuItem(hWindowsMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
99 EnableMenuItem(hWindowsMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED);
100 EnableMenuItem(hWindowsMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_ENABLED);
101 EnableMenuItem(hWindowsMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
103 /* No items selected */
106 EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
107 EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
108 EnableMenuItem(hWindowsMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
109 EnableMenuItem(hWindowsMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
110 EnableMenuItem(hWindowsMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
111 EnableMenuItem(hWindowsMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
116 static void AddOrUpdateHwnd(HWND hWnd, TCHAR *szTitle, HICON hIcon, BOOL bHung)
118 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
119 HIMAGELIST hImageListLarge;
120 HIMAGELIST hImageListSmall;
123 BOOL bAlreadyInList = FALSE;
124 BOOL bItemRemoved = FALSE;
126 memset(&item, 0, sizeof(LV_ITEM));
128 /* Get the image lists */
129 hImageListLarge = ListView_GetImageList(hApplicationPageListCtrl, LVSIL_NORMAL);
130 hImageListSmall = ListView_GetImageList(hApplicationPageListCtrl, LVSIL_SMALL);
132 /* Check to see if it's already in our list */
133 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++)
135 memset(&item, 0, sizeof(LV_ITEM));
136 item.mask = LVIF_IMAGE|LVIF_PARAM;
138 SendMessage(hApplicationPageListCtrl, LVM_GETITEM, 0, (LPARAM) &item);
140 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
141 if (pAPLI->hWnd == hWnd)
143 bAlreadyInList = TRUE;
148 /* If it is already in the list then update it if necessary */
151 /* Check to see if anything needs updating */
152 if ((pAPLI->hIcon != hIcon) ||
153 (_tcsicmp(pAPLI->szTitle, szTitle) != 0) ||
154 (pAPLI->bHung != bHung))
156 /* Update the structure */
157 pAPLI->hIcon = hIcon;
158 pAPLI->bHung = bHung;
159 _tcscpy(pAPLI->szTitle, szTitle);
161 /* Update the image list */
162 ImageList_ReplaceIcon(hImageListLarge, item.iItem, hIcon);
163 ImageList_ReplaceIcon(hImageListSmall, item.iItem, hIcon);
165 /* Update the list view */
166 SendMessage(hApplicationPageListCtrl, LVM_REDRAWITEMS, 0, ListView_GetItemCount(hApplicationPageListCtrl));
167 /* UpdateWindow(hApplicationPageListCtrl); */
168 InvalidateRect(hApplicationPageListCtrl, NULL, 0);
171 /* It is not already in the list so add it */
174 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)malloc(sizeof(APPLICATION_PAGE_LIST_ITEM));
177 pAPLI->hIcon = hIcon;
178 pAPLI->bHung = bHung;
179 _tcscpy(pAPLI->szTitle, szTitle);
181 /* Add the item to the list */
182 memset(&item, 0, sizeof(LV_ITEM));
183 item.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
184 ImageList_AddIcon(hImageListLarge, hIcon);
185 item.iImage = ImageList_AddIcon(hImageListSmall, hIcon);
186 item.pszText = LPSTR_TEXTCALLBACK;
187 item.iItem = ListView_GetItemCount(hApplicationPageListCtrl);
188 item.lParam = (LPARAM)pAPLI;
189 SendMessage(hApplicationPageListCtrl, LVM_INSERTITEM, 0, (LPARAM) &item);
193 /* Check to see if we need to remove any items from the list */
194 for (i=ListView_GetItemCount(hApplicationPageListCtrl)-1; i>=0; i--)
196 memset(&item, 0, sizeof(LV_ITEM));
197 item.mask = LVIF_IMAGE|LVIF_PARAM;
199 SendMessage(hApplicationPageListCtrl, LVM_GETITEM, 0, (LPARAM) &item);
201 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
202 if (!IsWindow(pAPLI->hWnd)||
203 (_tcslen(pAPLI->szTitle) <= 0) ||
204 !IsWindowVisible(pAPLI->hWnd) ||
205 (GetParent(pAPLI->hWnd) != NULL) ||
206 (GetWindow(pAPLI->hWnd, GW_OWNER) != NULL) ||
207 (GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW))
209 ImageList_Remove(hImageListLarge, item.iItem);
210 ImageList_Remove(hImageListSmall, item.iItem);
212 SendMessage(hApplicationPageListCtrl, LVM_DELETEITEM, item.iItem, 0);
219 * If an item was removed from the list then
220 * we need to resync all the items with the
225 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++)
227 memset(&item, 0, sizeof(LV_ITEM));
228 item.mask = LVIF_IMAGE;
231 SendMessage(hApplicationPageListCtrl, LVM_SETITEM, 0, (LPARAM) &item);
235 ApplicationPageUpdate();
238 static BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
244 typedef int (__stdcall *IsHungAppWindowProc)(HWND);
245 IsHungAppWindowProc IsHungAppWindow;
248 /* Skip our window */
249 if (hWnd == hMainWnd)
252 bLargeIcon = TaskManagerSettings.View_LargeIcons ? TRUE : FALSE;
254 GetWindowText(hWnd, szText, 260); /* Get the window text */
256 /* Check and see if this is a top-level app window */
257 if ((_tcslen(szText) <= 0) ||
258 !IsWindowVisible(hWnd) ||
259 (GetParent(hWnd) != NULL) ||
260 (GetWindow(hWnd, GW_OWNER) != NULL) ||
261 (GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW))
263 return TRUE; /* Skip this window */
266 /* Get the icon for this window */
268 SendMessageTimeout(hWnd, WM_GETICON, bLargeIcon ? ICON_BIG /*1*/ : ICON_SMALL /*0*/, 0, 0, 1000, (PDWORD_PTR)&hIcon);
272 hIcon = (HICON)GetClassLongPtr(hWnd, bLargeIcon ? GCLP_HICON : GCLP_HICONSM);
273 if (!hIcon) hIcon = (HICON)GetClassLongPtr(hWnd, bLargeIcon ? GCLP_HICONSM : GCLP_HICON);
274 if (!hIcon) SendMessageTimeout(hWnd, WM_QUERYDRAGICON, 0, 0, 0, 1000, (PDWORD_PTR)&hIcon);
275 if (!hIcon) SendMessageTimeout(hWnd, WM_GETICON, bLargeIcon ? ICON_SMALL /*0*/ : ICON_BIG /*1*/, 0, 0, 1000, (PDWORD_PTR)&hIcon);
279 hIcon = LoadIcon(hInst, bLargeIcon ? MAKEINTRESOURCE(IDI_WINDOW) : MAKEINTRESOURCE(IDI_WINDOWSM));
283 IsHungAppWindow = (IsHungAppWindowProc)(FARPROC)GetProcAddress(GetModuleHandle(_T("USER32.DLL")), "IsHungAppWindow");
286 bHung = IsHungAppWindow(hWnd);
288 AddOrUpdateHwnd(hWnd, szText, hIcon, bHung);
293 static DWORD WINAPI ApplicationPageRefreshThread(void *lpParameter)
295 /* Create the event */
296 hApplicationPageEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
298 /* If we couldn't create the event then exit the thread */
299 if (!hApplicationPageEvent)
306 /* Wait on the event */
307 dwWaitVal = WaitForSingleObject(hApplicationPageEvent, INFINITE);
309 /* If the wait failed then the event object must have been */
310 /* closed and the task manager is exiting so exit this thread */
311 if (dwWaitVal == WAIT_FAILED)
314 if (dwWaitVal == WAIT_OBJECT_0)
316 /* Reset our event */
317 ResetEvent(hApplicationPageEvent);
322 * Should this be EnumDesktopWindows() instead?
324 EnumWindows(EnumWindowsProc, 0);
329 static void ApplicationPageShowContextMenu1(void)
337 hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_APPLICATION_PAGE_CONTEXT1));
338 hSubMenu = GetSubMenu(hMenu, 0);
340 if (TaskManagerSettings.View_LargeIcons)
341 CheckMenuRadioItem(hSubMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
342 else if (TaskManagerSettings.View_SmallIcons)
343 CheckMenuRadioItem(hSubMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
345 CheckMenuRadioItem(hSubMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
347 TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL);
352 static void ApplicationPageShowContextMenu2(void)
360 hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_APPLICATION_PAGE_CONTEXT2));
361 hSubMenu = GetSubMenu(hMenu, 0);
363 if (ListView_GetSelectedCount(hApplicationPageListCtrl) == 1)
365 EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
366 EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
367 EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
368 EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED);
369 EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
370 EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_ENABLED);
372 else if (ListView_GetSelectedCount(hApplicationPageListCtrl) > 1)
374 EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_ENABLED);
375 EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_ENABLED);
376 EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
377 EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED);
378 EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_ENABLED);
379 EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
383 EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
384 EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
385 EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
386 EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
387 EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
388 EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
391 SetMenuDefaultItem(hSubMenu, ID_APPLICATION_PAGE_SWITCHTO, MF_BYCOMMAND);
393 TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL);
398 static int CALLBACK ApplicationPageCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
400 LPAPPLICATION_PAGE_LIST_ITEM Param1;
401 LPAPPLICATION_PAGE_LIST_ITEM Param2;
403 if (bSortAscending) {
404 Param1 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam1;
405 Param2 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam2;
407 Param1 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam2;
408 Param2 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam1;
410 return _tcscmp(Param1->szTitle, Param2->szTitle);
413 static void ApplicationPageOnNotify(WPARAM wParam, LPARAM lParam)
419 LPAPPLICATION_PAGE_LIST_ITEM pAPLI;
422 idctrl = (int) wParam;
423 pnmh = (LPNMHDR) lParam;
424 pnmv = (LPNM_LISTVIEW) lParam;
425 pnmdi = (LV_DISPINFO*) lParam;
427 if (pnmh->hwndFrom == hApplicationPageListCtrl) {
428 switch (pnmh->code) {
429 case LVN_ITEMCHANGED:
430 ApplicationPageUpdate();
433 case LVN_GETDISPINFO:
434 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)pnmdi->item.lParam;
436 /* Update the item text */
437 if (pnmdi->item.iSubItem == 0)
439 _tcsncpy(pnmdi->item.pszText, pAPLI->szTitle, pnmdi->item.cchTextMax);
442 /* Update the item status */
443 else if (pnmdi->item.iSubItem == 1)
446 _tcsncpy(pnmdi->item.pszText, _T("Not Responding"), pnmdi->item.cchTextMax);
448 _tcsncpy(pnmdi->item.pszText, _T("Running"), pnmdi->item.cchTextMax);
455 if (ListView_GetSelectedCount(hApplicationPageListCtrl) < 1)
457 ApplicationPageShowContextMenu1();
461 ApplicationPageShowContextMenu2();
468 ApplicationPage_OnSwitchTo();
473 else if (pnmh->hwndFrom == ListView_GetHeader(hApplicationPageListCtrl))
479 if (ListView_GetSelectedCount(hApplicationPageListCtrl) < 1)
481 ApplicationPageShowContextMenu1();
485 ApplicationPageShowContextMenu2();
492 SendMessage(hApplicationPageListCtrl, LVM_SORTITEMS, 0, (LPARAM) ApplicationPageCompareFunc);
493 bSortAscending = !bSortAscending;
502 ApplicationPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
514 /* Save the width and height */
515 GetClientRect(hDlg, &rc);
516 nApplicationPageWidth = rc.right;
517 nApplicationPageHeight = rc.bottom;
519 /* Update window position */
520 SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
522 /* Get handles to the controls */
523 hApplicationPageListCtrl = GetDlgItem(hDlg, IDC_APPLIST);
524 hApplicationPageEndTaskButton = GetDlgItem(hDlg, IDC_ENDTASK);
525 hApplicationPageSwitchToButton = GetDlgItem(hDlg, IDC_SWITCHTO);
526 hApplicationPageNewTaskButton = GetDlgItem(hDlg, IDC_NEWTASK);
528 SetWindowText(hApplicationPageListCtrl, _T("Tasks"));
530 /* Initialize the application page's controls */
531 column.mask = LVCF_TEXT|LVCF_WIDTH;
532 _tcscpy(szTemp, _T("Task"));
533 column.pszText = szTemp;
535 /* Add the "Task" column */
536 SendMessage(hApplicationPageListCtrl, LVM_INSERTCOLUMN, 0, (LPARAM) &column);
537 column.mask = LVCF_TEXT|LVCF_WIDTH;
538 _tcscpy(szTemp, _T("Status"));
539 column.pszText = szTemp;
541 /* Add the "Status" column */
542 SendMessage(hApplicationPageListCtrl, LVM_INSERTCOLUMN, 1, (LPARAM) &column);
544 SendMessage(hApplicationPageListCtrl, LVM_SETIMAGELIST, LVSIL_SMALL,
545 (LPARAM) ImageList_Create(16, 16, ILC_COLOR8|ILC_MASK, 0, 1));
546 SendMessage(hApplicationPageListCtrl, LVM_SETIMAGELIST, LVSIL_NORMAL,
547 (LPARAM) ImageList_Create(32, 32, ILC_COLOR8|ILC_MASK, 0, 1));
549 UpdateApplicationListControlViewSetting();
551 /* Start our refresh thread */
552 CreateThread(NULL, 0, ApplicationPageRefreshThread, NULL, 0, NULL);
557 /* Close the event handle, this will make the */
558 /* refresh thread exit when the wait fails */
559 CloseHandle(hApplicationPageEvent);
564 /* Handle the button clicks */
565 switch (LOWORD(wParam))
568 ApplicationPage_OnEndTask();
571 ApplicationPage_OnSwitchTo();
574 SendMessage(hMainWnd, WM_COMMAND, MAKEWPARAM(ID_FILE_NEW, 0), 0);
581 if (wParam == SIZE_MINIMIZED)
586 nXDifference = cx - nApplicationPageWidth;
587 nYDifference = cy - nApplicationPageHeight;
588 nApplicationPageWidth = cx;
589 nApplicationPageHeight = cy;
591 /* Reposition the application page's controls */
592 GetWindowRect(hApplicationPageListCtrl, &rc);
593 cx = (rc.right - rc.left) + nXDifference;
594 cy = (rc.bottom - rc.top) + nYDifference;
595 SetWindowPos(hApplicationPageListCtrl, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
596 InvalidateRect(hApplicationPageListCtrl, NULL, TRUE);
598 GetClientRect(hApplicationPageEndTaskButton, &rc);
599 MapWindowPoints(hApplicationPageEndTaskButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
600 cx = rc.left + nXDifference;
601 cy = rc.top + nYDifference;
602 SetWindowPos(hApplicationPageEndTaskButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
603 InvalidateRect(hApplicationPageEndTaskButton, NULL, TRUE);
605 GetClientRect(hApplicationPageSwitchToButton, &rc);
606 MapWindowPoints(hApplicationPageSwitchToButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
607 cx = rc.left + nXDifference;
608 cy = rc.top + nYDifference;
609 SetWindowPos(hApplicationPageSwitchToButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
610 InvalidateRect(hApplicationPageSwitchToButton, NULL, TRUE);
612 GetClientRect(hApplicationPageNewTaskButton, &rc);
613 MapWindowPoints(hApplicationPageNewTaskButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
614 cx = rc.left + nXDifference;
615 cy = rc.top + nYDifference;
616 SetWindowPos(hApplicationPageNewTaskButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
617 InvalidateRect(hApplicationPageNewTaskButton, NULL, TRUE);
622 ApplicationPageOnNotify(wParam, lParam);
630 void RefreshApplicationPage(void)
632 /* Signal the event so that our refresh thread */
633 /* will wake up and refresh the application page */
634 SetEvent(hApplicationPageEvent);
637 void UpdateApplicationListControlViewSetting(void)
639 DWORD dwStyle = GetWindowLong(hApplicationPageListCtrl, GWL_STYLE);
641 dwStyle &= ~LVS_REPORT;
642 dwStyle &= ~LVS_ICON;
643 dwStyle &= ~LVS_LIST;
644 dwStyle &= ~LVS_SMALLICON;
646 if (TaskManagerSettings.View_LargeIcons)
648 else if (TaskManagerSettings.View_SmallIcons)
649 dwStyle |= LVS_SMALLICON;
651 dwStyle |= LVS_REPORT;
653 SetWindowLong(hApplicationPageListCtrl, GWL_STYLE, dwStyle);
655 RefreshApplicationPage();
658 void ApplicationPage_OnViewLargeIcons(void)
663 hMenu = GetMenu(hMainWnd);
664 hViewMenu = GetSubMenu(hMenu, 2);
666 TaskManagerSettings.View_LargeIcons = TRUE;
667 TaskManagerSettings.View_SmallIcons = FALSE;
668 TaskManagerSettings.View_Details = FALSE;
669 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
671 UpdateApplicationListControlViewSetting();
674 void ApplicationPage_OnViewSmallIcons(void)
679 hMenu = GetMenu(hMainWnd);
680 hViewMenu = GetSubMenu(hMenu, 2);
682 TaskManagerSettings.View_LargeIcons = FALSE;
683 TaskManagerSettings.View_SmallIcons = TRUE;
684 TaskManagerSettings.View_Details = FALSE;
685 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
687 UpdateApplicationListControlViewSetting();
690 void ApplicationPage_OnViewDetails(void)
695 hMenu = GetMenu(hMainWnd);
696 hViewMenu = GetSubMenu(hMenu, 2);
698 TaskManagerSettings.View_LargeIcons = FALSE;
699 TaskManagerSettings.View_SmallIcons = FALSE;
700 TaskManagerSettings.View_Details = TRUE;
701 CheckMenuRadioItem(hViewMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
703 UpdateApplicationListControlViewSetting();
706 void ApplicationPage_OnWindowsTileHorizontally(void)
708 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
714 hWndArray = (HWND*)malloc(sizeof(HWND) * ListView_GetItemCount(hApplicationPageListCtrl));
717 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
718 memset(&item, 0, sizeof(LV_ITEM));
719 item.mask = LVIF_STATE|LVIF_PARAM;
721 item.stateMask = (UINT)-1;
722 SendMessage(hApplicationPageListCtrl, LVM_GETITEM, 0, (LPARAM) &item);
724 if (item.state & LVIS_SELECTED) {
725 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
728 hWndArray[nWndCount] = pAPLI->hWnd;
733 TileWindows(NULL, MDITILE_HORIZONTAL, NULL, nWndCount, hWndArray);
737 void ApplicationPage_OnWindowsTileVertically(void)
739 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
745 hWndArray = (HWND*)malloc(sizeof(HWND) * ListView_GetItemCount(hApplicationPageListCtrl));
748 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
749 memset(&item, 0, sizeof(LV_ITEM));
750 item.mask = LVIF_STATE|LVIF_PARAM;
752 item.stateMask = (UINT)-1;
753 SendMessage(hApplicationPageListCtrl, LVM_GETITEM, 0, (LPARAM) &item);
755 if (item.state & LVIS_SELECTED) {
756 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
758 hWndArray[nWndCount] = pAPLI->hWnd;
764 TileWindows(NULL, MDITILE_VERTICAL, NULL, nWndCount, hWndArray);
768 void ApplicationPage_OnWindowsMinimize(void)
770 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
774 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
775 memset(&item, 0, sizeof(LV_ITEM));
776 item.mask = LVIF_STATE|LVIF_PARAM;
778 item.stateMask = (UINT)-1;
779 SendMessage(hApplicationPageListCtrl, LVM_GETITEM, 0, (LPARAM) &item);
780 if (item.state & LVIS_SELECTED) {
781 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
783 ShowWindow(pAPLI->hWnd, SW_MINIMIZE);
789 void ApplicationPage_OnWindowsMaximize(void)
791 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
795 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
796 memset(&item, 0, sizeof(LV_ITEM));
797 item.mask = LVIF_STATE|LVIF_PARAM;
799 item.stateMask = (UINT)-1;
800 SendMessage(hApplicationPageListCtrl, LVM_GETITEM, 0, (LPARAM) &item);
801 if (item.state & LVIS_SELECTED) {
802 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
804 ShowWindow(pAPLI->hWnd, SW_MAXIMIZE);
810 void ApplicationPage_OnWindowsCascade(void)
812 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
818 hWndArray = (HWND*)malloc(sizeof(HWND) * ListView_GetItemCount(hApplicationPageListCtrl));
821 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
822 memset(&item, 0, sizeof(LV_ITEM));
823 item.mask = LVIF_STATE|LVIF_PARAM;
825 item.stateMask = (UINT)-1;
826 SendMessage(hApplicationPageListCtrl, LVM_GETITEM, 0, (LPARAM) &item);
827 if (item.state & LVIS_SELECTED) {
828 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
830 hWndArray[nWndCount] = pAPLI->hWnd;
835 CascadeWindows(NULL, 0, NULL, nWndCount, hWndArray);
839 void ApplicationPage_OnWindowsBringToFront(void)
841 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
845 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
846 memset(&item, 0, sizeof(LV_ITEM));
847 item.mask = LVIF_STATE|LVIF_PARAM;
849 item.stateMask = (UINT)-1;
850 SendMessage(hApplicationPageListCtrl, LVM_GETITEM, 0, (LPARAM) &item);
851 if (item.state & LVIS_SELECTED) {
852 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
857 if (IsIconic(pAPLI->hWnd))
858 ShowWindow(pAPLI->hWnd, SW_RESTORE);
859 BringWindowToTop(pAPLI->hWnd);
863 void ApplicationPage_OnSwitchTo(void)
865 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
869 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
870 memset(&item, 0, sizeof(LV_ITEM));
871 item.mask = LVIF_STATE|LVIF_PARAM;
873 item.stateMask = (UINT)-1;
874 SendMessage(hApplicationPageListCtrl, LVM_GETITEM, 0, (LPARAM) &item);
876 if (item.state & LVIS_SELECTED) {
877 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
882 typedef void (WINAPI *PROCSWITCHTOTHISWINDOW) (HWND, BOOL);
883 PROCSWITCHTOTHISWINDOW SwitchToThisWindow;
885 HMODULE hUser32 = GetModuleHandle(_T("USER32"));
886 SwitchToThisWindow = (PROCSWITCHTOTHISWINDOW)GetProcAddress(hUser32, "SwitchToThisWindow");
887 if (SwitchToThisWindow) {
888 SwitchToThisWindow(pAPLI->hWnd, TRUE);
890 if (IsIconic(pAPLI->hWnd))
891 ShowWindow(pAPLI->hWnd, SW_RESTORE);
892 BringWindowToTop(pAPLI->hWnd);
893 SetForegroundWindow(pAPLI->hWnd);
895 if (TaskManagerSettings.MinimizeOnUse)
896 ShowWindow(hMainWnd, SW_MINIMIZE);
900 void ApplicationPage_OnEndTask(void)
902 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
906 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
907 memset(&item, 0, sizeof(LV_ITEM));
908 item.mask = LVIF_STATE|LVIF_PARAM;
910 item.stateMask = (UINT)-1;
911 SendMessage(hApplicationPageListCtrl, LVM_GETITEM, 0, (LPARAM) &item);
912 if (item.state & LVIS_SELECTED) {
913 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
915 PostMessage(pAPLI->hWnd, WM_CLOSE, 0, 0);
921 void ApplicationPage_OnGotoProcess(void)
923 LPAPPLICATION_PAGE_LIST_ITEM pAPLI = NULL;
928 for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++) {
929 memset(&item, 0, sizeof(LV_ITEM));
930 item.mask = LVIF_STATE|LVIF_PARAM;
932 item.stateMask = (UINT)-1;
933 SendMessage(hApplicationPageListCtrl, LVM_GETITEM, 0, (LPARAM) &item);
934 if (item.state & LVIS_SELECTED) {
935 pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
942 GetWindowThreadProcessId(pAPLI->hWnd, &dwProcessId);
944 * Switch to the process tab
946 TabCtrl_SetCurFocus(hTabWnd, 1);
948 * FIXME: Select the process item in the list
950 for (i=0; i<ListView_GetItemCount(hProcessPage); i++) {