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 (SendMessageW(hApplicationPageListCtrl
, LVM_GETSELECTEDCOUNT
, 0, 0))
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 (SendMessageW(hTabWnd
, TCM_GETCURSEL
, 0, 0) == 0)
82 hMenu
= GetMenu(hMainWnd
);
83 hWindowsMenu
= GetSubMenu(hMenu
, 3);
84 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETSELECTEDCOUNT
, 0, 0);
86 /* Only one item selected */
89 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
90 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
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_DISABLED
|MF_GRAYED
);
94 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_ENABLED
);
96 /* More than one item selected */
99 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_ENABLED
);
100 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_ENABLED
);
101 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
102 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
103 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_ENABLED
);
104 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
106 /* No items selected */
109 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
110 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
111 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
112 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
113 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
114 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
119 static void AddOrUpdateHwnd(HWND hWnd
, WCHAR
*wszTitle
, HICON hIcon
, BOOL bHung
)
121 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
122 HIMAGELIST hImageListLarge
;
123 HIMAGELIST hImageListSmall
;
126 BOOL bAlreadyInList
= FALSE
;
127 BOOL bItemRemoved
= FALSE
;
129 memset(&item
, 0, sizeof(LV_ITEMW
));
131 /* Get the image lists */
132 hImageListLarge
= (HIMAGELIST
)SendMessageW(hApplicationPageListCtrl
, LVM_GETIMAGELIST
, LVSIL_NORMAL
, 0);
133 hImageListSmall
= (HIMAGELIST
)SendMessageW(hApplicationPageListCtrl
, LVM_GETIMAGELIST
, LVSIL_SMALL
, 0);
135 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
136 /* Check to see if it's already in our list */
137 for (i
=0; i
<count
; i
++)
139 memset(&item
, 0, sizeof(LV_ITEMW
));
140 item
.mask
= LVIF_IMAGE
|LVIF_PARAM
;
142 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
144 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
145 if (pAPLI
->hWnd
== hWnd
)
147 bAlreadyInList
= TRUE
;
152 /* If it is already in the list then update it if necessary */
155 /* Check to see if anything needs updating */
156 if ((pAPLI
->hIcon
!= hIcon
) ||
157 (strcmpW(pAPLI
->wszTitle
, wszTitle
) != 0) ||
158 (pAPLI
->bHung
!= bHung
))
160 /* Update the structure */
161 pAPLI
->hIcon
= hIcon
;
162 pAPLI
->bHung
= bHung
;
163 strcpyW(pAPLI
->wszTitle
, wszTitle
);
165 /* Update the image list */
166 ImageList_ReplaceIcon(hImageListLarge
, item
.iItem
, hIcon
);
167 ImageList_ReplaceIcon(hImageListSmall
, item
.iItem
, hIcon
);
169 /* Update the list view */
170 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
171 SendMessageW(hApplicationPageListCtrl
, LVM_REDRAWITEMS
, 0, count
);
172 /* UpdateWindow(hApplicationPageListCtrl); */
173 InvalidateRect(hApplicationPageListCtrl
, NULL
, 0);
176 /* It is not already in the list so add it */
179 pAPLI
= HeapAlloc(GetProcessHeap(), 0, sizeof(APPLICATION_PAGE_LIST_ITEM
));
182 pAPLI
->hIcon
= hIcon
;
183 pAPLI
->bHung
= bHung
;
184 strcpyW(pAPLI
->wszTitle
, wszTitle
);
186 /* Add the item to the list */
187 memset(&item
, 0, sizeof(LV_ITEMW
));
188 item
.mask
= LVIF_TEXT
|LVIF_IMAGE
|LVIF_PARAM
;
189 ImageList_AddIcon(hImageListLarge
, hIcon
);
190 item
.iImage
= ImageList_AddIcon(hImageListSmall
, hIcon
);
191 item
.pszText
= LPSTR_TEXTCALLBACKW
;
192 item
.iItem
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
193 item
.lParam
= (LPARAM
)pAPLI
;
194 SendMessageW(hApplicationPageListCtrl
, LVM_INSERTITEMW
, 0, (LPARAM
) &item
);
198 /* Check to see if we need to remove any items from the list */
199 for (i
=SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0)-1; i
>=0; i
--)
201 memset(&item
, 0, sizeof(LV_ITEMW
));
202 item
.mask
= LVIF_IMAGE
|LVIF_PARAM
;
204 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
206 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
207 if (!IsWindow(pAPLI
->hWnd
)||
208 (strlenW(pAPLI
->wszTitle
) <= 0) ||
209 !IsWindowVisible(pAPLI
->hWnd
) ||
210 (GetParent(pAPLI
->hWnd
) != NULL
) ||
211 (GetWindow(pAPLI
->hWnd
, GW_OWNER
) != NULL
) ||
212 (GetWindowLongW(hWnd
, GWL_EXSTYLE
) & WS_EX_TOOLWINDOW
))
214 ImageList_Remove(hImageListLarge
, item
.iItem
);
215 ImageList_Remove(hImageListSmall
, item
.iItem
);
217 SendMessageW(hApplicationPageListCtrl
, LVM_DELETEITEM
, item
.iItem
, 0);
218 HeapFree(GetProcessHeap(), 0, pAPLI
);
224 * If an item was removed from the list then
225 * we need to resync all the items with the
230 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
231 for (i
=0; i
<count
; i
++)
233 memset(&item
, 0, sizeof(LV_ITEMW
));
234 item
.mask
= LVIF_IMAGE
;
237 SendMessageW(hApplicationPageListCtrl
, LVM_SETITEMW
, 0, (LPARAM
) &item
);
241 ApplicationPageUpdate();
244 static BOOL CALLBACK
EnumWindowsProc(HWND hWnd
, LPARAM lParam
)
250 typedef int (__stdcall
*IsHungAppWindowProc
)(HWND
);
251 IsHungAppWindowProc IsHungAppWindow
;
254 /* Skip our window */
255 if (hWnd
== hMainWnd
)
258 bLargeIcon
= TaskManagerSettings
.View_LargeIcons
? TRUE
: FALSE
;
260 /* Check and see if this is a top-level app window */
261 if (!GetWindowTextW(hWnd
, wszText
, sizeof(wszText
)/sizeof(WCHAR
)) ||
262 !IsWindowVisible(hWnd
) ||
263 (GetParent(hWnd
) != NULL
) ||
264 (GetWindow(hWnd
, GW_OWNER
) != NULL
) ||
265 (GetWindowLongW(hWnd
, GWL_EXSTYLE
) & WS_EX_TOOLWINDOW
))
267 return TRUE
; /* Skip this window */
270 /* Get the icon for this window */
272 SendMessageTimeoutW(hWnd
, WM_GETICON
, bLargeIcon
? ICON_BIG
/*1*/ : ICON_SMALL
/*0*/, 0, 0, 1000, (PDWORD_PTR
)&hIcon
);
276 hIcon
= (HICON
)GetClassLongPtrW(hWnd
, bLargeIcon
? GCLP_HICON
: GCLP_HICONSM
);
277 if (!hIcon
) hIcon
= (HICON
)GetClassLongPtrW(hWnd
, bLargeIcon
? GCLP_HICONSM
: GCLP_HICON
);
278 if (!hIcon
) SendMessageTimeoutW(hWnd
, WM_QUERYDRAGICON
, 0, 0, 0, 1000, (PDWORD_PTR
)&hIcon
);
279 if (!hIcon
) SendMessageTimeoutW(hWnd
, WM_GETICON
, bLargeIcon
? ICON_SMALL
/*0*/ : ICON_BIG
/*1*/, 0, 0, 1000, (PDWORD_PTR
)&hIcon
);
283 hIcon
= LoadIconW(hInst
, bLargeIcon
? MAKEINTRESOURCEW(IDI_WINDOW
) : MAKEINTRESOURCEW(IDI_WINDOWSM
));
287 IsHungAppWindow
= (IsHungAppWindowProc
)(FARPROC
)GetProcAddress(GetModuleHandleW(wszUser32
), "IsHungAppWindow");
290 bHung
= IsHungAppWindow(hWnd
);
292 AddOrUpdateHwnd(hWnd
, wszText
, hIcon
, bHung
);
297 static DWORD WINAPI
ApplicationPageRefreshThread(void *lpParameter
)
299 /* Create the event */
300 hApplicationPageEvent
= CreateEventW(NULL
, TRUE
, TRUE
, NULL
);
302 /* If we couldn't create the event then exit the thread */
303 if (!hApplicationPageEvent
)
310 /* Wait on the event */
311 dwWaitVal
= WaitForSingleObject(hApplicationPageEvent
, INFINITE
);
313 /* If the wait failed then the event object must have been */
314 /* closed and the task manager is exiting so exit this thread */
315 if (dwWaitVal
== WAIT_FAILED
)
318 if (dwWaitVal
== WAIT_OBJECT_0
)
320 /* Reset our event */
321 ResetEvent(hApplicationPageEvent
);
326 * Should this be EnumDesktopWindows() instead?
328 EnumWindows(EnumWindowsProc
, 0);
333 static void ApplicationPageShowContextMenu1(void)
341 hMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_APPLICATION_PAGE_CONTEXT1
));
342 hSubMenu
= GetSubMenu(hMenu
, 0);
344 if (TaskManagerSettings
.View_LargeIcons
)
345 CheckMenuRadioItem(hSubMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
346 else if (TaskManagerSettings
.View_SmallIcons
)
347 CheckMenuRadioItem(hSubMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
349 CheckMenuRadioItem(hSubMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
351 TrackPopupMenu(hSubMenu
, TPM_LEFTALIGN
|TPM_TOPALIGN
|TPM_LEFTBUTTON
, pt
.x
, pt
.y
, 0, hMainWnd
, NULL
);
356 static void ApplicationPageShowContextMenu2(void)
365 hMenu
= LoadMenuW(hInst
, MAKEINTRESOURCEW(IDR_APPLICATION_PAGE_CONTEXT2
));
366 hSubMenu
= GetSubMenu(hMenu
, 0);
368 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETSELECTEDCOUNT
, 0, 0);
371 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
372 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
373 EnableMenuItem(hSubMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
374 EnableMenuItem(hSubMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
375 EnableMenuItem(hSubMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
376 EnableMenuItem(hSubMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_ENABLED
);
380 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_ENABLED
);
381 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_ENABLED
);
382 EnableMenuItem(hSubMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
383 EnableMenuItem(hSubMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
384 EnableMenuItem(hSubMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_ENABLED
);
385 EnableMenuItem(hSubMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
389 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
390 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
391 EnableMenuItem(hSubMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
392 EnableMenuItem(hSubMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
393 EnableMenuItem(hSubMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
394 EnableMenuItem(hSubMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
397 SetMenuDefaultItem(hSubMenu
, ID_APPLICATION_PAGE_SWITCHTO
, MF_BYCOMMAND
);
399 TrackPopupMenu(hSubMenu
, TPM_LEFTALIGN
|TPM_TOPALIGN
|TPM_LEFTBUTTON
, pt
.x
, pt
.y
, 0, hMainWnd
, NULL
);
404 static int CALLBACK
ApplicationPageCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
406 LPAPPLICATION_PAGE_LIST_ITEM Param1
;
407 LPAPPLICATION_PAGE_LIST_ITEM Param2
;
409 if (bSortAscending
) {
410 Param1
= (LPAPPLICATION_PAGE_LIST_ITEM
)lParam1
;
411 Param2
= (LPAPPLICATION_PAGE_LIST_ITEM
)lParam2
;
413 Param1
= (LPAPPLICATION_PAGE_LIST_ITEM
)lParam2
;
414 Param2
= (LPAPPLICATION_PAGE_LIST_ITEM
)lParam1
;
416 return strcmpW(Param1
->wszTitle
, Param2
->wszTitle
);
419 static void ApplicationPageOnNotify(WPARAM wParam
, LPARAM lParam
)
423 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
;
424 WCHAR wszNotResponding
[255];
425 WCHAR wszRunning
[255];
427 LoadStringW(hInst
, IDS_APPLICATION_NOT_RESPONDING
, wszNotResponding
, sizeof(wszNotResponding
)/sizeof(WCHAR
));
428 LoadStringW(hInst
, IDS_APPLICATION_RUNNING
, wszRunning
, sizeof(wszRunning
)/sizeof(WCHAR
));
430 pnmh
= (LPNMHDR
) lParam
;
431 pnmdi
= (LV_DISPINFOW
*) lParam
;
433 if (pnmh
->hwndFrom
== hApplicationPageListCtrl
) {
434 switch (pnmh
->code
) {
435 case LVN_ITEMCHANGED
:
436 ApplicationPageUpdate();
439 case LVN_GETDISPINFOW
:
440 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)pnmdi
->item
.lParam
;
442 /* Update the item text */
443 if (pnmdi
->item
.iSubItem
== 0)
445 lstrcpynW(pnmdi
->item
.pszText
, pAPLI
->wszTitle
, pnmdi
->item
.cchTextMax
);
448 /* Update the item status */
449 else if (pnmdi
->item
.iSubItem
== 1)
452 lstrcpynW(pnmdi
->item
.pszText
, wszNotResponding
, pnmdi
->item
.cchTextMax
);
454 lstrcpynW(pnmdi
->item
.pszText
, wszRunning
, pnmdi
->item
.cchTextMax
);
461 if (SendMessageW(hApplicationPageListCtrl
, LVM_GETSELECTEDCOUNT
, 0, 0) < 1)
463 ApplicationPageShowContextMenu1();
467 ApplicationPageShowContextMenu2();
474 ApplicationPage_OnSwitchTo();
479 else if (pnmh
->hwndFrom
== (HWND
)SendMessageW(hApplicationPageListCtrl
, LVM_GETHEADER
, 0, 0))
485 if (SendMessageW(hApplicationPageListCtrl
, LVM_GETSELECTEDCOUNT
, 0, 0) < 1)
487 ApplicationPageShowContextMenu1();
491 ApplicationPageShowContextMenu2();
498 SendMessageW(hApplicationPageListCtrl
, LVM_SORTITEMS
, 0, (LPARAM
) ApplicationPageCompareFunc
);
499 bSortAscending
= !bSortAscending
;
507 void RefreshApplicationPage(void)
509 /* Signal the event so that our refresh thread */
510 /* will wake up and refresh the application page */
511 SetEvent(hApplicationPageEvent
);
514 static void UpdateApplicationListControlViewSetting(void)
516 DWORD dwStyle
= GetWindowLongW(hApplicationPageListCtrl
, GWL_STYLE
);
518 dwStyle
&= ~LVS_REPORT
;
519 dwStyle
&= ~LVS_ICON
;
520 dwStyle
&= ~LVS_LIST
;
521 dwStyle
&= ~LVS_SMALLICON
;
523 if (TaskManagerSettings
.View_LargeIcons
)
525 else if (TaskManagerSettings
.View_SmallIcons
)
526 dwStyle
|= LVS_SMALLICON
;
528 dwStyle
|= LVS_REPORT
;
530 SetWindowLongW(hApplicationPageListCtrl
, GWL_STYLE
, dwStyle
);
532 RefreshApplicationPage();
535 void ApplicationPage_OnViewLargeIcons(void)
540 hMenu
= GetMenu(hMainWnd
);
541 hViewMenu
= GetSubMenu(hMenu
, 2);
543 TaskManagerSettings
.View_LargeIcons
= TRUE
;
544 TaskManagerSettings
.View_SmallIcons
= FALSE
;
545 TaskManagerSettings
.View_Details
= FALSE
;
546 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
548 UpdateApplicationListControlViewSetting();
551 void ApplicationPage_OnViewSmallIcons(void)
556 hMenu
= GetMenu(hMainWnd
);
557 hViewMenu
= GetSubMenu(hMenu
, 2);
559 TaskManagerSettings
.View_LargeIcons
= FALSE
;
560 TaskManagerSettings
.View_SmallIcons
= TRUE
;
561 TaskManagerSettings
.View_Details
= FALSE
;
562 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
564 UpdateApplicationListControlViewSetting();
567 void ApplicationPage_OnViewDetails(void)
572 hMenu
= GetMenu(hMainWnd
);
573 hViewMenu
= GetSubMenu(hMenu
, 2);
575 TaskManagerSettings
.View_LargeIcons
= FALSE
;
576 TaskManagerSettings
.View_SmallIcons
= FALSE
;
577 TaskManagerSettings
.View_Details
= TRUE
;
578 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
580 UpdateApplicationListControlViewSetting();
583 void ApplicationPage_OnWindowsTileHorizontally(void)
585 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
591 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
592 hWndArray
= HeapAlloc(GetProcessHeap(), 0,
593 sizeof(HWND
) * count
);
596 for (i
=0; i
<count
; i
++) {
597 memset(&item
, 0, sizeof(LV_ITEMW
));
598 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
600 item
.stateMask
= (UINT
)-1;
601 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
603 if (item
.state
& LVIS_SELECTED
) {
604 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
607 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
612 TileWindows(NULL
, MDITILE_HORIZONTAL
, NULL
, nWndCount
, hWndArray
);
613 HeapFree(GetProcessHeap(), 0, hWndArray
);
616 void ApplicationPage_OnWindowsTileVertically(void)
618 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
624 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
625 hWndArray
= HeapAlloc(GetProcessHeap(), 0,
626 sizeof(HWND
) * count
);
629 for (i
=0; i
<count
; i
++) {
630 memset(&item
, 0, sizeof(LV_ITEMW
));
631 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
633 item
.stateMask
= (UINT
)-1;
634 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
636 if (item
.state
& LVIS_SELECTED
) {
637 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
639 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
645 TileWindows(NULL
, MDITILE_VERTICAL
, NULL
, nWndCount
, hWndArray
);
646 HeapFree(GetProcessHeap(), 0, hWndArray
);
649 void ApplicationPage_OnWindowsMinimize(void)
651 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
655 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
656 for (i
=0; i
<count
; i
++) {
657 memset(&item
, 0, sizeof(LV_ITEMW
));
658 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
660 item
.stateMask
= (UINT
)-1;
661 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
662 if (item
.state
& LVIS_SELECTED
) {
663 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
665 ShowWindow(pAPLI
->hWnd
, SW_MINIMIZE
);
671 void ApplicationPage_OnWindowsMaximize(void)
673 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
677 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
678 for (i
=0; i
<count
; i
++) {
679 memset(&item
, 0, sizeof(LV_ITEMW
));
680 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
682 item
.stateMask
= (UINT
)-1;
683 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
684 if (item
.state
& LVIS_SELECTED
) {
685 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
687 ShowWindow(pAPLI
->hWnd
, SW_MAXIMIZE
);
693 void ApplicationPage_OnWindowsCascade(void)
695 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
701 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
702 hWndArray
= HeapAlloc(GetProcessHeap(), 0,
703 sizeof(HWND
) * count
);
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
;
715 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
720 CascadeWindows(NULL
, 0, NULL
, nWndCount
, hWndArray
);
721 HeapFree(GetProcessHeap(), 0, hWndArray
);
724 void ApplicationPage_OnWindowsBringToFront(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
);
737 if (item
.state
& LVIS_SELECTED
) {
738 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
743 if (IsIconic(pAPLI
->hWnd
))
744 ShowWindow(pAPLI
->hWnd
, SW_RESTORE
);
745 BringWindowToTop(pAPLI
->hWnd
);
749 void ApplicationPage_OnSwitchTo(void)
751 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
755 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
756 for (i
=0; i
<count
; i
++) {
757 memset(&item
, 0, sizeof(LV_ITEMW
));
758 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
760 item
.stateMask
= (UINT
)-1;
761 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
763 if (item
.state
& LVIS_SELECTED
) {
764 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
769 typedef void (WINAPI
*PROCSWITCHTOTHISWINDOW
) (HWND
, BOOL
);
770 PROCSWITCHTOTHISWINDOW SwitchToThisWindow
;
772 HMODULE hUser32
= GetModuleHandleW(wszUser32
);
773 SwitchToThisWindow
= (PROCSWITCHTOTHISWINDOW
)GetProcAddress(hUser32
, "SwitchToThisWindow");
774 if (SwitchToThisWindow
) {
775 SwitchToThisWindow(pAPLI
->hWnd
, TRUE
);
777 if (IsIconic(pAPLI
->hWnd
))
778 ShowWindow(pAPLI
->hWnd
, SW_RESTORE
);
779 BringWindowToTop(pAPLI
->hWnd
);
780 SetForegroundWindow(pAPLI
->hWnd
);
782 if (TaskManagerSettings
.MinimizeOnUse
)
783 ShowWindow(hMainWnd
, SW_MINIMIZE
);
787 void ApplicationPage_OnEndTask(void)
789 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
793 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
794 for (i
=0; i
<count
; i
++) {
795 memset(&item
, 0, sizeof(LV_ITEMW
));
796 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
798 item
.stateMask
= (UINT
)-1;
799 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
800 if (item
.state
& LVIS_SELECTED
) {
801 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
803 PostMessageW(pAPLI
->hWnd
, WM_CLOSE
, 0, 0);
809 void ApplicationPage_OnGotoProcess(void)
811 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
816 count
= SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
817 for (i
=0; i
<count
; i
++) {
818 memset(&item
, 0, sizeof(LV_ITEMW
));
819 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
821 item
.stateMask
= (UINT
)-1;
822 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
823 if (item
.state
& LVIS_SELECTED
) {
824 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
831 GetWindowThreadProcessId(pAPLI
->hWnd
, &dwProcessId
);
833 * Switch to the process tab
835 SendMessageW(hTabWnd
, TCM_SETCURFOCUS
, 1, 0);
837 * FIXME: Select the process item in the list
843 ApplicationPageWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
852 WCHAR wszStatus
[255];
854 LoadStringW(hInst
, IDS_APPLICATION_TASK
, wszTask
, sizeof(wszTask
)/sizeof(WCHAR
));
855 LoadStringW(hInst
, IDS_APPLICATION_STATUS
, wszStatus
, sizeof(wszStatus
)/sizeof(WCHAR
));
860 /* Save the width and height */
861 GetClientRect(hDlg
, &rc
);
862 nApplicationPageWidth
= rc
.right
;
863 nApplicationPageHeight
= rc
.bottom
;
865 /* Update window position */
866 SetWindowPos(hDlg
, NULL
, 15, 30, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
868 /* Get handles to the controls */
869 hApplicationPageListCtrl
= GetDlgItem(hDlg
, IDC_APPLIST
);
870 hApplicationPageEndTaskButton
= GetDlgItem(hDlg
, IDC_ENDTASK
);
871 hApplicationPageSwitchToButton
= GetDlgItem(hDlg
, IDC_SWITCHTO
);
872 hApplicationPageNewTaskButton
= GetDlgItem(hDlg
, IDC_NEWTASK
);
874 /* Initialize the application page's controls */
875 column
.mask
= LVCF_TEXT
|LVCF_WIDTH
;
876 column
.pszText
= wszTask
;
878 /* Add the "Task" column */
879 SendMessageW(hApplicationPageListCtrl
, LVM_INSERTCOLUMNW
, 0, (LPARAM
) &column
);
880 column
.mask
= LVCF_TEXT
|LVCF_WIDTH
;
881 column
.pszText
= wszStatus
;
883 /* Add the "Status" column */
884 SendMessageW(hApplicationPageListCtrl
, LVM_INSERTCOLUMNW
, 1, (LPARAM
) &column
);
886 SendMessageW(hApplicationPageListCtrl
, LVM_SETIMAGELIST
, LVSIL_SMALL
,
887 (LPARAM
) ImageList_Create(16, 16, ILC_COLOR8
|ILC_MASK
, 0, 1));
888 SendMessageW(hApplicationPageListCtrl
, LVM_SETIMAGELIST
, LVSIL_NORMAL
,
889 (LPARAM
) ImageList_Create(32, 32, ILC_COLOR8
|ILC_MASK
, 0, 1));
891 UpdateApplicationListControlViewSetting();
893 /* Start our refresh thread */
894 CreateThread(NULL
, 0, ApplicationPageRefreshThread
, NULL
, 0, NULL
);
899 /* Close the event handle, this will make the */
900 /* refresh thread exit when the wait fails */
901 CloseHandle(hApplicationPageEvent
);
906 /* Handle the button clicks */
907 switch (LOWORD(wParam
))
910 ApplicationPage_OnEndTask();
913 ApplicationPage_OnSwitchTo();
916 SendMessageW(hMainWnd
, WM_COMMAND
, MAKEWPARAM(ID_FILE_NEW
, 0), 0);
923 if (wParam
== SIZE_MINIMIZED
)
928 nXDifference
= cx
- nApplicationPageWidth
;
929 nYDifference
= cy
- nApplicationPageHeight
;
930 nApplicationPageWidth
= cx
;
931 nApplicationPageHeight
= cy
;
933 /* Reposition the application page's controls */
934 GetWindowRect(hApplicationPageListCtrl
, &rc
);
935 cx
= (rc
.right
- rc
.left
) + nXDifference
;
936 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
937 SetWindowPos(hApplicationPageListCtrl
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
938 InvalidateRect(hApplicationPageListCtrl
, NULL
, TRUE
);
940 GetClientRect(hApplicationPageEndTaskButton
, &rc
);
941 MapWindowPoints(hApplicationPageEndTaskButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
942 cx
= rc
.left
+ nXDifference
;
943 cy
= rc
.top
+ nYDifference
;
944 SetWindowPos(hApplicationPageEndTaskButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
945 InvalidateRect(hApplicationPageEndTaskButton
, NULL
, TRUE
);
947 GetClientRect(hApplicationPageSwitchToButton
, &rc
);
948 MapWindowPoints(hApplicationPageSwitchToButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
949 cx
= rc
.left
+ nXDifference
;
950 cy
= rc
.top
+ nYDifference
;
951 SetWindowPos(hApplicationPageSwitchToButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
952 InvalidateRect(hApplicationPageSwitchToButton
, NULL
, TRUE
);
954 GetClientRect(hApplicationPageNewTaskButton
, &rc
);
955 MapWindowPoints(hApplicationPageNewTaskButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
956 cx
= rc
.left
+ nXDifference
;
957 cy
= rc
.top
+ nYDifference
;
958 SetWindowPos(hApplicationPageNewTaskButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
959 InvalidateRect(hApplicationPageNewTaskButton
, NULL
, TRUE
);
964 ApplicationPageOnNotify(wParam
, lParam
);