6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 * Copyright (C) 2008 Vladimir Pankratov
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
38 } APPLICATION_PAGE_LIST_ITEM
, *LPAPPLICATION_PAGE_LIST_ITEM
;
40 HWND hApplicationPage
; /* Application List Property Page */
41 HWND hApplicationPageListCtrl
; /* Application ListCtrl Window */
42 HWND hApplicationPageEndTaskButton
; /* Application End Task button */
43 HWND hApplicationPageSwitchToButton
; /* Application Switch To button */
44 HWND hApplicationPageNewTaskButton
; /* Application New Task button */
45 static int nApplicationPageWidth
;
46 static int nApplicationPageHeight
;
47 static HANDLE hApplicationPageEvent
= NULL
; /* When this event becomes signaled then we refresh the app list */
48 static BOOL bSortAscending
= TRUE
;
50 static void ApplicationPageUpdate(void)
52 /* Enable or disable the "End Task" & "Switch To" buttons */
53 if (SendMessageW(hApplicationPageListCtrl
, LVM_GETSELECTEDCOUNT
, 0, 0))
55 EnableWindow(hApplicationPageEndTaskButton
, TRUE
);
56 EnableWindow(hApplicationPageSwitchToButton
, TRUE
);
60 EnableWindow(hApplicationPageEndTaskButton
, FALSE
);
61 EnableWindow(hApplicationPageSwitchToButton
, FALSE
);
64 /* If we are on the applications tab, then the windows menu will */
65 /* be present on the menu bar so enable & disable the menu items */
66 if (SendMessageW(hTabWnd
, TCM_GETCURSEL
, 0, 0) == 0)
72 hMenu
= GetMenu(hMainWnd
);
73 hWindowsMenu
= GetSubMenu(hMenu
, 3);
74 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETSELECTEDCOUNT
, 0, 0);
76 /* Only one item selected */
79 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
80 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
81 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
82 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
83 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
84 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_ENABLED
);
86 /* More than one item selected */
89 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_ENABLED
);
90 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_ENABLED
);
91 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
92 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
93 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_ENABLED
);
94 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
96 /* No items selected */
99 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
100 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
101 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
102 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
103 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
104 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
109 static void AddOrUpdateHwnd(HWND hWnd
, WCHAR
*wszTitle
, HICON hIcon
, BOOL bHung
)
111 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
112 HIMAGELIST hImageListLarge
;
113 HIMAGELIST hImageListSmall
;
116 BOOL bAlreadyInList
= FALSE
;
117 BOOL bItemRemoved
= FALSE
;
119 memset(&item
, 0, sizeof(LV_ITEMW
));
121 /* Get the image lists */
122 hImageListLarge
= (HIMAGELIST
)SendMessageW(hApplicationPageListCtrl
, LVM_GETIMAGELIST
, LVSIL_NORMAL
, 0);
123 hImageListSmall
= (HIMAGELIST
)SendMessageW(hApplicationPageListCtrl
, LVM_GETIMAGELIST
, LVSIL_SMALL
, 0);
125 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
126 /* Check to see if it's already in our list */
127 for (i
=0; i
<count
; i
++)
129 memset(&item
, 0, sizeof(LV_ITEMW
));
130 item
.mask
= LVIF_IMAGE
|LVIF_PARAM
;
132 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
134 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
135 if (pAPLI
->hWnd
== hWnd
)
137 bAlreadyInList
= TRUE
;
142 /* If it is already in the list then update it if necessary */
145 /* Check to see if anything needs updating */
146 if ((pAPLI
->hIcon
!= hIcon
) ||
147 (lstrcmpW(pAPLI
->wszTitle
, wszTitle
) != 0) ||
148 (pAPLI
->bHung
!= bHung
))
150 /* Update the structure */
151 pAPLI
->hIcon
= hIcon
;
152 pAPLI
->bHung
= bHung
;
153 lstrcpyW(pAPLI
->wszTitle
, wszTitle
);
155 /* Update the image list */
156 ImageList_ReplaceIcon(hImageListLarge
, item
.iItem
, hIcon
);
157 ImageList_ReplaceIcon(hImageListSmall
, item
.iItem
, hIcon
);
159 /* Update the list view */
160 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
161 SendMessageW(hApplicationPageListCtrl
, LVM_REDRAWITEMS
, 0, count
);
162 /* UpdateWindow(hApplicationPageListCtrl); */
163 InvalidateRect(hApplicationPageListCtrl
, NULL
, 0);
166 /* It is not already in the list so add it */
169 pAPLI
= HeapAlloc(GetProcessHeap(), 0, sizeof(APPLICATION_PAGE_LIST_ITEM
));
172 pAPLI
->hIcon
= hIcon
;
173 pAPLI
->bHung
= bHung
;
174 lstrcpyW(pAPLI
->wszTitle
, wszTitle
);
176 /* Add the item to the list */
177 memset(&item
, 0, sizeof(LV_ITEMW
));
178 item
.mask
= LVIF_TEXT
|LVIF_IMAGE
|LVIF_PARAM
;
179 ImageList_AddIcon(hImageListLarge
, hIcon
);
180 item
.iImage
= ImageList_AddIcon(hImageListSmall
, hIcon
);
181 item
.pszText
= LPSTR_TEXTCALLBACKW
;
182 item
.iItem
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
183 item
.lParam
= (LPARAM
)pAPLI
;
184 SendMessageW(hApplicationPageListCtrl
, LVM_INSERTITEMW
, 0, (LPARAM
) &item
);
188 /* Check to see if we need to remove any items from the list */
189 for (i
=SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0)-1; i
>=0; i
--)
191 memset(&item
, 0, sizeof(LV_ITEMW
));
192 item
.mask
= LVIF_IMAGE
|LVIF_PARAM
;
194 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
196 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
197 if (!IsWindow(pAPLI
->hWnd
)||
198 (lstrlenW(pAPLI
->wszTitle
) <= 0) ||
199 !IsWindowVisible(pAPLI
->hWnd
) ||
200 (GetParent(pAPLI
->hWnd
) != NULL
) ||
201 (GetWindow(pAPLI
->hWnd
, GW_OWNER
) != NULL
) ||
202 (GetWindowLongW(hWnd
, GWL_EXSTYLE
) & WS_EX_TOOLWINDOW
))
204 ImageList_Remove(hImageListLarge
, item
.iItem
);
205 ImageList_Remove(hImageListSmall
, item
.iItem
);
207 SendMessageW(hApplicationPageListCtrl
, LVM_DELETEITEM
, item
.iItem
, 0);
208 HeapFree(GetProcessHeap(), 0, pAPLI
);
214 * If an item was removed from the list then
215 * we need to resync all the items with the
220 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
221 for (i
=0; i
<count
; i
++)
223 memset(&item
, 0, sizeof(LV_ITEMW
));
224 item
.mask
= LVIF_IMAGE
;
227 SendMessageW(hApplicationPageListCtrl
, LVM_SETITEMW
, 0, (LPARAM
) &item
);
231 ApplicationPageUpdate();
234 static BOOL CALLBACK
EnumWindowsProc(HWND hWnd
, LPARAM lParam
)
238 BOOL bLargeIcon
= TaskManagerSettings
.View_LargeIcons
;
240 /* Skip our window */
241 if (hWnd
== hMainWnd
)
244 /* Check and see if this is a top-level app window */
245 if (!GetWindowTextW(hWnd
, wszText
, ARRAY_SIZE(wszText
)) || !IsWindowVisible(hWnd
) ||
246 (GetParent(hWnd
) != NULL
) || (GetWindow(hWnd
, GW_OWNER
) != NULL
) ||
247 (GetWindowLongW(hWnd
, GWL_EXSTYLE
) & WS_EX_TOOLWINDOW
))
249 return TRUE
; /* Skip this window */
252 /* Get the icon for this window */
254 SendMessageTimeoutW(hWnd
, WM_GETICON
, bLargeIcon
? ICON_BIG
/*1*/ : ICON_SMALL
/*0*/, 0, 0, 1000, (PDWORD_PTR
)&hIcon
);
258 hIcon
= (HICON
)GetClassLongPtrW(hWnd
, bLargeIcon
? GCLP_HICON
: GCLP_HICONSM
);
259 if (!hIcon
) hIcon
= (HICON
)GetClassLongPtrW(hWnd
, bLargeIcon
? GCLP_HICONSM
: GCLP_HICON
);
260 if (!hIcon
) SendMessageTimeoutW(hWnd
, WM_QUERYDRAGICON
, 0, 0, 0, 1000, (PDWORD_PTR
)&hIcon
);
261 if (!hIcon
) SendMessageTimeoutW(hWnd
, WM_GETICON
, bLargeIcon
? ICON_SMALL
/*0*/ : ICON_BIG
/*1*/, 0, 0, 1000, (PDWORD_PTR
)&hIcon
);
265 hIcon
= LoadIconW(hInst
, bLargeIcon
? MAKEINTRESOURCEW(IDI_WINDOW
) : MAKEINTRESOURCEW(IDI_WINDOWSM
));
267 AddOrUpdateHwnd(hWnd
, wszText
, hIcon
, IsHungAppWindow(hWnd
));
272 static DWORD WINAPI
ApplicationPageRefreshThread(void *lpParameter
)
274 /* Create the event */
275 hApplicationPageEvent
= CreateEventW(NULL
, TRUE
, TRUE
, NULL
);
277 /* If we couldn't create the event then exit the thread */
278 if (!hApplicationPageEvent
)
285 /* Wait on the event */
286 dwWaitVal
= WaitForSingleObject(hApplicationPageEvent
, INFINITE
);
288 /* If the wait failed then the event object must have been */
289 /* closed and the task manager is exiting so exit this thread */
290 if (dwWaitVal
== WAIT_FAILED
)
293 if (dwWaitVal
== WAIT_OBJECT_0
)
295 /* Reset our event */
296 ResetEvent(hApplicationPageEvent
);
301 * Should this be EnumDesktopWindows() instead?
303 EnumWindows(EnumWindowsProc
, 0);
308 static void ApplicationPageShowContextMenu1(void)
316 hMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_APPLICATION_PAGE_CONTEXT1
));
317 hSubMenu
= GetSubMenu(hMenu
, 0);
319 if (TaskManagerSettings
.View_LargeIcons
)
320 CheckMenuRadioItem(hSubMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
321 else if (TaskManagerSettings
.View_SmallIcons
)
322 CheckMenuRadioItem(hSubMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
324 CheckMenuRadioItem(hSubMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
326 TrackPopupMenu(hSubMenu
, TPM_LEFTALIGN
|TPM_TOPALIGN
|TPM_LEFTBUTTON
, pt
.x
, pt
.y
, 0, hMainWnd
, NULL
);
331 static void ApplicationPageShowContextMenu2(void)
340 hMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_APPLICATION_PAGE_CONTEXT2
));
341 hSubMenu
= GetSubMenu(hMenu
, 0);
343 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETSELECTEDCOUNT
, 0, 0);
346 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
347 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
348 EnableMenuItem(hSubMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
349 EnableMenuItem(hSubMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
350 EnableMenuItem(hSubMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
351 EnableMenuItem(hSubMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_ENABLED
);
355 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_ENABLED
);
356 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_ENABLED
);
357 EnableMenuItem(hSubMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
358 EnableMenuItem(hSubMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
359 EnableMenuItem(hSubMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_ENABLED
);
360 EnableMenuItem(hSubMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
364 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
365 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
366 EnableMenuItem(hSubMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
367 EnableMenuItem(hSubMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
368 EnableMenuItem(hSubMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
369 EnableMenuItem(hSubMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
372 SetMenuDefaultItem(hSubMenu
, ID_APPLICATION_PAGE_SWITCHTO
, MF_BYCOMMAND
);
374 TrackPopupMenu(hSubMenu
, TPM_LEFTALIGN
|TPM_TOPALIGN
|TPM_LEFTBUTTON
, pt
.x
, pt
.y
, 0, hMainWnd
, NULL
);
379 static int CALLBACK
ApplicationPageCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
381 LPAPPLICATION_PAGE_LIST_ITEM Param1
;
382 LPAPPLICATION_PAGE_LIST_ITEM Param2
;
384 if (bSortAscending
) {
385 Param1
= (LPAPPLICATION_PAGE_LIST_ITEM
)lParam1
;
386 Param2
= (LPAPPLICATION_PAGE_LIST_ITEM
)lParam2
;
388 Param1
= (LPAPPLICATION_PAGE_LIST_ITEM
)lParam2
;
389 Param2
= (LPAPPLICATION_PAGE_LIST_ITEM
)lParam1
;
391 return lstrcmpW(Param1
->wszTitle
, Param2
->wszTitle
);
394 static void ApplicationPageOnNotify(WPARAM wParam
, LPARAM lParam
)
398 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
;
399 WCHAR wszNotResponding
[255];
400 WCHAR wszRunning
[255];
402 LoadStringW(hInst
, IDS_APPLICATION_NOT_RESPONDING
, wszNotResponding
, ARRAY_SIZE(wszNotResponding
));
403 LoadStringW(hInst
, IDS_APPLICATION_RUNNING
, wszRunning
, ARRAY_SIZE(wszRunning
));
405 pnmh
= (LPNMHDR
) lParam
;
406 pnmdi
= (LV_DISPINFOW
*) lParam
;
408 if (pnmh
->hwndFrom
== hApplicationPageListCtrl
) {
409 switch (pnmh
->code
) {
410 case LVN_ITEMCHANGED
:
411 ApplicationPageUpdate();
414 case LVN_GETDISPINFOW
:
415 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)pnmdi
->item
.lParam
;
417 /* Update the item text */
418 if (pnmdi
->item
.iSubItem
== 0)
420 lstrcpynW(pnmdi
->item
.pszText
, pAPLI
->wszTitle
, pnmdi
->item
.cchTextMax
);
423 /* Update the item status */
424 else if (pnmdi
->item
.iSubItem
== 1)
427 lstrcpynW(pnmdi
->item
.pszText
, wszNotResponding
, pnmdi
->item
.cchTextMax
);
429 lstrcpynW(pnmdi
->item
.pszText
, wszRunning
, pnmdi
->item
.cchTextMax
);
436 if (SendMessageW(hApplicationPageListCtrl
, LVM_GETSELECTEDCOUNT
, 0, 0) < 1)
438 ApplicationPageShowContextMenu1();
442 ApplicationPageShowContextMenu2();
449 ApplicationPage_OnSwitchTo();
454 else if (pnmh
->hwndFrom
== (HWND
)SendMessageW(hApplicationPageListCtrl
, LVM_GETHEADER
, 0, 0))
460 if (SendMessageW(hApplicationPageListCtrl
, LVM_GETSELECTEDCOUNT
, 0, 0) < 1)
462 ApplicationPageShowContextMenu1();
466 ApplicationPageShowContextMenu2();
473 SendMessageW(hApplicationPageListCtrl
, LVM_SORTITEMS
, 0, (LPARAM
) ApplicationPageCompareFunc
);
474 bSortAscending
= !bSortAscending
;
482 void RefreshApplicationPage(void)
484 /* Signal the event so that our refresh thread */
485 /* will wake up and refresh the application page */
486 SetEvent(hApplicationPageEvent
);
489 static void UpdateApplicationListControlViewSetting(void)
491 DWORD dwStyle
= GetWindowLongW(hApplicationPageListCtrl
, GWL_STYLE
);
493 dwStyle
&= ~LVS_REPORT
;
494 dwStyle
&= ~LVS_ICON
;
495 dwStyle
&= ~LVS_LIST
;
496 dwStyle
&= ~LVS_SMALLICON
;
498 if (TaskManagerSettings
.View_LargeIcons
)
500 else if (TaskManagerSettings
.View_SmallIcons
)
501 dwStyle
|= LVS_SMALLICON
;
503 dwStyle
|= LVS_REPORT
;
505 SetWindowLongW(hApplicationPageListCtrl
, GWL_STYLE
, dwStyle
);
507 RefreshApplicationPage();
510 void ApplicationPage_OnViewLargeIcons(void)
515 hMenu
= GetMenu(hMainWnd
);
516 hViewMenu
= GetSubMenu(hMenu
, 2);
518 TaskManagerSettings
.View_LargeIcons
= TRUE
;
519 TaskManagerSettings
.View_SmallIcons
= FALSE
;
520 TaskManagerSettings
.View_Details
= FALSE
;
521 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
523 UpdateApplicationListControlViewSetting();
526 void ApplicationPage_OnViewSmallIcons(void)
531 hMenu
= GetMenu(hMainWnd
);
532 hViewMenu
= GetSubMenu(hMenu
, 2);
534 TaskManagerSettings
.View_LargeIcons
= FALSE
;
535 TaskManagerSettings
.View_SmallIcons
= TRUE
;
536 TaskManagerSettings
.View_Details
= FALSE
;
537 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
539 UpdateApplicationListControlViewSetting();
542 void ApplicationPage_OnViewDetails(void)
547 hMenu
= GetMenu(hMainWnd
);
548 hViewMenu
= GetSubMenu(hMenu
, 2);
550 TaskManagerSettings
.View_LargeIcons
= FALSE
;
551 TaskManagerSettings
.View_SmallIcons
= FALSE
;
552 TaskManagerSettings
.View_Details
= TRUE
;
553 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
555 UpdateApplicationListControlViewSetting();
558 void ApplicationPage_OnWindowsTileHorizontally(void)
560 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
566 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
567 hWndArray
= HeapAlloc(GetProcessHeap(), 0,
568 sizeof(HWND
) * count
);
571 for (i
=0; i
<count
; i
++) {
572 memset(&item
, 0, sizeof(LV_ITEMW
));
573 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
575 item
.stateMask
= (UINT
)-1;
576 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
578 if (item
.state
& LVIS_SELECTED
) {
579 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
582 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
587 TileWindows(NULL
, MDITILE_HORIZONTAL
, NULL
, nWndCount
, hWndArray
);
588 HeapFree(GetProcessHeap(), 0, hWndArray
);
591 void ApplicationPage_OnWindowsTileVertically(void)
593 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
599 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
600 hWndArray
= HeapAlloc(GetProcessHeap(), 0,
601 sizeof(HWND
) * count
);
604 for (i
=0; i
<count
; i
++) {
605 memset(&item
, 0, sizeof(LV_ITEMW
));
606 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
608 item
.stateMask
= (UINT
)-1;
609 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
611 if (item
.state
& LVIS_SELECTED
) {
612 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
614 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
620 TileWindows(NULL
, MDITILE_VERTICAL
, NULL
, nWndCount
, hWndArray
);
621 HeapFree(GetProcessHeap(), 0, hWndArray
);
624 void ApplicationPage_OnWindowsMinimize(void)
626 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
630 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
631 for (i
=0; i
<count
; i
++) {
632 memset(&item
, 0, sizeof(LV_ITEMW
));
633 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
635 item
.stateMask
= (UINT
)-1;
636 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
637 if (item
.state
& LVIS_SELECTED
) {
638 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
640 ShowWindow(pAPLI
->hWnd
, SW_MINIMIZE
);
646 void ApplicationPage_OnWindowsMaximize(void)
648 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
652 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
653 for (i
=0; i
<count
; i
++) {
654 memset(&item
, 0, sizeof(LV_ITEMW
));
655 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
657 item
.stateMask
= (UINT
)-1;
658 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
659 if (item
.state
& LVIS_SELECTED
) {
660 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
662 ShowWindow(pAPLI
->hWnd
, SW_MAXIMIZE
);
668 void ApplicationPage_OnWindowsCascade(void)
670 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
676 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
677 hWndArray
= HeapAlloc(GetProcessHeap(), 0,
678 sizeof(HWND
) * count
);
681 for (i
=0; i
<count
; i
++) {
682 memset(&item
, 0, sizeof(LV_ITEMW
));
683 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
685 item
.stateMask
= (UINT
)-1;
686 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
687 if (item
.state
& LVIS_SELECTED
) {
688 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
690 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
695 CascadeWindows(NULL
, 0, NULL
, nWndCount
, hWndArray
);
696 HeapFree(GetProcessHeap(), 0, hWndArray
);
699 void ApplicationPage_OnWindowsBringToFront(void)
701 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
705 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
706 for (i
=0; i
<count
; i
++) {
707 memset(&item
, 0, sizeof(LV_ITEMW
));
708 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
710 item
.stateMask
= (UINT
)-1;
711 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
712 if (item
.state
& LVIS_SELECTED
) {
713 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
718 if (IsIconic(pAPLI
->hWnd
))
719 ShowWindow(pAPLI
->hWnd
, SW_RESTORE
);
720 BringWindowToTop(pAPLI
->hWnd
);
724 void ApplicationPage_OnSwitchTo(void)
726 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
730 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
731 for (i
=0; i
<count
; i
++) {
732 memset(&item
, 0, sizeof(LV_ITEMW
));
733 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
735 item
.stateMask
= (UINT
)-1;
736 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
738 if (item
.state
& LVIS_SELECTED
) {
739 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
744 SwitchToThisWindow(pAPLI
->hWnd
, TRUE
);
745 if (TaskManagerSettings
.MinimizeOnUse
)
746 ShowWindow(hMainWnd
, SW_MINIMIZE
);
750 void ApplicationPage_OnEndTask(void)
752 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
756 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
757 for (i
=0; i
<count
; i
++) {
758 memset(&item
, 0, sizeof(LV_ITEMW
));
759 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
761 item
.stateMask
= (UINT
)-1;
762 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
763 if (item
.state
& LVIS_SELECTED
) {
764 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
766 PostMessageW(pAPLI
->hWnd
, WM_CLOSE
, 0, 0);
772 void ApplicationPage_OnGotoProcess(void)
774 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
779 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
780 for (i
=0; i
<count
; i
++) {
781 memset(&item
, 0, sizeof(LV_ITEMW
));
782 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
784 item
.stateMask
= (UINT
)-1;
785 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
786 if (item
.state
& LVIS_SELECTED
) {
787 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
794 GetWindowThreadProcessId(pAPLI
->hWnd
, &dwProcessId
);
796 * Switch to the process tab
798 SendMessageW(hTabWnd
, TCM_SETCURFOCUS
, 1, 0);
800 * FIXME: Select the process item in the list
806 ApplicationPageWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
815 WCHAR wszStatus
[255];
817 LoadStringW(hInst
, IDS_APPLICATION_TASK
, wszTask
, ARRAY_SIZE(wszTask
));
818 LoadStringW(hInst
, IDS_APPLICATION_STATUS
, wszStatus
, ARRAY_SIZE(wszStatus
));
823 /* Save the width and height */
824 GetClientRect(hDlg
, &rc
);
825 nApplicationPageWidth
= rc
.right
;
826 nApplicationPageHeight
= rc
.bottom
;
828 /* Update window position */
829 SetWindowPos(hDlg
, NULL
, 15, 30, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
831 /* Get handles to the controls */
832 hApplicationPageListCtrl
= GetDlgItem(hDlg
, IDC_APPLIST
);
833 hApplicationPageEndTaskButton
= GetDlgItem(hDlg
, IDC_ENDTASK
);
834 hApplicationPageSwitchToButton
= GetDlgItem(hDlg
, IDC_SWITCHTO
);
835 hApplicationPageNewTaskButton
= GetDlgItem(hDlg
, IDC_NEWTASK
);
837 /* Initialize the application page's controls */
838 column
.mask
= LVCF_TEXT
|LVCF_WIDTH
;
839 column
.pszText
= wszTask
;
841 /* Add the "Task" column */
842 SendMessageW(hApplicationPageListCtrl
, LVM_INSERTCOLUMNW
, 0, (LPARAM
) &column
);
843 column
.mask
= LVCF_TEXT
|LVCF_WIDTH
;
844 column
.pszText
= wszStatus
;
846 /* Add the "Status" column */
847 SendMessageW(hApplicationPageListCtrl
, LVM_INSERTCOLUMNW
, 1, (LPARAM
) &column
);
849 SendMessageW(hApplicationPageListCtrl
, LVM_SETIMAGELIST
, LVSIL_SMALL
,
850 (LPARAM
) ImageList_Create(16, 16, ILC_COLOR8
|ILC_MASK
, 0, 1));
851 SendMessageW(hApplicationPageListCtrl
, LVM_SETIMAGELIST
, LVSIL_NORMAL
,
852 (LPARAM
) ImageList_Create(32, 32, ILC_COLOR8
|ILC_MASK
, 0, 1));
854 UpdateApplicationListControlViewSetting();
856 /* Start our refresh thread */
857 CloseHandle( CreateThread(NULL
, 0, ApplicationPageRefreshThread
, NULL
, 0, NULL
));
862 /* Close the event handle, this will make the */
863 /* refresh thread exit when the wait fails */
864 CloseHandle(hApplicationPageEvent
);
869 /* Handle the button clicks */
870 switch (LOWORD(wParam
))
873 ApplicationPage_OnEndTask();
876 ApplicationPage_OnSwitchTo();
879 SendMessageW(hMainWnd
, WM_COMMAND
, MAKEWPARAM(ID_FILE_NEW
, 0), 0);
886 if (wParam
== SIZE_MINIMIZED
)
891 nXDifference
= cx
- nApplicationPageWidth
;
892 nYDifference
= cy
- nApplicationPageHeight
;
893 nApplicationPageWidth
= cx
;
894 nApplicationPageHeight
= cy
;
896 /* Reposition the application page's controls */
897 GetWindowRect(hApplicationPageListCtrl
, &rc
);
898 cx
= (rc
.right
- rc
.left
) + nXDifference
;
899 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
900 SetWindowPos(hApplicationPageListCtrl
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
901 InvalidateRect(hApplicationPageListCtrl
, NULL
, TRUE
);
903 GetClientRect(hApplicationPageEndTaskButton
, &rc
);
904 MapWindowPoints(hApplicationPageEndTaskButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
905 cx
= rc
.left
+ nXDifference
;
906 cy
= rc
.top
+ nYDifference
;
907 SetWindowPos(hApplicationPageEndTaskButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
908 InvalidateRect(hApplicationPageEndTaskButton
, NULL
, TRUE
);
910 GetClientRect(hApplicationPageSwitchToButton
, &rc
);
911 MapWindowPoints(hApplicationPageSwitchToButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
912 cx
= rc
.left
+ nXDifference
;
913 cy
= rc
.top
+ nYDifference
;
914 SetWindowPos(hApplicationPageSwitchToButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
915 InvalidateRect(hApplicationPageSwitchToButton
, NULL
, TRUE
);
917 GetClientRect(hApplicationPageNewTaskButton
, &rc
);
918 MapWindowPoints(hApplicationPageNewTaskButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
919 cx
= rc
.left
+ nXDifference
;
920 cy
= rc
.top
+ nYDifference
;
921 SetWindowPos(hApplicationPageNewTaskButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
922 InvalidateRect(hApplicationPageNewTaskButton
, NULL
, TRUE
);
927 ApplicationPageOnNotify(wParam
, lParam
);