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 static const WCHAR wszNotResponding
[] = {'N','o','t',' ','R','e','s','p','o','n','d','i','n','g',0};
421 static const WCHAR wszRunning
[] = {'R','u','n','n','i','n','g',0};
424 idctrl
= (int) wParam
;
425 pnmh
= (LPNMHDR
) lParam
;
426 pnmv
= (LPNM_LISTVIEW
) lParam
;
427 pnmdi
= (LV_DISPINFOW
*) lParam
;
429 if (pnmh
->hwndFrom
== hApplicationPageListCtrl
) {
430 switch (pnmh
->code
) {
431 case LVN_ITEMCHANGED
:
432 ApplicationPageUpdate();
435 case LVN_GETDISPINFOW
:
436 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)pnmdi
->item
.lParam
;
438 /* Update the item text */
439 if (pnmdi
->item
.iSubItem
== 0)
441 lstrcpynW(pnmdi
->item
.pszText
, pAPLI
->wszTitle
, pnmdi
->item
.cchTextMax
);
444 /* Update the item status */
445 else if (pnmdi
->item
.iSubItem
== 1)
448 lstrcpynW(pnmdi
->item
.pszText
, wszNotResponding
, pnmdi
->item
.cchTextMax
);
450 lstrcpynW(pnmdi
->item
.pszText
, wszRunning
, pnmdi
->item
.cchTextMax
);
457 if (ListView_GetSelectedCount(hApplicationPageListCtrl
) < 1)
459 ApplicationPageShowContextMenu1();
463 ApplicationPageShowContextMenu2();
470 ApplicationPage_OnSwitchTo();
475 else if (pnmh
->hwndFrom
== ListView_GetHeader(hApplicationPageListCtrl
))
481 if (ListView_GetSelectedCount(hApplicationPageListCtrl
) < 1)
483 ApplicationPageShowContextMenu1();
487 ApplicationPageShowContextMenu2();
494 SendMessageW(hApplicationPageListCtrl
, LVM_SORTITEMS
, 0, (LPARAM
) ApplicationPageCompareFunc
);
495 bSortAscending
= !bSortAscending
;
504 ApplicationPageWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
512 static const WCHAR wszTasks
[] = {'T','a','s','k','s',0};
513 static WCHAR wszTask
[] = {'T','a','s','k',0};
514 static WCHAR wszStatus
[] = {'S','t','a','t','u','s',0};
519 /* Save the width and height */
520 GetClientRect(hDlg
, &rc
);
521 nApplicationPageWidth
= rc
.right
;
522 nApplicationPageHeight
= rc
.bottom
;
524 /* Update window position */
525 SetWindowPos(hDlg
, NULL
, 15, 30, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
527 /* Get handles to the controls */
528 hApplicationPageListCtrl
= GetDlgItem(hDlg
, IDC_APPLIST
);
529 hApplicationPageEndTaskButton
= GetDlgItem(hDlg
, IDC_ENDTASK
);
530 hApplicationPageSwitchToButton
= GetDlgItem(hDlg
, IDC_SWITCHTO
);
531 hApplicationPageNewTaskButton
= GetDlgItem(hDlg
, IDC_NEWTASK
);
533 SetWindowTextW(hApplicationPageListCtrl
, wszTasks
);
535 /* Initialize the application page's controls */
536 column
.mask
= LVCF_TEXT
|LVCF_WIDTH
;
537 column
.pszText
= wszTask
;
539 /* Add the "Task" column */
540 SendMessageW(hApplicationPageListCtrl
, LVM_INSERTCOLUMNW
, 0, (LPARAM
) &column
);
541 column
.mask
= LVCF_TEXT
|LVCF_WIDTH
;
542 column
.pszText
= wszStatus
;
544 /* Add the "Status" column */
545 SendMessageW(hApplicationPageListCtrl
, LVM_INSERTCOLUMNW
, 1, (LPARAM
) &column
);
547 SendMessageW(hApplicationPageListCtrl
, LVM_SETIMAGELIST
, LVSIL_SMALL
,
548 (LPARAM
) ImageList_Create(16, 16, ILC_COLOR8
|ILC_MASK
, 0, 1));
549 SendMessageW(hApplicationPageListCtrl
, LVM_SETIMAGELIST
, LVSIL_NORMAL
,
550 (LPARAM
) ImageList_Create(32, 32, ILC_COLOR8
|ILC_MASK
, 0, 1));
552 UpdateApplicationListControlViewSetting();
554 /* Start our refresh thread */
555 CreateThread(NULL
, 0, ApplicationPageRefreshThread
, NULL
, 0, NULL
);
560 /* Close the event handle, this will make the */
561 /* refresh thread exit when the wait fails */
562 CloseHandle(hApplicationPageEvent
);
567 /* Handle the button clicks */
568 switch (LOWORD(wParam
))
571 ApplicationPage_OnEndTask();
574 ApplicationPage_OnSwitchTo();
577 SendMessageW(hMainWnd
, WM_COMMAND
, MAKEWPARAM(ID_FILE_NEW
, 0), 0);
584 if (wParam
== SIZE_MINIMIZED
)
589 nXDifference
= cx
- nApplicationPageWidth
;
590 nYDifference
= cy
- nApplicationPageHeight
;
591 nApplicationPageWidth
= cx
;
592 nApplicationPageHeight
= cy
;
594 /* Reposition the application page's controls */
595 GetWindowRect(hApplicationPageListCtrl
, &rc
);
596 cx
= (rc
.right
- rc
.left
) + nXDifference
;
597 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
598 SetWindowPos(hApplicationPageListCtrl
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
599 InvalidateRect(hApplicationPageListCtrl
, NULL
, TRUE
);
601 GetClientRect(hApplicationPageEndTaskButton
, &rc
);
602 MapWindowPoints(hApplicationPageEndTaskButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
603 cx
= rc
.left
+ nXDifference
;
604 cy
= rc
.top
+ nYDifference
;
605 SetWindowPos(hApplicationPageEndTaskButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
606 InvalidateRect(hApplicationPageEndTaskButton
, NULL
, TRUE
);
608 GetClientRect(hApplicationPageSwitchToButton
, &rc
);
609 MapWindowPoints(hApplicationPageSwitchToButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
610 cx
= rc
.left
+ nXDifference
;
611 cy
= rc
.top
+ nYDifference
;
612 SetWindowPos(hApplicationPageSwitchToButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
613 InvalidateRect(hApplicationPageSwitchToButton
, NULL
, TRUE
);
615 GetClientRect(hApplicationPageNewTaskButton
, &rc
);
616 MapWindowPoints(hApplicationPageNewTaskButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
617 cx
= rc
.left
+ nXDifference
;
618 cy
= rc
.top
+ nYDifference
;
619 SetWindowPos(hApplicationPageNewTaskButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
620 InvalidateRect(hApplicationPageNewTaskButton
, NULL
, TRUE
);
625 ApplicationPageOnNotify(wParam
, lParam
);
633 void RefreshApplicationPage(void)
635 /* Signal the event so that our refresh thread */
636 /* will wake up and refresh the application page */
637 SetEvent(hApplicationPageEvent
);
640 void UpdateApplicationListControlViewSetting(void)
642 DWORD dwStyle
= GetWindowLong(hApplicationPageListCtrl
, GWL_STYLE
);
644 dwStyle
&= ~LVS_REPORT
;
645 dwStyle
&= ~LVS_ICON
;
646 dwStyle
&= ~LVS_LIST
;
647 dwStyle
&= ~LVS_SMALLICON
;
649 if (TaskManagerSettings
.View_LargeIcons
)
651 else if (TaskManagerSettings
.View_SmallIcons
)
652 dwStyle
|= LVS_SMALLICON
;
654 dwStyle
|= LVS_REPORT
;
656 SetWindowLong(hApplicationPageListCtrl
, GWL_STYLE
, dwStyle
);
658 RefreshApplicationPage();
661 void ApplicationPage_OnViewLargeIcons(void)
666 hMenu
= GetMenu(hMainWnd
);
667 hViewMenu
= GetSubMenu(hMenu
, 2);
669 TaskManagerSettings
.View_LargeIcons
= TRUE
;
670 TaskManagerSettings
.View_SmallIcons
= FALSE
;
671 TaskManagerSettings
.View_Details
= FALSE
;
672 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
674 UpdateApplicationListControlViewSetting();
677 void ApplicationPage_OnViewSmallIcons(void)
682 hMenu
= GetMenu(hMainWnd
);
683 hViewMenu
= GetSubMenu(hMenu
, 2);
685 TaskManagerSettings
.View_LargeIcons
= FALSE
;
686 TaskManagerSettings
.View_SmallIcons
= TRUE
;
687 TaskManagerSettings
.View_Details
= FALSE
;
688 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
690 UpdateApplicationListControlViewSetting();
693 void ApplicationPage_OnViewDetails(void)
698 hMenu
= GetMenu(hMainWnd
);
699 hViewMenu
= GetSubMenu(hMenu
, 2);
701 TaskManagerSettings
.View_LargeIcons
= FALSE
;
702 TaskManagerSettings
.View_SmallIcons
= FALSE
;
703 TaskManagerSettings
.View_Details
= TRUE
;
704 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
706 UpdateApplicationListControlViewSetting();
709 void ApplicationPage_OnWindowsTileHorizontally(void)
711 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
717 hWndArray
= HeapAlloc(GetProcessHeap(), 0,
718 sizeof(HWND
) * ListView_GetItemCount(hApplicationPageListCtrl
));
721 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
722 memset(&item
, 0, sizeof(LV_ITEMW
));
723 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
725 item
.stateMask
= (UINT
)-1;
726 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
728 if (item
.state
& LVIS_SELECTED
) {
729 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
732 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
737 TileWindows(NULL
, MDITILE_HORIZONTAL
, NULL
, nWndCount
, hWndArray
);
738 HeapFree(GetProcessHeap(), 0, hWndArray
);
741 void ApplicationPage_OnWindowsTileVertically(void)
743 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
749 hWndArray
= HeapAlloc(GetProcessHeap(), 0,
750 sizeof(HWND
) * ListView_GetItemCount(hApplicationPageListCtrl
));
753 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
754 memset(&item
, 0, sizeof(LV_ITEMW
));
755 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
757 item
.stateMask
= (UINT
)-1;
758 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
760 if (item
.state
& LVIS_SELECTED
) {
761 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
763 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
769 TileWindows(NULL
, MDITILE_VERTICAL
, NULL
, nWndCount
, hWndArray
);
770 HeapFree(GetProcessHeap(), 0, hWndArray
);
773 void ApplicationPage_OnWindowsMinimize(void)
775 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
779 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
780 memset(&item
, 0, sizeof(LV_ITEMW
));
781 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
783 item
.stateMask
= (UINT
)-1;
784 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
785 if (item
.state
& LVIS_SELECTED
) {
786 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
788 ShowWindow(pAPLI
->hWnd
, SW_MINIMIZE
);
794 void ApplicationPage_OnWindowsMaximize(void)
796 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
800 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
801 memset(&item
, 0, sizeof(LV_ITEMW
));
802 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
804 item
.stateMask
= (UINT
)-1;
805 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
806 if (item
.state
& LVIS_SELECTED
) {
807 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
809 ShowWindow(pAPLI
->hWnd
, SW_MAXIMIZE
);
815 void ApplicationPage_OnWindowsCascade(void)
817 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
823 hWndArray
= HeapAlloc(GetProcessHeap(), 0,
824 sizeof(HWND
) * ListView_GetItemCount(hApplicationPageListCtrl
));
827 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
828 memset(&item
, 0, sizeof(LV_ITEMW
));
829 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
831 item
.stateMask
= (UINT
)-1;
832 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
833 if (item
.state
& LVIS_SELECTED
) {
834 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
836 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
841 CascadeWindows(NULL
, 0, NULL
, nWndCount
, hWndArray
);
842 HeapFree(GetProcessHeap(), 0, hWndArray
);
845 void ApplicationPage_OnWindowsBringToFront(void)
847 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
851 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
852 memset(&item
, 0, sizeof(LV_ITEMW
));
853 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
855 item
.stateMask
= (UINT
)-1;
856 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
857 if (item
.state
& LVIS_SELECTED
) {
858 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
863 if (IsIconic(pAPLI
->hWnd
))
864 ShowWindow(pAPLI
->hWnd
, SW_RESTORE
);
865 BringWindowToTop(pAPLI
->hWnd
);
869 void ApplicationPage_OnSwitchTo(void)
871 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
875 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
876 memset(&item
, 0, sizeof(LV_ITEMW
));
877 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
879 item
.stateMask
= (UINT
)-1;
880 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
882 if (item
.state
& LVIS_SELECTED
) {
883 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
888 typedef void (WINAPI
*PROCSWITCHTOTHISWINDOW
) (HWND
, BOOL
);
889 PROCSWITCHTOTHISWINDOW SwitchToThisWindow
;
891 HMODULE hUser32
= GetModuleHandleW(wszUser32
);
892 SwitchToThisWindow
= (PROCSWITCHTOTHISWINDOW
)GetProcAddress(hUser32
, "SwitchToThisWindow");
893 if (SwitchToThisWindow
) {
894 SwitchToThisWindow(pAPLI
->hWnd
, TRUE
);
896 if (IsIconic(pAPLI
->hWnd
))
897 ShowWindow(pAPLI
->hWnd
, SW_RESTORE
);
898 BringWindowToTop(pAPLI
->hWnd
);
899 SetForegroundWindow(pAPLI
->hWnd
);
901 if (TaskManagerSettings
.MinimizeOnUse
)
902 ShowWindow(hMainWnd
, SW_MINIMIZE
);
906 void ApplicationPage_OnEndTask(void)
908 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
912 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
913 memset(&item
, 0, sizeof(LV_ITEMW
));
914 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
916 item
.stateMask
= (UINT
)-1;
917 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
918 if (item
.state
& LVIS_SELECTED
) {
919 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
921 PostMessage(pAPLI
->hWnd
, WM_CLOSE
, 0, 0);
927 void ApplicationPage_OnGotoProcess(void)
929 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
934 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
935 memset(&item
, 0, sizeof(LV_ITEMW
));
936 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
938 item
.stateMask
= (UINT
)-1;
939 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
940 if (item
.state
& LVIS_SELECTED
) {
941 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
948 GetWindowThreadProcessId(pAPLI
->hWnd
, &dwProcessId
);
950 * Switch to the process tab
952 TabCtrl_SetCurFocus(hTabWnd
, 1);
954 * FIXME: Select the process item in the list
956 for (i
=0; i
<ListView_GetItemCount(hProcessPage
); i
++) {