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
24 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
31 #include "wine/unicode.h"
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
;
52 static const WCHAR wszUser32
[] = {'U','S','E','R','3','2','.','D','L','L',0};
54 void SwitchToThisWindow (
55 HWND hWnd
, /* Handle to the window that should be activated */
56 BOOL bRestore
/* Restore the window if it is minimized */
60 static void ApplicationPageUpdate(void)
62 /* Enable or disable the "End Task" & "Switch To" buttons */
63 if (ListView_GetSelectedCount(hApplicationPageListCtrl
))
65 EnableWindow(hApplicationPageEndTaskButton
, TRUE
);
66 EnableWindow(hApplicationPageSwitchToButton
, TRUE
);
70 EnableWindow(hApplicationPageEndTaskButton
, FALSE
);
71 EnableWindow(hApplicationPageSwitchToButton
, FALSE
);
74 /* If we are on the applications tab, then the windows menu will */
75 /* be present on the menu bar so enable & disable the menu items */
76 if (TabCtrl_GetCurSel(hTabWnd
) == 0)
81 hMenu
= GetMenu(hMainWnd
);
82 hWindowsMenu
= GetSubMenu(hMenu
, 3);
84 /* Only one item selected */
85 if (ListView_GetSelectedCount(hApplicationPageListCtrl
) == 1)
87 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
88 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
89 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
90 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
91 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
92 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_ENABLED
);
94 /* More than one item selected */
95 else if (ListView_GetSelectedCount(hApplicationPageListCtrl
) > 1)
97 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_ENABLED
);
98 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_ENABLED
);
99 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
100 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
101 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_ENABLED
);
102 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
104 /* No items selected */
107 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
108 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
109 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
110 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
111 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
112 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
117 static void AddOrUpdateHwnd(HWND hWnd
, WCHAR
*wszTitle
, HICON hIcon
, BOOL bHung
)
119 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
120 HIMAGELIST hImageListLarge
;
121 HIMAGELIST hImageListSmall
;
124 BOOL bAlreadyInList
= FALSE
;
125 BOOL bItemRemoved
= FALSE
;
127 memset(&item
, 0, sizeof(LV_ITEMW
));
129 /* Get the image lists */
130 hImageListLarge
= ListView_GetImageList(hApplicationPageListCtrl
, LVSIL_NORMAL
);
131 hImageListSmall
= ListView_GetImageList(hApplicationPageListCtrl
, LVSIL_SMALL
);
133 /* Check to see if it's already in our list */
134 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++)
136 memset(&item
, 0, sizeof(LV_ITEMW
));
137 item
.mask
= LVIF_IMAGE
|LVIF_PARAM
;
139 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
141 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
142 if (pAPLI
->hWnd
== hWnd
)
144 bAlreadyInList
= TRUE
;
149 /* If it is already in the list then update it if necessary */
152 /* Check to see if anything needs updating */
153 if ((pAPLI
->hIcon
!= hIcon
) ||
154 (strcmpW(pAPLI
->wszTitle
, wszTitle
) != 0) ||
155 (pAPLI
->bHung
!= bHung
))
157 /* Update the structure */
158 pAPLI
->hIcon
= hIcon
;
159 pAPLI
->bHung
= bHung
;
160 strcpyW(pAPLI
->wszTitle
, wszTitle
);
162 /* Update the image list */
163 ImageList_ReplaceIcon(hImageListLarge
, item
.iItem
, hIcon
);
164 ImageList_ReplaceIcon(hImageListSmall
, item
.iItem
, hIcon
);
166 /* Update the list view */
167 SendMessageW(hApplicationPageListCtrl
, LVM_REDRAWITEMS
, 0, ListView_GetItemCount(hApplicationPageListCtrl
));
168 /* UpdateWindow(hApplicationPageListCtrl); */
169 InvalidateRect(hApplicationPageListCtrl
, NULL
, 0);
172 /* It is not already in the list so add it */
175 pAPLI
= HeapAlloc(GetProcessHeap(), 0, sizeof(APPLICATION_PAGE_LIST_ITEM
));
178 pAPLI
->hIcon
= hIcon
;
179 pAPLI
->bHung
= bHung
;
180 strcpyW(pAPLI
->wszTitle
, wszTitle
);
182 /* Add the item to the list */
183 memset(&item
, 0, sizeof(LV_ITEMW
));
184 item
.mask
= LVIF_TEXT
|LVIF_IMAGE
|LVIF_PARAM
;
185 ImageList_AddIcon(hImageListLarge
, hIcon
);
186 item
.iImage
= ImageList_AddIcon(hImageListSmall
, hIcon
);
187 item
.pszText
= LPSTR_TEXTCALLBACKW
;
188 item
.iItem
= ListView_GetItemCount(hApplicationPageListCtrl
);
189 item
.lParam
= (LPARAM
)pAPLI
;
190 SendMessageW(hApplicationPageListCtrl
, LVM_INSERTITEMW
, 0, (LPARAM
) &item
);
194 /* Check to see if we need to remove any items from the list */
195 for (i
=ListView_GetItemCount(hApplicationPageListCtrl
)-1; i
>=0; i
--)
197 memset(&item
, 0, sizeof(LV_ITEMW
));
198 item
.mask
= LVIF_IMAGE
|LVIF_PARAM
;
200 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
202 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
203 if (!IsWindow(pAPLI
->hWnd
)||
204 (strlenW(pAPLI
->wszTitle
) <= 0) ||
205 !IsWindowVisible(pAPLI
->hWnd
) ||
206 (GetParent(pAPLI
->hWnd
) != NULL
) ||
207 (GetWindow(pAPLI
->hWnd
, GW_OWNER
) != NULL
) ||
208 (GetWindowLong(hWnd
, GWL_EXSTYLE
) & WS_EX_TOOLWINDOW
))
210 ImageList_Remove(hImageListLarge
, item
.iItem
);
211 ImageList_Remove(hImageListSmall
, item
.iItem
);
213 SendMessage(hApplicationPageListCtrl
, LVM_DELETEITEM
, item
.iItem
, 0);
214 HeapFree(GetProcessHeap(), 0, pAPLI
);
220 * If an item was removed from the list then
221 * we need to resync all the items with the
226 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++)
228 memset(&item
, 0, sizeof(LV_ITEMW
));
229 item
.mask
= LVIF_IMAGE
;
232 SendMessageW(hApplicationPageListCtrl
, LVM_SETITEMW
, 0, (LPARAM
) &item
);
236 ApplicationPageUpdate();
239 static BOOL CALLBACK
EnumWindowsProc(HWND hWnd
, LPARAM lParam
)
245 typedef int (__stdcall
*IsHungAppWindowProc
)(HWND
);
246 IsHungAppWindowProc IsHungAppWindow
;
249 /* Skip our window */
250 if (hWnd
== hMainWnd
)
253 bLargeIcon
= TaskManagerSettings
.View_LargeIcons
? TRUE
: FALSE
;
255 /* Check and see if this is a top-level app window */
256 if (!GetWindowTextW(hWnd
, wszText
, sizeof(wszText
)/sizeof(WCHAR
)) ||
257 !IsWindowVisible(hWnd
) ||
258 (GetParent(hWnd
) != NULL
) ||
259 (GetWindow(hWnd
, GW_OWNER
) != NULL
) ||
260 (GetWindowLong(hWnd
, GWL_EXSTYLE
) & WS_EX_TOOLWINDOW
))
262 return TRUE
; /* Skip this window */
265 /* Get the icon for this window */
267 SendMessageTimeout(hWnd
, WM_GETICON
, bLargeIcon
? ICON_BIG
/*1*/ : ICON_SMALL
/*0*/, 0, 0, 1000, (PDWORD_PTR
)&hIcon
);
271 hIcon
= (HICON
)GetClassLongPtr(hWnd
, bLargeIcon
? GCLP_HICON
: GCLP_HICONSM
);
272 if (!hIcon
) hIcon
= (HICON
)GetClassLongPtr(hWnd
, bLargeIcon
? GCLP_HICONSM
: GCLP_HICON
);
273 if (!hIcon
) SendMessageTimeout(hWnd
, WM_QUERYDRAGICON
, 0, 0, 0, 1000, (PDWORD_PTR
)&hIcon
);
274 if (!hIcon
) SendMessageTimeout(hWnd
, WM_GETICON
, bLargeIcon
? ICON_SMALL
/*0*/ : ICON_BIG
/*1*/, 0, 0, 1000, (PDWORD_PTR
)&hIcon
);
278 hIcon
= LoadIcon(hInst
, bLargeIcon
? MAKEINTRESOURCE(IDI_WINDOW
) : MAKEINTRESOURCE(IDI_WINDOWSM
));
282 IsHungAppWindow
= (IsHungAppWindowProc
)(FARPROC
)GetProcAddress(GetModuleHandleW(wszUser32
), "IsHungAppWindow");
285 bHung
= IsHungAppWindow(hWnd
);
287 AddOrUpdateHwnd(hWnd
, wszText
, hIcon
, bHung
);
292 static DWORD WINAPI
ApplicationPageRefreshThread(void *lpParameter
)
294 /* Create the event */
295 hApplicationPageEvent
= CreateEvent(NULL
, TRUE
, TRUE
, NULL
);
297 /* If we couldn't create the event then exit the thread */
298 if (!hApplicationPageEvent
)
305 /* Wait on the event */
306 dwWaitVal
= WaitForSingleObject(hApplicationPageEvent
, INFINITE
);
308 /* If the wait failed then the event object must have been */
309 /* closed and the task manager is exiting so exit this thread */
310 if (dwWaitVal
== WAIT_FAILED
)
313 if (dwWaitVal
== WAIT_OBJECT_0
)
315 /* Reset our event */
316 ResetEvent(hApplicationPageEvent
);
321 * Should this be EnumDesktopWindows() instead?
323 EnumWindows(EnumWindowsProc
, 0);
328 static void ApplicationPageShowContextMenu1(void)
336 hMenu
= LoadMenu(hInst
, MAKEINTRESOURCE(IDR_APPLICATION_PAGE_CONTEXT1
));
337 hSubMenu
= GetSubMenu(hMenu
, 0);
339 if (TaskManagerSettings
.View_LargeIcons
)
340 CheckMenuRadioItem(hSubMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
341 else if (TaskManagerSettings
.View_SmallIcons
)
342 CheckMenuRadioItem(hSubMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
344 CheckMenuRadioItem(hSubMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
346 TrackPopupMenu(hSubMenu
, TPM_LEFTALIGN
|TPM_TOPALIGN
|TPM_LEFTBUTTON
, pt
.x
, pt
.y
, 0, hMainWnd
, NULL
);
351 static void ApplicationPageShowContextMenu2(void)
359 hMenu
= LoadMenu(hInst
, MAKEINTRESOURCE(IDR_APPLICATION_PAGE_CONTEXT2
));
360 hSubMenu
= GetSubMenu(hMenu
, 0);
362 if (ListView_GetSelectedCount(hApplicationPageListCtrl
) == 1)
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_ENABLED
);
367 EnableMenuItem(hSubMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
368 EnableMenuItem(hSubMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
369 EnableMenuItem(hSubMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_ENABLED
);
371 else if (ListView_GetSelectedCount(hApplicationPageListCtrl
) > 1)
373 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_ENABLED
);
374 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_ENABLED
);
375 EnableMenuItem(hSubMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
376 EnableMenuItem(hSubMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
377 EnableMenuItem(hSubMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_ENABLED
);
378 EnableMenuItem(hSubMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
382 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
383 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
384 EnableMenuItem(hSubMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
385 EnableMenuItem(hSubMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
386 EnableMenuItem(hSubMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
387 EnableMenuItem(hSubMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
390 SetMenuDefaultItem(hSubMenu
, ID_APPLICATION_PAGE_SWITCHTO
, MF_BYCOMMAND
);
392 TrackPopupMenu(hSubMenu
, TPM_LEFTALIGN
|TPM_TOPALIGN
|TPM_LEFTBUTTON
, pt
.x
, pt
.y
, 0, hMainWnd
, NULL
);
397 static int CALLBACK
ApplicationPageCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
399 LPAPPLICATION_PAGE_LIST_ITEM Param1
;
400 LPAPPLICATION_PAGE_LIST_ITEM Param2
;
402 if (bSortAscending
) {
403 Param1
= (LPAPPLICATION_PAGE_LIST_ITEM
)lParam1
;
404 Param2
= (LPAPPLICATION_PAGE_LIST_ITEM
)lParam2
;
406 Param1
= (LPAPPLICATION_PAGE_LIST_ITEM
)lParam2
;
407 Param2
= (LPAPPLICATION_PAGE_LIST_ITEM
)lParam1
;
409 return strcmpW(Param1
->wszTitle
, Param2
->wszTitle
);
412 static void ApplicationPageOnNotify(WPARAM wParam
, LPARAM lParam
)
418 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
;
420 WCHAR wszNotResponding
[255];
421 WCHAR wszRunning
[255];
423 LoadStringW(hInst
, IDS_APPLICATION_NOT_RESPONDING
, wszNotResponding
, sizeof(wszNotResponding
)/sizeof(WCHAR
));
424 LoadStringW(hInst
, IDS_APPLICATION_RUNNING
, wszRunning
, sizeof(wszRunning
)/sizeof(WCHAR
));
426 idctrl
= (int) wParam
;
427 pnmh
= (LPNMHDR
) lParam
;
428 pnmv
= (LPNM_LISTVIEW
) lParam
;
429 pnmdi
= (LV_DISPINFOW
*) lParam
;
431 if (pnmh
->hwndFrom
== hApplicationPageListCtrl
) {
432 switch (pnmh
->code
) {
433 case LVN_ITEMCHANGED
:
434 ApplicationPageUpdate();
437 case LVN_GETDISPINFOW
:
438 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)pnmdi
->item
.lParam
;
440 /* Update the item text */
441 if (pnmdi
->item
.iSubItem
== 0)
443 lstrcpynW(pnmdi
->item
.pszText
, pAPLI
->wszTitle
, pnmdi
->item
.cchTextMax
);
446 /* Update the item status */
447 else if (pnmdi
->item
.iSubItem
== 1)
450 lstrcpynW(pnmdi
->item
.pszText
, wszNotResponding
, pnmdi
->item
.cchTextMax
);
452 lstrcpynW(pnmdi
->item
.pszText
, wszRunning
, pnmdi
->item
.cchTextMax
);
459 if (ListView_GetSelectedCount(hApplicationPageListCtrl
) < 1)
461 ApplicationPageShowContextMenu1();
465 ApplicationPageShowContextMenu2();
472 ApplicationPage_OnSwitchTo();
477 else if (pnmh
->hwndFrom
== ListView_GetHeader(hApplicationPageListCtrl
))
483 if (ListView_GetSelectedCount(hApplicationPageListCtrl
) < 1)
485 ApplicationPageShowContextMenu1();
489 ApplicationPageShowContextMenu2();
496 SendMessageW(hApplicationPageListCtrl
, LVM_SORTITEMS
, 0, (LPARAM
) ApplicationPageCompareFunc
);
497 bSortAscending
= !bSortAscending
;
505 void RefreshApplicationPage(void)
507 /* Signal the event so that our refresh thread */
508 /* will wake up and refresh the application page */
509 SetEvent(hApplicationPageEvent
);
512 static void UpdateApplicationListControlViewSetting(void)
514 DWORD dwStyle
= GetWindowLong(hApplicationPageListCtrl
, GWL_STYLE
);
516 dwStyle
&= ~LVS_REPORT
;
517 dwStyle
&= ~LVS_ICON
;
518 dwStyle
&= ~LVS_LIST
;
519 dwStyle
&= ~LVS_SMALLICON
;
521 if (TaskManagerSettings
.View_LargeIcons
)
523 else if (TaskManagerSettings
.View_SmallIcons
)
524 dwStyle
|= LVS_SMALLICON
;
526 dwStyle
|= LVS_REPORT
;
528 SetWindowLong(hApplicationPageListCtrl
, GWL_STYLE
, dwStyle
);
530 RefreshApplicationPage();
533 void ApplicationPage_OnViewLargeIcons(void)
538 hMenu
= GetMenu(hMainWnd
);
539 hViewMenu
= GetSubMenu(hMenu
, 2);
541 TaskManagerSettings
.View_LargeIcons
= TRUE
;
542 TaskManagerSettings
.View_SmallIcons
= FALSE
;
543 TaskManagerSettings
.View_Details
= FALSE
;
544 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
546 UpdateApplicationListControlViewSetting();
549 void ApplicationPage_OnViewSmallIcons(void)
554 hMenu
= GetMenu(hMainWnd
);
555 hViewMenu
= GetSubMenu(hMenu
, 2);
557 TaskManagerSettings
.View_LargeIcons
= FALSE
;
558 TaskManagerSettings
.View_SmallIcons
= TRUE
;
559 TaskManagerSettings
.View_Details
= FALSE
;
560 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
562 UpdateApplicationListControlViewSetting();
565 void ApplicationPage_OnViewDetails(void)
570 hMenu
= GetMenu(hMainWnd
);
571 hViewMenu
= GetSubMenu(hMenu
, 2);
573 TaskManagerSettings
.View_LargeIcons
= FALSE
;
574 TaskManagerSettings
.View_SmallIcons
= FALSE
;
575 TaskManagerSettings
.View_Details
= TRUE
;
576 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
578 UpdateApplicationListControlViewSetting();
581 void ApplicationPage_OnWindowsTileHorizontally(void)
583 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
589 hWndArray
= HeapAlloc(GetProcessHeap(), 0,
590 sizeof(HWND
) * ListView_GetItemCount(hApplicationPageListCtrl
));
593 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
594 memset(&item
, 0, sizeof(LV_ITEMW
));
595 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
597 item
.stateMask
= (UINT
)-1;
598 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
600 if (item
.state
& LVIS_SELECTED
) {
601 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
604 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
609 TileWindows(NULL
, MDITILE_HORIZONTAL
, NULL
, nWndCount
, hWndArray
);
610 HeapFree(GetProcessHeap(), 0, hWndArray
);
613 void ApplicationPage_OnWindowsTileVertically(void)
615 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
621 hWndArray
= HeapAlloc(GetProcessHeap(), 0,
622 sizeof(HWND
) * ListView_GetItemCount(hApplicationPageListCtrl
));
625 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
626 memset(&item
, 0, sizeof(LV_ITEMW
));
627 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
629 item
.stateMask
= (UINT
)-1;
630 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
632 if (item
.state
& LVIS_SELECTED
) {
633 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
635 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
641 TileWindows(NULL
, MDITILE_VERTICAL
, NULL
, nWndCount
, hWndArray
);
642 HeapFree(GetProcessHeap(), 0, hWndArray
);
645 void ApplicationPage_OnWindowsMinimize(void)
647 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
651 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
652 memset(&item
, 0, sizeof(LV_ITEMW
));
653 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
655 item
.stateMask
= (UINT
)-1;
656 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
657 if (item
.state
& LVIS_SELECTED
) {
658 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
660 ShowWindow(pAPLI
->hWnd
, SW_MINIMIZE
);
666 void ApplicationPage_OnWindowsMaximize(void)
668 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
672 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
673 memset(&item
, 0, sizeof(LV_ITEMW
));
674 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
676 item
.stateMask
= (UINT
)-1;
677 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
678 if (item
.state
& LVIS_SELECTED
) {
679 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
681 ShowWindow(pAPLI
->hWnd
, SW_MAXIMIZE
);
687 void ApplicationPage_OnWindowsCascade(void)
689 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
695 hWndArray
= HeapAlloc(GetProcessHeap(), 0,
696 sizeof(HWND
) * ListView_GetItemCount(hApplicationPageListCtrl
));
699 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
700 memset(&item
, 0, sizeof(LV_ITEMW
));
701 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
703 item
.stateMask
= (UINT
)-1;
704 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
705 if (item
.state
& LVIS_SELECTED
) {
706 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
708 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
713 CascadeWindows(NULL
, 0, NULL
, nWndCount
, hWndArray
);
714 HeapFree(GetProcessHeap(), 0, hWndArray
);
717 void ApplicationPage_OnWindowsBringToFront(void)
719 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
723 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
724 memset(&item
, 0, sizeof(LV_ITEMW
));
725 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
727 item
.stateMask
= (UINT
)-1;
728 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
729 if (item
.state
& LVIS_SELECTED
) {
730 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
735 if (IsIconic(pAPLI
->hWnd
))
736 ShowWindow(pAPLI
->hWnd
, SW_RESTORE
);
737 BringWindowToTop(pAPLI
->hWnd
);
741 void ApplicationPage_OnSwitchTo(void)
743 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
747 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
748 memset(&item
, 0, sizeof(LV_ITEMW
));
749 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
751 item
.stateMask
= (UINT
)-1;
752 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
754 if (item
.state
& LVIS_SELECTED
) {
755 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
760 typedef void (WINAPI
*PROCSWITCHTOTHISWINDOW
) (HWND
, BOOL
);
761 PROCSWITCHTOTHISWINDOW SwitchToThisWindow
;
763 HMODULE hUser32
= GetModuleHandleW(wszUser32
);
764 SwitchToThisWindow
= (PROCSWITCHTOTHISWINDOW
)GetProcAddress(hUser32
, "SwitchToThisWindow");
765 if (SwitchToThisWindow
) {
766 SwitchToThisWindow(pAPLI
->hWnd
, TRUE
);
768 if (IsIconic(pAPLI
->hWnd
))
769 ShowWindow(pAPLI
->hWnd
, SW_RESTORE
);
770 BringWindowToTop(pAPLI
->hWnd
);
771 SetForegroundWindow(pAPLI
->hWnd
);
773 if (TaskManagerSettings
.MinimizeOnUse
)
774 ShowWindow(hMainWnd
, SW_MINIMIZE
);
778 void ApplicationPage_OnEndTask(void)
780 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
784 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
785 memset(&item
, 0, sizeof(LV_ITEMW
));
786 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
788 item
.stateMask
= (UINT
)-1;
789 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
790 if (item
.state
& LVIS_SELECTED
) {
791 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
793 PostMessage(pAPLI
->hWnd
, WM_CLOSE
, 0, 0);
799 void ApplicationPage_OnGotoProcess(void)
801 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
806 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
807 memset(&item
, 0, sizeof(LV_ITEMW
));
808 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
810 item
.stateMask
= (UINT
)-1;
811 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
812 if (item
.state
& LVIS_SELECTED
) {
813 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
820 GetWindowThreadProcessId(pAPLI
->hWnd
, &dwProcessId
);
822 * Switch to the process tab
824 TabCtrl_SetCurFocus(hTabWnd
, 1);
826 * FIXME: Select the process item in the list
828 for (i
=0; i
<ListView_GetItemCount(hProcessPage
); i
++) {
834 ApplicationPageWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
843 WCHAR wszStatus
[255];
845 LoadStringW(hInst
, IDS_APPLICATION_TASK
, wszTask
, sizeof(wszTask
)/sizeof(WCHAR
));
846 LoadStringW(hInst
, IDS_APPLICATION_STATUS
, wszStatus
, sizeof(wszStatus
)/sizeof(WCHAR
));
851 /* Save the width and height */
852 GetClientRect(hDlg
, &rc
);
853 nApplicationPageWidth
= rc
.right
;
854 nApplicationPageHeight
= rc
.bottom
;
856 /* Update window position */
857 SetWindowPos(hDlg
, NULL
, 15, 30, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
859 /* Get handles to the controls */
860 hApplicationPageListCtrl
= GetDlgItem(hDlg
, IDC_APPLIST
);
861 hApplicationPageEndTaskButton
= GetDlgItem(hDlg
, IDC_ENDTASK
);
862 hApplicationPageSwitchToButton
= GetDlgItem(hDlg
, IDC_SWITCHTO
);
863 hApplicationPageNewTaskButton
= GetDlgItem(hDlg
, IDC_NEWTASK
);
865 /* Initialize the application page's controls */
866 column
.mask
= LVCF_TEXT
|LVCF_WIDTH
;
867 column
.pszText
= wszTask
;
869 /* Add the "Task" column */
870 SendMessageW(hApplicationPageListCtrl
, LVM_INSERTCOLUMNW
, 0, (LPARAM
) &column
);
871 column
.mask
= LVCF_TEXT
|LVCF_WIDTH
;
872 column
.pszText
= wszStatus
;
874 /* Add the "Status" column */
875 SendMessageW(hApplicationPageListCtrl
, LVM_INSERTCOLUMNW
, 1, (LPARAM
) &column
);
877 SendMessageW(hApplicationPageListCtrl
, LVM_SETIMAGELIST
, LVSIL_SMALL
,
878 (LPARAM
) ImageList_Create(16, 16, ILC_COLOR8
|ILC_MASK
, 0, 1));
879 SendMessageW(hApplicationPageListCtrl
, LVM_SETIMAGELIST
, LVSIL_NORMAL
,
880 (LPARAM
) ImageList_Create(32, 32, ILC_COLOR8
|ILC_MASK
, 0, 1));
882 UpdateApplicationListControlViewSetting();
884 /* Start our refresh thread */
885 CreateThread(NULL
, 0, ApplicationPageRefreshThread
, NULL
, 0, NULL
);
890 /* Close the event handle, this will make the */
891 /* refresh thread exit when the wait fails */
892 CloseHandle(hApplicationPageEvent
);
897 /* Handle the button clicks */
898 switch (LOWORD(wParam
))
901 ApplicationPage_OnEndTask();
904 ApplicationPage_OnSwitchTo();
907 SendMessageW(hMainWnd
, WM_COMMAND
, MAKEWPARAM(ID_FILE_NEW
, 0), 0);
914 if (wParam
== SIZE_MINIMIZED
)
919 nXDifference
= cx
- nApplicationPageWidth
;
920 nYDifference
= cy
- nApplicationPageHeight
;
921 nApplicationPageWidth
= cx
;
922 nApplicationPageHeight
= cy
;
924 /* Reposition the application page's controls */
925 GetWindowRect(hApplicationPageListCtrl
, &rc
);
926 cx
= (rc
.right
- rc
.left
) + nXDifference
;
927 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
928 SetWindowPos(hApplicationPageListCtrl
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
929 InvalidateRect(hApplicationPageListCtrl
, NULL
, TRUE
);
931 GetClientRect(hApplicationPageEndTaskButton
, &rc
);
932 MapWindowPoints(hApplicationPageEndTaskButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
933 cx
= rc
.left
+ nXDifference
;
934 cy
= rc
.top
+ nYDifference
;
935 SetWindowPos(hApplicationPageEndTaskButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
936 InvalidateRect(hApplicationPageEndTaskButton
, NULL
, TRUE
);
938 GetClientRect(hApplicationPageSwitchToButton
, &rc
);
939 MapWindowPoints(hApplicationPageSwitchToButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
940 cx
= rc
.left
+ nXDifference
;
941 cy
= rc
.top
+ nYDifference
;
942 SetWindowPos(hApplicationPageSwitchToButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
943 InvalidateRect(hApplicationPageSwitchToButton
, NULL
, TRUE
);
945 GetClientRect(hApplicationPageNewTaskButton
, &rc
);
946 MapWindowPoints(hApplicationPageNewTaskButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
947 cx
= rc
.left
+ nXDifference
;
948 cy
= rc
.top
+ nYDifference
;
949 SetWindowPos(hApplicationPageNewTaskButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
950 InvalidateRect(hApplicationPageNewTaskButton
, NULL
, TRUE
);
955 ApplicationPageOnNotify(wParam
, lParam
);