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 */
32 #include "wine/unicode.h"
41 } APPLICATION_PAGE_LIST_ITEM
, *LPAPPLICATION_PAGE_LIST_ITEM
;
43 HWND hApplicationPage
; /* Application List Property Page */
44 HWND hApplicationPageListCtrl
; /* Application ListCtrl Window */
45 HWND hApplicationPageEndTaskButton
; /* Application End Task button */
46 HWND hApplicationPageSwitchToButton
; /* Application Switch To button */
47 HWND hApplicationPageNewTaskButton
; /* Application New Task button */
48 static int nApplicationPageWidth
;
49 static int nApplicationPageHeight
;
50 static HANDLE hApplicationPageEvent
= NULL
; /* When this event becomes signaled then we refresh the app list */
51 static BOOL bSortAscending
= TRUE
;
53 static const WCHAR wszUser32
[] = {'U','S','E','R','3','2','.','D','L','L',0};
55 void SwitchToThisWindow (
56 HWND hWnd
, /* Handle to the window that should be activated */
57 BOOL bRestore
/* Restore the window if it is minimized */
61 static void ApplicationPageUpdate(void)
63 /* Enable or disable the "End Task" & "Switch To" buttons */
64 if (ListView_GetSelectedCount(hApplicationPageListCtrl
))
66 EnableWindow(hApplicationPageEndTaskButton
, TRUE
);
67 EnableWindow(hApplicationPageSwitchToButton
, TRUE
);
71 EnableWindow(hApplicationPageEndTaskButton
, FALSE
);
72 EnableWindow(hApplicationPageSwitchToButton
, FALSE
);
75 /* If we are on the applications tab, then the windows menu will */
76 /* be present on the menu bar so enable & disable the menu items */
77 if (TabCtrl_GetCurSel(hTabWnd
) == 0)
82 hMenu
= GetMenu(hMainWnd
);
83 hWindowsMenu
= GetSubMenu(hMenu
, 3);
85 /* Only one item selected */
86 if (ListView_GetSelectedCount(hApplicationPageListCtrl
) == 1)
88 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
89 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
90 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
91 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
92 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
93 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_ENABLED
);
95 /* More than one item selected */
96 else if (ListView_GetSelectedCount(hApplicationPageListCtrl
) > 1)
98 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_ENABLED
);
99 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_ENABLED
);
100 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
101 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
102 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_ENABLED
);
103 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
105 /* No items selected */
108 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
109 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
110 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
111 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
112 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
113 EnableMenuItem(hWindowsMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
118 static void AddOrUpdateHwnd(HWND hWnd
, WCHAR
*wszTitle
, HICON hIcon
, BOOL bHung
)
120 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
121 HIMAGELIST hImageListLarge
;
122 HIMAGELIST hImageListSmall
;
125 BOOL bAlreadyInList
= FALSE
;
126 BOOL bItemRemoved
= FALSE
;
128 memset(&item
, 0, sizeof(LV_ITEMW
));
130 /* Get the image lists */
131 hImageListLarge
= ListView_GetImageList(hApplicationPageListCtrl
, LVSIL_NORMAL
);
132 hImageListSmall
= ListView_GetImageList(hApplicationPageListCtrl
, LVSIL_SMALL
);
134 /* Check to see if it's already in our list */
135 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++)
137 memset(&item
, 0, sizeof(LV_ITEMW
));
138 item
.mask
= LVIF_IMAGE
|LVIF_PARAM
;
140 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
142 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
143 if (pAPLI
->hWnd
== hWnd
)
145 bAlreadyInList
= TRUE
;
150 /* If it is already in the list then update it if necessary */
153 /* Check to see if anything needs updating */
154 if ((pAPLI
->hIcon
!= hIcon
) ||
155 (strcmpW(pAPLI
->wszTitle
, wszTitle
) != 0) ||
156 (pAPLI
->bHung
!= bHung
))
158 /* Update the structure */
159 pAPLI
->hIcon
= hIcon
;
160 pAPLI
->bHung
= bHung
;
161 strcpyW(pAPLI
->wszTitle
, wszTitle
);
163 /* Update the image list */
164 ImageList_ReplaceIcon(hImageListLarge
, item
.iItem
, hIcon
);
165 ImageList_ReplaceIcon(hImageListSmall
, item
.iItem
, hIcon
);
167 /* Update the list view */
168 SendMessageW(hApplicationPageListCtrl
, LVM_REDRAWITEMS
, 0, ListView_GetItemCount(hApplicationPageListCtrl
));
169 /* UpdateWindow(hApplicationPageListCtrl); */
170 InvalidateRect(hApplicationPageListCtrl
, NULL
, 0);
173 /* It is not already in the list so add it */
176 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)malloc(sizeof(APPLICATION_PAGE_LIST_ITEM
));
179 pAPLI
->hIcon
= hIcon
;
180 pAPLI
->bHung
= bHung
;
181 strcpyW(pAPLI
->wszTitle
, wszTitle
);
183 /* Add the item to the list */
184 memset(&item
, 0, sizeof(LV_ITEMW
));
185 item
.mask
= LVIF_TEXT
|LVIF_IMAGE
|LVIF_PARAM
;
186 ImageList_AddIcon(hImageListLarge
, hIcon
);
187 item
.iImage
= ImageList_AddIcon(hImageListSmall
, hIcon
);
188 item
.pszText
= LPSTR_TEXTCALLBACKW
;
189 item
.iItem
= ListView_GetItemCount(hApplicationPageListCtrl
);
190 item
.lParam
= (LPARAM
)pAPLI
;
191 SendMessageW(hApplicationPageListCtrl
, LVM_INSERTITEMW
, 0, (LPARAM
) &item
);
195 /* Check to see if we need to remove any items from the list */
196 for (i
=ListView_GetItemCount(hApplicationPageListCtrl
)-1; i
>=0; i
--)
198 memset(&item
, 0, sizeof(LV_ITEMW
));
199 item
.mask
= LVIF_IMAGE
|LVIF_PARAM
;
201 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
203 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
204 if (!IsWindow(pAPLI
->hWnd
)||
205 (strlenW(pAPLI
->wszTitle
) <= 0) ||
206 !IsWindowVisible(pAPLI
->hWnd
) ||
207 (GetParent(pAPLI
->hWnd
) != NULL
) ||
208 (GetWindow(pAPLI
->hWnd
, GW_OWNER
) != NULL
) ||
209 (GetWindowLong(hWnd
, GWL_EXSTYLE
) & WS_EX_TOOLWINDOW
))
211 ImageList_Remove(hImageListLarge
, item
.iItem
);
212 ImageList_Remove(hImageListSmall
, item
.iItem
);
214 SendMessage(hApplicationPageListCtrl
, LVM_DELETEITEM
, item
.iItem
, 0);
221 * If an item was removed from the list then
222 * we need to resync all the items with the
227 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++)
229 memset(&item
, 0, sizeof(LV_ITEMW
));
230 item
.mask
= LVIF_IMAGE
;
233 SendMessageW(hApplicationPageListCtrl
, LVM_SETITEMW
, 0, (LPARAM
) &item
);
237 ApplicationPageUpdate();
240 static BOOL CALLBACK
EnumWindowsProc(HWND hWnd
, LPARAM lParam
)
246 typedef int (__stdcall
*IsHungAppWindowProc
)(HWND
);
247 IsHungAppWindowProc IsHungAppWindow
;
250 /* Skip our window */
251 if (hWnd
== hMainWnd
)
254 bLargeIcon
= TaskManagerSettings
.View_LargeIcons
? TRUE
: FALSE
;
256 /* Check and see if this is a top-level app window */
257 if (!GetWindowTextW(hWnd
, wszText
, sizeof(wszText
)/sizeof(WCHAR
)) ||
258 !IsWindowVisible(hWnd
) ||
259 (GetParent(hWnd
) != NULL
) ||
260 (GetWindow(hWnd
, GW_OWNER
) != NULL
) ||
261 (GetWindowLong(hWnd
, GWL_EXSTYLE
) & WS_EX_TOOLWINDOW
))
263 return TRUE
; /* Skip this window */
266 /* Get the icon for this window */
268 SendMessageTimeout(hWnd
, WM_GETICON
, bLargeIcon
? ICON_BIG
/*1*/ : ICON_SMALL
/*0*/, 0, 0, 1000, (PDWORD_PTR
)&hIcon
);
272 hIcon
= (HICON
)GetClassLongPtr(hWnd
, bLargeIcon
? GCLP_HICON
: GCLP_HICONSM
);
273 if (!hIcon
) hIcon
= (HICON
)GetClassLongPtr(hWnd
, bLargeIcon
? GCLP_HICONSM
: GCLP_HICON
);
274 if (!hIcon
) SendMessageTimeout(hWnd
, WM_QUERYDRAGICON
, 0, 0, 0, 1000, (PDWORD_PTR
)&hIcon
);
275 if (!hIcon
) SendMessageTimeout(hWnd
, WM_GETICON
, bLargeIcon
? ICON_SMALL
/*0*/ : ICON_BIG
/*1*/, 0, 0, 1000, (PDWORD_PTR
)&hIcon
);
279 hIcon
= LoadIcon(hInst
, bLargeIcon
? MAKEINTRESOURCE(IDI_WINDOW
) : MAKEINTRESOURCE(IDI_WINDOWSM
));
283 IsHungAppWindow
= (IsHungAppWindowProc
)(FARPROC
)GetProcAddress(GetModuleHandleW(wszUser32
), "IsHungAppWindow");
286 bHung
= IsHungAppWindow(hWnd
);
288 AddOrUpdateHwnd(hWnd
, wszText
, hIcon
, bHung
);
293 static DWORD WINAPI
ApplicationPageRefreshThread(void *lpParameter
)
295 /* Create the event */
296 hApplicationPageEvent
= CreateEvent(NULL
, TRUE
, TRUE
, NULL
);
298 /* If we couldn't create the event then exit the thread */
299 if (!hApplicationPageEvent
)
306 /* Wait on the event */
307 dwWaitVal
= WaitForSingleObject(hApplicationPageEvent
, INFINITE
);
309 /* If the wait failed then the event object must have been */
310 /* closed and the task manager is exiting so exit this thread */
311 if (dwWaitVal
== WAIT_FAILED
)
314 if (dwWaitVal
== WAIT_OBJECT_0
)
316 /* Reset our event */
317 ResetEvent(hApplicationPageEvent
);
322 * Should this be EnumDesktopWindows() instead?
324 EnumWindows(EnumWindowsProc
, 0);
329 static void ApplicationPageShowContextMenu1(void)
337 hMenu
= LoadMenu(hInst
, MAKEINTRESOURCE(IDR_APPLICATION_PAGE_CONTEXT1
));
338 hSubMenu
= GetSubMenu(hMenu
, 0);
340 if (TaskManagerSettings
.View_LargeIcons
)
341 CheckMenuRadioItem(hSubMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
342 else if (TaskManagerSettings
.View_SmallIcons
)
343 CheckMenuRadioItem(hSubMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
345 CheckMenuRadioItem(hSubMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
347 TrackPopupMenu(hSubMenu
, TPM_LEFTALIGN
|TPM_TOPALIGN
|TPM_LEFTBUTTON
, pt
.x
, pt
.y
, 0, hMainWnd
, NULL
);
352 static void ApplicationPageShowContextMenu2(void)
360 hMenu
= LoadMenu(hInst
, MAKEINTRESOURCE(IDR_APPLICATION_PAGE_CONTEXT2
));
361 hSubMenu
= GetSubMenu(hMenu
, 0);
363 if (ListView_GetSelectedCount(hApplicationPageListCtrl
) == 1)
365 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
366 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
367 EnableMenuItem(hSubMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
368 EnableMenuItem(hSubMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
369 EnableMenuItem(hSubMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
370 EnableMenuItem(hSubMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_ENABLED
);
372 else if (ListView_GetSelectedCount(hApplicationPageListCtrl
) > 1)
374 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_ENABLED
);
375 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_ENABLED
);
376 EnableMenuItem(hSubMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
377 EnableMenuItem(hSubMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_ENABLED
);
378 EnableMenuItem(hSubMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_ENABLED
);
379 EnableMenuItem(hSubMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
383 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEHORIZONTALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
384 EnableMenuItem(hSubMenu
, ID_WINDOWS_TILEVERTICALLY
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
385 EnableMenuItem(hSubMenu
, ID_WINDOWS_MINIMIZE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
386 EnableMenuItem(hSubMenu
, ID_WINDOWS_MAXIMIZE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
387 EnableMenuItem(hSubMenu
, ID_WINDOWS_CASCADE
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
388 EnableMenuItem(hSubMenu
, ID_WINDOWS_BRINGTOFRONT
, MF_BYCOMMAND
|MF_DISABLED
|MF_GRAYED
);
391 SetMenuDefaultItem(hSubMenu
, ID_APPLICATION_PAGE_SWITCHTO
, MF_BYCOMMAND
);
393 TrackPopupMenu(hSubMenu
, TPM_LEFTALIGN
|TPM_TOPALIGN
|TPM_LEFTBUTTON
, pt
.x
, pt
.y
, 0, hMainWnd
, NULL
);
398 static int CALLBACK
ApplicationPageCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
400 LPAPPLICATION_PAGE_LIST_ITEM Param1
;
401 LPAPPLICATION_PAGE_LIST_ITEM Param2
;
403 if (bSortAscending
) {
404 Param1
= (LPAPPLICATION_PAGE_LIST_ITEM
)lParam1
;
405 Param2
= (LPAPPLICATION_PAGE_LIST_ITEM
)lParam2
;
407 Param1
= (LPAPPLICATION_PAGE_LIST_ITEM
)lParam2
;
408 Param2
= (LPAPPLICATION_PAGE_LIST_ITEM
)lParam1
;
410 return strcmpW(Param1
->wszTitle
, Param2
->wszTitle
);
413 static void ApplicationPageOnNotify(WPARAM wParam
, LPARAM lParam
)
419 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
;
421 static const WCHAR wszNotResponding
[] = {'N','o','t',' ','R','e','s','p','o','n','d','i','n','g',0};
422 static const WCHAR wszRunning
[] = {'R','u','n','n','i','n','g',0};
425 idctrl
= (int) wParam
;
426 pnmh
= (LPNMHDR
) lParam
;
427 pnmv
= (LPNM_LISTVIEW
) lParam
;
428 pnmdi
= (LV_DISPINFOW
*) lParam
;
430 if (pnmh
->hwndFrom
== hApplicationPageListCtrl
) {
431 switch (pnmh
->code
) {
432 case LVN_ITEMCHANGED
:
433 ApplicationPageUpdate();
436 case LVN_GETDISPINFOW
:
437 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)pnmdi
->item
.lParam
;
439 /* Update the item text */
440 if (pnmdi
->item
.iSubItem
== 0)
442 lstrcpynW(pnmdi
->item
.pszText
, pAPLI
->wszTitle
, pnmdi
->item
.cchTextMax
);
445 /* Update the item status */
446 else if (pnmdi
->item
.iSubItem
== 1)
449 lstrcpynW(pnmdi
->item
.pszText
, wszNotResponding
, pnmdi
->item
.cchTextMax
);
451 lstrcpynW(pnmdi
->item
.pszText
, wszRunning
, pnmdi
->item
.cchTextMax
);
458 if (ListView_GetSelectedCount(hApplicationPageListCtrl
) < 1)
460 ApplicationPageShowContextMenu1();
464 ApplicationPageShowContextMenu2();
471 ApplicationPage_OnSwitchTo();
476 else if (pnmh
->hwndFrom
== ListView_GetHeader(hApplicationPageListCtrl
))
482 if (ListView_GetSelectedCount(hApplicationPageListCtrl
) < 1)
484 ApplicationPageShowContextMenu1();
488 ApplicationPageShowContextMenu2();
495 SendMessageW(hApplicationPageListCtrl
, LVM_SORTITEMS
, 0, (LPARAM
) ApplicationPageCompareFunc
);
496 bSortAscending
= !bSortAscending
;
505 ApplicationPageWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
513 static const WCHAR wszTasks
[] = {'T','a','s','k','s',0};
514 static WCHAR wszTask
[] = {'T','a','s','k',0};
515 static WCHAR wszStatus
[] = {'S','t','a','t','u','s',0};
520 /* Save the width and height */
521 GetClientRect(hDlg
, &rc
);
522 nApplicationPageWidth
= rc
.right
;
523 nApplicationPageHeight
= rc
.bottom
;
525 /* Update window position */
526 SetWindowPos(hDlg
, NULL
, 15, 30, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
528 /* Get handles to the controls */
529 hApplicationPageListCtrl
= GetDlgItem(hDlg
, IDC_APPLIST
);
530 hApplicationPageEndTaskButton
= GetDlgItem(hDlg
, IDC_ENDTASK
);
531 hApplicationPageSwitchToButton
= GetDlgItem(hDlg
, IDC_SWITCHTO
);
532 hApplicationPageNewTaskButton
= GetDlgItem(hDlg
, IDC_NEWTASK
);
534 SetWindowTextW(hApplicationPageListCtrl
, wszTasks
);
536 /* Initialize the application page's controls */
537 column
.mask
= LVCF_TEXT
|LVCF_WIDTH
;
538 column
.pszText
= wszTask
;
540 /* Add the "Task" column */
541 SendMessageW(hApplicationPageListCtrl
, LVM_INSERTCOLUMNW
, 0, (LPARAM
) &column
);
542 column
.mask
= LVCF_TEXT
|LVCF_WIDTH
;
543 column
.pszText
= wszStatus
;
545 /* Add the "Status" column */
546 SendMessageW(hApplicationPageListCtrl
, LVM_INSERTCOLUMNW
, 1, (LPARAM
) &column
);
548 SendMessageW(hApplicationPageListCtrl
, LVM_SETIMAGELIST
, LVSIL_SMALL
,
549 (LPARAM
) ImageList_Create(16, 16, ILC_COLOR8
|ILC_MASK
, 0, 1));
550 SendMessageW(hApplicationPageListCtrl
, LVM_SETIMAGELIST
, LVSIL_NORMAL
,
551 (LPARAM
) ImageList_Create(32, 32, ILC_COLOR8
|ILC_MASK
, 0, 1));
553 UpdateApplicationListControlViewSetting();
555 /* Start our refresh thread */
556 CreateThread(NULL
, 0, ApplicationPageRefreshThread
, NULL
, 0, NULL
);
561 /* Close the event handle, this will make the */
562 /* refresh thread exit when the wait fails */
563 CloseHandle(hApplicationPageEvent
);
568 /* Handle the button clicks */
569 switch (LOWORD(wParam
))
572 ApplicationPage_OnEndTask();
575 ApplicationPage_OnSwitchTo();
578 SendMessageW(hMainWnd
, WM_COMMAND
, MAKEWPARAM(ID_FILE_NEW
, 0), 0);
585 if (wParam
== SIZE_MINIMIZED
)
590 nXDifference
= cx
- nApplicationPageWidth
;
591 nYDifference
= cy
- nApplicationPageHeight
;
592 nApplicationPageWidth
= cx
;
593 nApplicationPageHeight
= cy
;
595 /* Reposition the application page's controls */
596 GetWindowRect(hApplicationPageListCtrl
, &rc
);
597 cx
= (rc
.right
- rc
.left
) + nXDifference
;
598 cy
= (rc
.bottom
- rc
.top
) + nYDifference
;
599 SetWindowPos(hApplicationPageListCtrl
, NULL
, 0, 0, cx
, cy
, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOMOVE
|SWP_NOZORDER
);
600 InvalidateRect(hApplicationPageListCtrl
, NULL
, TRUE
);
602 GetClientRect(hApplicationPageEndTaskButton
, &rc
);
603 MapWindowPoints(hApplicationPageEndTaskButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
604 cx
= rc
.left
+ nXDifference
;
605 cy
= rc
.top
+ nYDifference
;
606 SetWindowPos(hApplicationPageEndTaskButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
607 InvalidateRect(hApplicationPageEndTaskButton
, NULL
, TRUE
);
609 GetClientRect(hApplicationPageSwitchToButton
, &rc
);
610 MapWindowPoints(hApplicationPageSwitchToButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
611 cx
= rc
.left
+ nXDifference
;
612 cy
= rc
.top
+ nYDifference
;
613 SetWindowPos(hApplicationPageSwitchToButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
614 InvalidateRect(hApplicationPageSwitchToButton
, NULL
, TRUE
);
616 GetClientRect(hApplicationPageNewTaskButton
, &rc
);
617 MapWindowPoints(hApplicationPageNewTaskButton
, hDlg
, (LPPOINT
)(&rc
), (sizeof(RECT
)/sizeof(POINT
)) );
618 cx
= rc
.left
+ nXDifference
;
619 cy
= rc
.top
+ nYDifference
;
620 SetWindowPos(hApplicationPageNewTaskButton
, NULL
, cx
, cy
, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
621 InvalidateRect(hApplicationPageNewTaskButton
, NULL
, TRUE
);
626 ApplicationPageOnNotify(wParam
, lParam
);
634 void RefreshApplicationPage(void)
636 /* Signal the event so that our refresh thread */
637 /* will wake up and refresh the application page */
638 SetEvent(hApplicationPageEvent
);
641 void UpdateApplicationListControlViewSetting(void)
643 DWORD dwStyle
= GetWindowLong(hApplicationPageListCtrl
, GWL_STYLE
);
645 dwStyle
&= ~LVS_REPORT
;
646 dwStyle
&= ~LVS_ICON
;
647 dwStyle
&= ~LVS_LIST
;
648 dwStyle
&= ~LVS_SMALLICON
;
650 if (TaskManagerSettings
.View_LargeIcons
)
652 else if (TaskManagerSettings
.View_SmallIcons
)
653 dwStyle
|= LVS_SMALLICON
;
655 dwStyle
|= LVS_REPORT
;
657 SetWindowLong(hApplicationPageListCtrl
, GWL_STYLE
, dwStyle
);
659 RefreshApplicationPage();
662 void ApplicationPage_OnViewLargeIcons(void)
667 hMenu
= GetMenu(hMainWnd
);
668 hViewMenu
= GetSubMenu(hMenu
, 2);
670 TaskManagerSettings
.View_LargeIcons
= TRUE
;
671 TaskManagerSettings
.View_SmallIcons
= FALSE
;
672 TaskManagerSettings
.View_Details
= FALSE
;
673 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_LARGE
, MF_BYCOMMAND
);
675 UpdateApplicationListControlViewSetting();
678 void ApplicationPage_OnViewSmallIcons(void)
683 hMenu
= GetMenu(hMainWnd
);
684 hViewMenu
= GetSubMenu(hMenu
, 2);
686 TaskManagerSettings
.View_LargeIcons
= FALSE
;
687 TaskManagerSettings
.View_SmallIcons
= TRUE
;
688 TaskManagerSettings
.View_Details
= FALSE
;
689 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_SMALL
, MF_BYCOMMAND
);
691 UpdateApplicationListControlViewSetting();
694 void ApplicationPage_OnViewDetails(void)
699 hMenu
= GetMenu(hMainWnd
);
700 hViewMenu
= GetSubMenu(hMenu
, 2);
702 TaskManagerSettings
.View_LargeIcons
= FALSE
;
703 TaskManagerSettings
.View_SmallIcons
= FALSE
;
704 TaskManagerSettings
.View_Details
= TRUE
;
705 CheckMenuRadioItem(hViewMenu
, ID_VIEW_LARGE
, ID_VIEW_DETAILS
, ID_VIEW_DETAILS
, MF_BYCOMMAND
);
707 UpdateApplicationListControlViewSetting();
710 void ApplicationPage_OnWindowsTileHorizontally(void)
712 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
718 hWndArray
= (HWND
*)malloc(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
);
741 void ApplicationPage_OnWindowsTileVertically(void)
743 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
749 hWndArray
= (HWND
*)malloc(sizeof(HWND
) * ListView_GetItemCount(hApplicationPageListCtrl
));
752 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
753 memset(&item
, 0, sizeof(LV_ITEMW
));
754 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
756 item
.stateMask
= (UINT
)-1;
757 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
759 if (item
.state
& LVIS_SELECTED
) {
760 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
762 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
768 TileWindows(NULL
, MDITILE_VERTICAL
, NULL
, nWndCount
, hWndArray
);
772 void ApplicationPage_OnWindowsMinimize(void)
774 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
778 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
779 memset(&item
, 0, sizeof(LV_ITEMW
));
780 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
782 item
.stateMask
= (UINT
)-1;
783 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
784 if (item
.state
& LVIS_SELECTED
) {
785 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
787 ShowWindow(pAPLI
->hWnd
, SW_MINIMIZE
);
793 void ApplicationPage_OnWindowsMaximize(void)
795 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
799 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
800 memset(&item
, 0, sizeof(LV_ITEMW
));
801 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
803 item
.stateMask
= (UINT
)-1;
804 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
805 if (item
.state
& LVIS_SELECTED
) {
806 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
808 ShowWindow(pAPLI
->hWnd
, SW_MAXIMIZE
);
814 void ApplicationPage_OnWindowsCascade(void)
816 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
822 hWndArray
= (HWND
*)malloc(sizeof(HWND
) * ListView_GetItemCount(hApplicationPageListCtrl
));
825 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
826 memset(&item
, 0, sizeof(LV_ITEMW
));
827 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
829 item
.stateMask
= (UINT
)-1;
830 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
831 if (item
.state
& LVIS_SELECTED
) {
832 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
834 hWndArray
[nWndCount
] = pAPLI
->hWnd
;
839 CascadeWindows(NULL
, 0, NULL
, nWndCount
, hWndArray
);
843 void ApplicationPage_OnWindowsBringToFront(void)
845 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
849 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
850 memset(&item
, 0, sizeof(LV_ITEMW
));
851 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
853 item
.stateMask
= (UINT
)-1;
854 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
855 if (item
.state
& LVIS_SELECTED
) {
856 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
861 if (IsIconic(pAPLI
->hWnd
))
862 ShowWindow(pAPLI
->hWnd
, SW_RESTORE
);
863 BringWindowToTop(pAPLI
->hWnd
);
867 void ApplicationPage_OnSwitchTo(void)
869 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
873 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
874 memset(&item
, 0, sizeof(LV_ITEMW
));
875 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
877 item
.stateMask
= (UINT
)-1;
878 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
880 if (item
.state
& LVIS_SELECTED
) {
881 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
886 typedef void (WINAPI
*PROCSWITCHTOTHISWINDOW
) (HWND
, BOOL
);
887 PROCSWITCHTOTHISWINDOW SwitchToThisWindow
;
889 HMODULE hUser32
= GetModuleHandleW(wszUser32
);
890 SwitchToThisWindow
= (PROCSWITCHTOTHISWINDOW
)GetProcAddress(hUser32
, "SwitchToThisWindow");
891 if (SwitchToThisWindow
) {
892 SwitchToThisWindow(pAPLI
->hWnd
, TRUE
);
894 if (IsIconic(pAPLI
->hWnd
))
895 ShowWindow(pAPLI
->hWnd
, SW_RESTORE
);
896 BringWindowToTop(pAPLI
->hWnd
);
897 SetForegroundWindow(pAPLI
->hWnd
);
899 if (TaskManagerSettings
.MinimizeOnUse
)
900 ShowWindow(hMainWnd
, SW_MINIMIZE
);
904 void ApplicationPage_OnEndTask(void)
906 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
910 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
911 memset(&item
, 0, sizeof(LV_ITEMW
));
912 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
914 item
.stateMask
= (UINT
)-1;
915 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
916 if (item
.state
& LVIS_SELECTED
) {
917 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
919 PostMessage(pAPLI
->hWnd
, WM_CLOSE
, 0, 0);
925 void ApplicationPage_OnGotoProcess(void)
927 LPAPPLICATION_PAGE_LIST_ITEM pAPLI
= NULL
;
932 for (i
=0; i
<ListView_GetItemCount(hApplicationPageListCtrl
); i
++) {
933 memset(&item
, 0, sizeof(LV_ITEMW
));
934 item
.mask
= LVIF_STATE
|LVIF_PARAM
;
936 item
.stateMask
= (UINT
)-1;
937 SendMessageW(hApplicationPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &item
);
938 if (item
.state
& LVIS_SELECTED
) {
939 pAPLI
= (LPAPPLICATION_PAGE_LIST_ITEM
)item
.lParam
;
946 GetWindowThreadProcessId(pAPLI
->hWnd
, &dwProcessId
);
948 * Switch to the process tab
950 TabCtrl_SetCurFocus(hTabWnd
, 1);
952 * FIXME: Select the process item in the list
954 for (i
=0; i
<ListView_GetItemCount(hProcessPage
); i
++) {