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
)
416 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
;
418 WCHAR wszNotResponding
[255];
419 WCHAR wszRunning
[255];
421 LoadStringW(hInst
, IDS_APPLICATION_NOT_RESPONDING
, wszNotResponding
, sizeof(wszNotResponding
)/sizeof(WCHAR
));
422 LoadStringW(hInst
, IDS_APPLICATION_RUNNING
, wszRunning
, sizeof(wszRunning
)/sizeof(WCHAR
));
424 pnmh
= (LPNMHDR
) lParam
;
425 pnmdi
= (LV_DISPINFOW
*) lParam
;
427 if (pnmh
->hwndFrom
== hApplicationPageListCtrl
) {
428 switch (pnmh
->code
) {
429 case LVN_ITEMCHANGED
:
430 ApplicationPageUpdate();
433 case LVN_GETDISPINFOW
:
434 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)pnmdi
->item
.lParam
;
436 /* Update the item text */
437 if (pnmdi
->item
.iSubItem
== 0)
439 lstrcpynW(pnmdi
->item
.pszText
, pAPLI
->wszTitle
, pnmdi
->item
.cchTextMax
);
442 /* Update the item status */
443 else if (pnmdi
->item
.iSubItem
== 1)
446 lstrcpynW(pnmdi
->item
.pszText
, wszNotResponding
, pnmdi
->item
.cchTextMax
);
448 lstrcpynW(pnmdi
->item
.pszText
, wszRunning
, 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 SendMessageW(hApplicationPageListCtrl
, LVM_SORTITEMS
, 0, (LPARAM
) ApplicationPageCompareFunc
);
493 bSortAscending
= !bSortAscending
;
501 void RefreshApplicationPage(void)
503 /* Signal the event so that our refresh thread */
504 /* will wake up and refresh the application page */
505 SetEvent(hApplicationPageEvent
);
508 static void UpdateApplicationListControlViewSetting(void)
510 DWORD dwStyle
= GetWindowLong(hApplicationPageListCtrl
, GWL_STYLE
);
512 dwStyle
&= ~LVS_REPORT
;
513 dwStyle
&= ~LVS_ICON
;
514 dwStyle
&= ~LVS_LIST
;
515 dwStyle
&= ~LVS_SMALLICON
;
517 if (TaskManagerSettings
.View_LargeIcons
)
519 else if (TaskManagerSettings
.View_SmallIcons
)
520 dwStyle
|= LVS_SMALLICON
;
522 dwStyle
|= LVS_REPORT
;
524 SetWindowLong(hApplicationPageListCtrl
, GWL_STYLE
, dwStyle
);
526 RefreshApplicationPage();
529 void ApplicationPage_OnViewLargeIcons(void)
534 hMenu
= GetMenu(hMainWnd
);
535 hViewMenu
= GetSubMenu(hMenu
, 2);
537 TaskManagerSettings
.View_LargeIcons
= TRUE
;
538 TaskManagerSettings
.View_SmallIcons
= FALSE
;
539 TaskManagerSettings
.View_Details
= FALSE
;
540 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
542 UpdateApplicationListControlViewSetting();
545 void ApplicationPage_OnViewSmallIcons(void)
550 hMenu
= GetMenu(hMainWnd
);
551 hViewMenu
= GetSubMenu(hMenu
, 2);
553 TaskManagerSettings
.View_LargeIcons
= FALSE
;
554 TaskManagerSettings
.View_SmallIcons
= TRUE
;
555 TaskManagerSettings
.View_Details
= FALSE
;
556 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
558 UpdateApplicationListControlViewSetting();
561 void ApplicationPage_OnViewDetails(void)
566 hMenu
= GetMenu(hMainWnd
);
567 hViewMenu
= GetSubMenu(hMenu
, 2);
569 TaskManagerSettings
.View_LargeIcons
= FALSE
;
570 TaskManagerSettings
.View_SmallIcons
= FALSE
;
571 TaskManagerSettings
.View_Details
= TRUE
;
572 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
574 UpdateApplicationListControlViewSetting();
577 void ApplicationPage_OnWindowsTileHorizontally(void)
579 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
585 hWndArray
= HeapAlloc(GetProcessHeap(), 0,
586 sizeof(HWND
) * ListView_GetItemCount(hApplicationPageListCtrl
));
589 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
590 memset(&item
, 0, sizeof(LV_ITEMW
));
591 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
593 item
.stateMask
= (UINT
)-1;
594 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
596 if (item
.state
& LVIS_SELECTED
) {
597 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
600 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
605 TileWindows(NULL
, MDITILE_HORIZONTAL
, NULL
, nWndCount
, hWndArray
);
606 HeapFree(GetProcessHeap(), 0, hWndArray
);
609 void ApplicationPage_OnWindowsTileVertically(void)
611 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
617 hWndArray
= HeapAlloc(GetProcessHeap(), 0,
618 sizeof(HWND
) * ListView_GetItemCount(hApplicationPageListCtrl
));
621 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
622 memset(&item
, 0, sizeof(LV_ITEMW
));
623 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
625 item
.stateMask
= (UINT
)-1;
626 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
628 if (item
.state
& LVIS_SELECTED
) {
629 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
631 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
637 TileWindows(NULL
, MDITILE_VERTICAL
, NULL
, nWndCount
, hWndArray
);
638 HeapFree(GetProcessHeap(), 0, hWndArray
);
641 void ApplicationPage_OnWindowsMinimize(void)
643 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
647 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
648 memset(&item
, 0, sizeof(LV_ITEMW
));
649 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
651 item
.stateMask
= (UINT
)-1;
652 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
653 if (item
.state
& LVIS_SELECTED
) {
654 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
656 ShowWindow(pAPLI
->hWnd
, SW_MINIMIZE
);
662 void ApplicationPage_OnWindowsMaximize(void)
664 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
668 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
669 memset(&item
, 0, sizeof(LV_ITEMW
));
670 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
672 item
.stateMask
= (UINT
)-1;
673 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
674 if (item
.state
& LVIS_SELECTED
) {
675 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
677 ShowWindow(pAPLI
->hWnd
, SW_MAXIMIZE
);
683 void ApplicationPage_OnWindowsCascade(void)
685 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
691 hWndArray
= HeapAlloc(GetProcessHeap(), 0,
692 sizeof(HWND
) * ListView_GetItemCount(hApplicationPageListCtrl
));
695 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
696 memset(&item
, 0, sizeof(LV_ITEMW
));
697 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
699 item
.stateMask
= (UINT
)-1;
700 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
701 if (item
.state
& LVIS_SELECTED
) {
702 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
704 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
709 CascadeWindows(NULL
, 0, NULL
, nWndCount
, hWndArray
);
710 HeapFree(GetProcessHeap(), 0, hWndArray
);
713 void ApplicationPage_OnWindowsBringToFront(void)
715 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
719 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
720 memset(&item
, 0, sizeof(LV_ITEMW
));
721 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
723 item
.stateMask
= (UINT
)-1;
724 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
725 if (item
.state
& LVIS_SELECTED
) {
726 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
731 if (IsIconic(pAPLI
->hWnd
))
732 ShowWindow(pAPLI
->hWnd
, SW_RESTORE
);
733 BringWindowToTop(pAPLI
->hWnd
);
737 void ApplicationPage_OnSwitchTo(void)
739 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
743 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
744 memset(&item
, 0, sizeof(LV_ITEMW
));
745 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
747 item
.stateMask
= (UINT
)-1;
748 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
750 if (item
.state
& LVIS_SELECTED
) {
751 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
756 typedef void (WINAPI
*PROCSWITCHTOTHISWINDOW
) (HWND
, BOOL
);
757 PROCSWITCHTOTHISWINDOW SwitchToThisWindow
;
759 HMODULE hUser32
= GetModuleHandleW(wszUser32
);
760 SwitchToThisWindow
= (PROCSWITCHTOTHISWINDOW
)GetProcAddress(hUser32
, "SwitchToThisWindow");
761 if (SwitchToThisWindow
) {
762 SwitchToThisWindow(pAPLI
->hWnd
, TRUE
);
764 if (IsIconic(pAPLI
->hWnd
))
765 ShowWindow(pAPLI
->hWnd
, SW_RESTORE
);
766 BringWindowToTop(pAPLI
->hWnd
);
767 SetForegroundWindow(pAPLI
->hWnd
);
769 if (TaskManagerSettings
.MinimizeOnUse
)
770 ShowWindow(hMainWnd
, SW_MINIMIZE
);
774 void ApplicationPage_OnEndTask(void)
776 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
780 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); 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
;
789 PostMessage(pAPLI
->hWnd
, WM_CLOSE
, 0, 0);
795 void ApplicationPage_OnGotoProcess(void)
797 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
802 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
803 memset(&item
, 0, sizeof(LV_ITEMW
));
804 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
806 item
.stateMask
= (UINT
)-1;
807 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
808 if (item
.state
& LVIS_SELECTED
) {
809 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
816 GetWindowThreadProcessId(pAPLI
->hWnd
, &dwProcessId
);
818 * Switch to the process tab
820 TabCtrl_SetCurFocus(hTabWnd
, 1);
822 * FIXME: Select the process item in the list
824 for (i
=0; i
<ListView_GetItemCount(hProcessPage
); i
++) {
830 ApplicationPageWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
839 WCHAR wszStatus
[255];
841 LoadStringW(hInst
, IDS_APPLICATION_TASK
, wszTask
, sizeof(wszTask
)/sizeof(WCHAR
));
842 LoadStringW(hInst
, IDS_APPLICATION_STATUS
, wszStatus
, sizeof(wszStatus
)/sizeof(WCHAR
));
847 /* Save the width and height */
848 GetClientRect(hDlg
, &rc
);
849 nApplicationPageWidth
= rc
.right
;
850 nApplicationPageHeight
= rc
.bottom
;
852 /* Update window position */
853 SetWindowPos(hDlg
, NULL
, 15, 30, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
855 /* Get handles to the controls */
856 hApplicationPageListCtrl
= GetDlgItem(hDlg
, IDC_APPLIST
);
857 hApplicationPageEndTaskButton
= GetDlgItem(hDlg
, IDC_ENDTASK
);
858 hApplicationPageSwitchToButton
= GetDlgItem(hDlg
, IDC_SWITCHTO
);
859 hApplicationPageNewTaskButton
= GetDlgItem(hDlg
, IDC_NEWTASK
);
861 /* Initialize the application page's controls */
862 column
.mask
= LVCF_TEXT
|LVCF_WIDTH
;
863 column
.pszText
= wszTask
;
865 /* Add the "Task" column */
866 SendMessageW(hApplicationPageListCtrl
, LVM_INSERTCOLUMNW
, 0, (LPARAM
) &column
);
867 column
.mask
= LVCF_TEXT
|LVCF_WIDTH
;
868 column
.pszText
= wszStatus
;
870 /* Add the "Status" column */
871 SendMessageW(hApplicationPageListCtrl
, LVM_INSERTCOLUMNW
, 1, (LPARAM
) &column
);
873 SendMessageW(hApplicationPageListCtrl
, LVM_SETIMAGELIST
, LVSIL_SMALL
,
874 (LPARAM
) ImageList_Create(16, 16, ILC_COLOR8
|ILC_MASK
, 0, 1));
875 SendMessageW(hApplicationPageListCtrl
, LVM_SETIMAGELIST
, LVSIL_NORMAL
,
876 (LPARAM
) ImageList_Create(32, 32, ILC_COLOR8
|ILC_MASK
, 0, 1));
878 UpdateApplicationListControlViewSetting();
880 /* Start our refresh thread */
881 CreateThread(NULL
, 0, ApplicationPageRefreshThread
, NULL
, 0, NULL
);
886 /* Close the event handle, this will make the */
887 /* refresh thread exit when the wait fails */
888 CloseHandle(hApplicationPageEvent
);
893 /* Handle the button clicks */
894 switch (LOWORD(wParam
))
897 ApplicationPage_OnEndTask();
900 ApplicationPage_OnSwitchTo();
903 SendMessageW(hMainWnd
, WM_COMMAND
, MAKEWPARAM(ID_FILE_NEW
, 0), 0);
910 if (wParam
== SIZE_MINIMIZED
)
915 nXDifference
= cx
- nApplicationPageWidth
;
916 nYDifference
= cy
- nApplicationPageHeight
;
917 nApplicationPageWidth
= cx
;
918 nApplicationPageHeight
= cy
;
920 /* Reposition the application page's controls */
921 GetWindowRect(hApplicationPageListCtrl
, &rc
);
922 cx
= (rc
.right
- rc
.left
) + nXDifference
;
923 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
924 SetWindowPos(hApplicationPageListCtrl
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
925 InvalidateRect(hApplicationPageListCtrl
, NULL
, TRUE
);
927 GetClientRect(hApplicationPageEndTaskButton
, &rc
);
928 MapWindowPoints(hApplicationPageEndTaskButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
929 cx
= rc
.left
+ nXDifference
;
930 cy
= rc
.top
+ nYDifference
;
931 SetWindowPos(hApplicationPageEndTaskButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
932 InvalidateRect(hApplicationPageEndTaskButton
, NULL
, TRUE
);
934 GetClientRect(hApplicationPageSwitchToButton
, &rc
);
935 MapWindowPoints(hApplicationPageSwitchToButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
936 cx
= rc
.left
+ nXDifference
;
937 cy
= rc
.top
+ nYDifference
;
938 SetWindowPos(hApplicationPageSwitchToButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
939 InvalidateRect(hApplicationPageSwitchToButton
, NULL
, TRUE
);
941 GetClientRect(hApplicationPageNewTaskButton
, &rc
);
942 MapWindowPoints(hApplicationPageNewTaskButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
943 cx
= rc
.left
+ nXDifference
;
944 cy
= rc
.top
+ nYDifference
;
945 SetWindowPos(hApplicationPageNewTaskButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
946 InvalidateRect(hApplicationPageNewTaskButton
, NULL
, TRUE
);
951 ApplicationPageOnNotify(wParam
, lParam
);