Commit b01a1c6f authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

taskmgr: Reorder functions to avoid forward declarations.

parent b72013d6
......@@ -48,14 +48,6 @@ static int nApplicationPageWidth;
static int nApplicationPageHeight;
static HANDLE hApplicationPageEvent = NULL; /* When this event becomes signaled then we refresh the app list */
static BOOL bSortAscending = TRUE;
static DWORD WINAPI ApplicationPageRefreshThread(void *lpParameter);
static BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam);
static void AddOrUpdateHwnd(HWND hWnd, TCHAR *szTitle, HICON hIcon, BOOL bHung);
static void ApplicationPageUpdate(void);
static void ApplicationPageOnNotify(WPARAM wParam, LPARAM lParam);
static void ApplicationPageShowContextMenu1(void);
static void ApplicationPageShowContextMenu2(void);
static int CALLBACK ApplicationPageCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
#if 0
void SwitchToThisWindow (
......@@ -64,252 +56,61 @@ BOOL bRestore /* Restore the window if it is minimized */
);
#endif
INT_PTR CALLBACK
ApplicationPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
static void ApplicationPageUpdate(void)
{
RECT rc;
int nXDifference;
int nYDifference;
LV_COLUMN column;
TCHAR szTemp[256];
int cx, cy;
switch (message) {
case WM_INITDIALOG:
/* Save the width and height */
GetClientRect(hDlg, &rc);
nApplicationPageWidth = rc.right;
nApplicationPageHeight = rc.bottom;
/* Update window position */
SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
/* Get handles to the controls */
hApplicationPageListCtrl = GetDlgItem(hDlg, IDC_APPLIST);
hApplicationPageEndTaskButton = GetDlgItem(hDlg, IDC_ENDTASK);
hApplicationPageSwitchToButton = GetDlgItem(hDlg, IDC_SWITCHTO);
hApplicationPageNewTaskButton = GetDlgItem(hDlg, IDC_NEWTASK);
SetWindowText(hApplicationPageListCtrl, _T("Tasks"));
/* Initialize the application page's controls */
column.mask = LVCF_TEXT|LVCF_WIDTH;
_tcscpy(szTemp, _T("Task"));
column.pszText = szTemp;
column.cx = 250;
/* Add the "Task" column */
SendMessage(hApplicationPageListCtrl, LVM_INSERTCOLUMN, 0, (LPARAM) &column);
column.mask = LVCF_TEXT|LVCF_WIDTH;
_tcscpy(szTemp, _T("Status"));
column.pszText = szTemp;
column.cx = 95;
/* Add the "Status" column */
SendMessage(hApplicationPageListCtrl, LVM_INSERTCOLUMN, 1, (LPARAM) &column);
SendMessage(hApplicationPageListCtrl, LVM_SETIMAGELIST, LVSIL_SMALL,
(LPARAM) ImageList_Create(16, 16, ILC_COLOR8|ILC_MASK, 0, 1));
SendMessage(hApplicationPageListCtrl, LVM_SETIMAGELIST, LVSIL_NORMAL,
(LPARAM) ImageList_Create(32, 32, ILC_COLOR8|ILC_MASK, 0, 1));
UpdateApplicationListControlViewSetting();
/* Start our refresh thread */
CreateThread(NULL, 0, ApplicationPageRefreshThread, NULL, 0, NULL);
return TRUE;
case WM_DESTROY:
/* Close the event handle, this will make the */
/* refresh thread exit when the wait fails */
CloseHandle(hApplicationPageEvent);
break;
case WM_COMMAND:
/* Handle the button clicks */
switch (LOWORD(wParam))
{
case IDC_ENDTASK:
ApplicationPage_OnEndTask();
break;
case IDC_SWITCHTO:
ApplicationPage_OnSwitchTo();
break;
case IDC_NEWTASK:
SendMessage(hMainWnd, WM_COMMAND, MAKEWPARAM(ID_FILE_NEW, 0), 0);
break;
}
break;
case WM_SIZE:
if (wParam == SIZE_MINIMIZED)
return 0;
cx = LOWORD(lParam);
cy = HIWORD(lParam);
nXDifference = cx - nApplicationPageWidth;
nYDifference = cy - nApplicationPageHeight;
nApplicationPageWidth = cx;
nApplicationPageHeight = cy;
/* Reposition the application page's controls */
GetWindowRect(hApplicationPageListCtrl, &rc);
cx = (rc.right - rc.left) + nXDifference;
cy = (rc.bottom - rc.top) + nYDifference;
SetWindowPos(hApplicationPageListCtrl, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
InvalidateRect(hApplicationPageListCtrl, NULL, TRUE);
GetClientRect(hApplicationPageEndTaskButton, &rc);
MapWindowPoints(hApplicationPageEndTaskButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
cx = rc.left + nXDifference;
cy = rc.top + nYDifference;
SetWindowPos(hApplicationPageEndTaskButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
InvalidateRect(hApplicationPageEndTaskButton, NULL, TRUE);
GetClientRect(hApplicationPageSwitchToButton, &rc);
MapWindowPoints(hApplicationPageSwitchToButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
cx = rc.left + nXDifference;
cy = rc.top + nYDifference;
SetWindowPos(hApplicationPageSwitchToButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
InvalidateRect(hApplicationPageSwitchToButton, NULL, TRUE);
GetClientRect(hApplicationPageNewTaskButton, &rc);
MapWindowPoints(hApplicationPageNewTaskButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
cx = rc.left + nXDifference;
cy = rc.top + nYDifference;
SetWindowPos(hApplicationPageNewTaskButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
InvalidateRect(hApplicationPageNewTaskButton, NULL, TRUE);
break;
case WM_NOTIFY:
ApplicationPageOnNotify(wParam, lParam);
break;
/* Enable or disable the "End Task" & "Switch To" buttons */
if (ListView_GetSelectedCount(hApplicationPageListCtrl))
{
EnableWindow(hApplicationPageEndTaskButton, TRUE);
EnableWindow(hApplicationPageSwitchToButton, TRUE);
}
return 0;
}
void RefreshApplicationPage(void)
{
/* Signal the event so that our refresh thread */
/* will wake up and refresh the application page */
SetEvent(hApplicationPageEvent);
}
void UpdateApplicationListControlViewSetting(void)
{
DWORD dwStyle = GetWindowLong(hApplicationPageListCtrl, GWL_STYLE);
dwStyle &= ~LVS_REPORT;
dwStyle &= ~LVS_ICON;
dwStyle &= ~LVS_LIST;
dwStyle &= ~LVS_SMALLICON;
if (TaskManagerSettings.View_LargeIcons)
dwStyle |= LVS_ICON;
else if (TaskManagerSettings.View_SmallIcons)
dwStyle |= LVS_SMALLICON;
else
dwStyle |= LVS_REPORT;
SetWindowLong(hApplicationPageListCtrl, GWL_STYLE, dwStyle);
RefreshApplicationPage();
}
static DWORD WINAPI ApplicationPageRefreshThread(void *lpParameter)
{
/* Create the event */
hApplicationPageEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
/* If we couldn't create the event then exit the thread */
if (!hApplicationPageEvent)
return 0;
while (1)
{
DWORD dwWaitVal;
/* Wait on the event */
dwWaitVal = WaitForSingleObject(hApplicationPageEvent, INFINITE);
/* If the wait failed then the event object must have been */
/* closed and the task manager is exiting so exit this thread */
if (dwWaitVal == WAIT_FAILED)
return 0;
if (dwWaitVal == WAIT_OBJECT_0)
{
/* Reset our event */
ResetEvent(hApplicationPageEvent);
/*
* FIXME:
*
* Should this be EnumDesktopWindows() instead?
*/
EnumWindows(EnumWindowsProc, 0);
}
EnableWindow(hApplicationPageEndTaskButton, FALSE);
EnableWindow(hApplicationPageSwitchToButton, FALSE);
}
}
static BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
HICON hIcon;
TCHAR szText[260];
BOOL bLargeIcon;
BOOL bHung = FALSE;
typedef int (__stdcall *IsHungAppWindowProc)(HWND);
IsHungAppWindowProc IsHungAppWindow;
/* Skip our window */
if (hWnd == hMainWnd)
return TRUE;
bLargeIcon = TaskManagerSettings.View_LargeIcons ? TRUE : FALSE;
GetWindowText(hWnd, szText, 260); /* Get the window text */
/* Check and see if this is a top-level app window */
if ((_tcslen(szText) <= 0) ||
!IsWindowVisible(hWnd) ||
(GetParent(hWnd) != NULL) ||
(GetWindow(hWnd, GW_OWNER) != NULL) ||
(GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW))
/* If we are on the applications tab the the windows menu will */
/* be present on the menu bar so enable & disable the menu items */
if (TabCtrl_GetCurSel(hTabWnd) == 0)
{
return TRUE; /* Skip this window */
}
HMENU hMenu;
HMENU hWindowsMenu;
/* Get the icon for this window */
hIcon = NULL;
SendMessageTimeout(hWnd, WM_GETICON, bLargeIcon ? ICON_BIG /*1*/ : ICON_SMALL /*0*/, 0, 0, 1000, (PDWORD_PTR)&hIcon);
hMenu = GetMenu(hMainWnd);
hWindowsMenu = GetSubMenu(hMenu, 3);
if (!hIcon)
{
hIcon = (HICON)GetClassLongPtr(hWnd, bLargeIcon ? GCLP_HICON : GCLP_HICONSM);
if (!hIcon) hIcon = (HICON)GetClassLongPtr(hWnd, bLargeIcon ? GCLP_HICONSM : GCLP_HICON);
if (!hIcon) SendMessageTimeout(hWnd, WM_QUERYDRAGICON, 0, 0, 0, 1000, (PDWORD_PTR)&hIcon);
if (!hIcon) SendMessageTimeout(hWnd, WM_GETICON, bLargeIcon ? ICON_SMALL /*0*/ : ICON_BIG /*1*/, 0, 0, 1000, (PDWORD_PTR)&hIcon);
/* Only one item selected */
if (ListView_GetSelectedCount(hApplicationPageListCtrl) == 1)
{
EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_ENABLED);
}
/* More than one item selected */
else if (ListView_GetSelectedCount(hApplicationPageListCtrl) > 1)
{
EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
}
/* No items selected */
else
{
EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
}
}
if (!hIcon)
hIcon = LoadIcon(hInst, bLargeIcon ? MAKEINTRESOURCE(IDI_WINDOW) : MAKEINTRESOURCE(IDI_WINDOWSM));
bHung = FALSE;
IsHungAppWindow = (IsHungAppWindowProc)(FARPROC)GetProcAddress(GetModuleHandle(_T("USER32.DLL")), "IsHungAppWindow");
if (IsHungAppWindow)
bHung = IsHungAppWindow(hWnd);
AddOrUpdateHwnd(hWnd, szText, hIcon, bHung);
return TRUE;
}
static void AddOrUpdateHwnd(HWND hWnd, TCHAR *szTitle, HICON hIcon, BOOL bHung)
......@@ -434,61 +235,179 @@ static void AddOrUpdateHwnd(HWND hWnd, TCHAR *szTitle, HICON hIcon, BOOL bHung)
ApplicationPageUpdate();
}
static void ApplicationPageUpdate(void)
static BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
/* Enable or disable the "End Task" & "Switch To" buttons */
if (ListView_GetSelectedCount(hApplicationPageListCtrl))
HICON hIcon;
TCHAR szText[260];
BOOL bLargeIcon;
BOOL bHung = FALSE;
typedef int (__stdcall *IsHungAppWindowProc)(HWND);
IsHungAppWindowProc IsHungAppWindow;
/* Skip our window */
if (hWnd == hMainWnd)
return TRUE;
bLargeIcon = TaskManagerSettings.View_LargeIcons ? TRUE : FALSE;
GetWindowText(hWnd, szText, 260); /* Get the window text */
/* Check and see if this is a top-level app window */
if ((_tcslen(szText) <= 0) ||
!IsWindowVisible(hWnd) ||
(GetParent(hWnd) != NULL) ||
(GetWindow(hWnd, GW_OWNER) != NULL) ||
(GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW))
{
EnableWindow(hApplicationPageEndTaskButton, TRUE);
EnableWindow(hApplicationPageSwitchToButton, TRUE);
return TRUE; /* Skip this window */
}
else
/* Get the icon for this window */
hIcon = NULL;
SendMessageTimeout(hWnd, WM_GETICON, bLargeIcon ? ICON_BIG /*1*/ : ICON_SMALL /*0*/, 0, 0, 1000, (PDWORD_PTR)&hIcon);
if (!hIcon)
{
EnableWindow(hApplicationPageEndTaskButton, FALSE);
EnableWindow(hApplicationPageSwitchToButton, FALSE);
hIcon = (HICON)GetClassLongPtr(hWnd, bLargeIcon ? GCLP_HICON : GCLP_HICONSM);
if (!hIcon) hIcon = (HICON)GetClassLongPtr(hWnd, bLargeIcon ? GCLP_HICONSM : GCLP_HICON);
if (!hIcon) SendMessageTimeout(hWnd, WM_QUERYDRAGICON, 0, 0, 0, 1000, (PDWORD_PTR)&hIcon);
if (!hIcon) SendMessageTimeout(hWnd, WM_GETICON, bLargeIcon ? ICON_SMALL /*0*/ : ICON_BIG /*1*/, 0, 0, 1000, (PDWORD_PTR)&hIcon);
}
/* If we are on the applications tab the the windows menu will */
/* be present on the menu bar so enable & disable the menu items */
if (TabCtrl_GetCurSel(hTabWnd) == 0)
if (!hIcon)
hIcon = LoadIcon(hInst, bLargeIcon ? MAKEINTRESOURCE(IDI_WINDOW) : MAKEINTRESOURCE(IDI_WINDOWSM));
bHung = FALSE;
IsHungAppWindow = (IsHungAppWindowProc)(FARPROC)GetProcAddress(GetModuleHandle(_T("USER32.DLL")), "IsHungAppWindow");
if (IsHungAppWindow)
bHung = IsHungAppWindow(hWnd);
AddOrUpdateHwnd(hWnd, szText, hIcon, bHung);
return TRUE;
}
static DWORD WINAPI ApplicationPageRefreshThread(void *lpParameter)
{
/* Create the event */
hApplicationPageEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
/* If we couldn't create the event then exit the thread */
if (!hApplicationPageEvent)
return 0;
while (1)
{
HMENU hMenu;
HMENU hWindowsMenu;
DWORD dwWaitVal;
/* Wait on the event */
dwWaitVal = WaitForSingleObject(hApplicationPageEvent, INFINITE);
/* If the wait failed then the event object must have been */
/* closed and the task manager is exiting so exit this thread */
if (dwWaitVal == WAIT_FAILED)
return 0;
if (dwWaitVal == WAIT_OBJECT_0)
{
/* Reset our event */
ResetEvent(hApplicationPageEvent);
/*
* FIXME:
*
* Should this be EnumDesktopWindows() instead?
*/
EnumWindows(EnumWindowsProc, 0);
}
}
}
static void ApplicationPageShowContextMenu1(void)
{
HMENU hMenu;
HMENU hSubMenu;
POINT pt;
GetCursorPos(&pt);
hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_APPLICATION_PAGE_CONTEXT1));
hSubMenu = GetSubMenu(hMenu, 0);
if (TaskManagerSettings.View_LargeIcons)
CheckMenuRadioItem(hSubMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
else if (TaskManagerSettings.View_SmallIcons)
CheckMenuRadioItem(hSubMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
else
CheckMenuRadioItem(hSubMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL);
DestroyMenu(hMenu);
}
static void ApplicationPageShowContextMenu2(void)
{
HMENU hMenu;
HMENU hSubMenu;
POINT pt;
GetCursorPos(&pt);
hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_APPLICATION_PAGE_CONTEXT2));
hSubMenu = GetSubMenu(hMenu, 0);
if (ListView_GetSelectedCount(hApplicationPageListCtrl) == 1)
{
EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_ENABLED);
}
else if (ListView_GetSelectedCount(hApplicationPageListCtrl) > 1)
{
EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
}
else
{
EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
}
SetMenuDefaultItem(hSubMenu, ID_APPLICATION_PAGE_SWITCHTO, MF_BYCOMMAND);
hMenu = GetMenu(hMainWnd);
hWindowsMenu = GetSubMenu(hMenu, 3);
TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL);
/* Only one item selected */
if (ListView_GetSelectedCount(hApplicationPageListCtrl) == 1)
{
EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_ENABLED);
}
/* More than one item selected */
else if (ListView_GetSelectedCount(hApplicationPageListCtrl) > 1)
{
EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
}
/* No items selected */
else
{
EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hWindowsMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
}
DestroyMenu(hMenu);
}
static int CALLBACK ApplicationPageCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
LPAPPLICATION_PAGE_LIST_ITEM Param1;
LPAPPLICATION_PAGE_LIST_ITEM Param2;
if (bSortAscending) {
Param1 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam1;
Param2 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam2;
} else {
Param1 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam2;
Param2 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam1;
}
return _tcscmp(Param1->szTitle, Param2->szTitle);
}
static void ApplicationPageOnNotify(WPARAM wParam, LPARAM lParam)
......@@ -579,73 +498,161 @@ static void ApplicationPageOnNotify(WPARAM wParam, LPARAM lParam)
}
static void ApplicationPageShowContextMenu1(void)
INT_PTR CALLBACK
ApplicationPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
HMENU hMenu;
HMENU hSubMenu;
POINT pt;
RECT rc;
int nXDifference;
int nYDifference;
LV_COLUMN column;
TCHAR szTemp[256];
int cx, cy;
GetCursorPos(&pt);
switch (message) {
case WM_INITDIALOG:
hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_APPLICATION_PAGE_CONTEXT1));
hSubMenu = GetSubMenu(hMenu, 0);
/* Save the width and height */
GetClientRect(hDlg, &rc);
nApplicationPageWidth = rc.right;
nApplicationPageHeight = rc.bottom;
if (TaskManagerSettings.View_LargeIcons)
CheckMenuRadioItem(hSubMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_LARGE, MF_BYCOMMAND);
else if (TaskManagerSettings.View_SmallIcons)
CheckMenuRadioItem(hSubMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_SMALL, MF_BYCOMMAND);
else
CheckMenuRadioItem(hSubMenu, ID_VIEW_LARGE, ID_VIEW_DETAILS, ID_VIEW_DETAILS, MF_BYCOMMAND);
/* Update window position */
SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL);
/* Get handles to the controls */
hApplicationPageListCtrl = GetDlgItem(hDlg, IDC_APPLIST);
hApplicationPageEndTaskButton = GetDlgItem(hDlg, IDC_ENDTASK);
hApplicationPageSwitchToButton = GetDlgItem(hDlg, IDC_SWITCHTO);
hApplicationPageNewTaskButton = GetDlgItem(hDlg, IDC_NEWTASK);
DestroyMenu(hMenu);
SetWindowText(hApplicationPageListCtrl, _T("Tasks"));
/* Initialize the application page's controls */
column.mask = LVCF_TEXT|LVCF_WIDTH;
_tcscpy(szTemp, _T("Task"));
column.pszText = szTemp;
column.cx = 250;
/* Add the "Task" column */
SendMessage(hApplicationPageListCtrl, LVM_INSERTCOLUMN, 0, (LPARAM) &column);
column.mask = LVCF_TEXT|LVCF_WIDTH;
_tcscpy(szTemp, _T("Status"));
column.pszText = szTemp;
column.cx = 95;
/* Add the "Status" column */
SendMessage(hApplicationPageListCtrl, LVM_INSERTCOLUMN, 1, (LPARAM) &column);
SendMessage(hApplicationPageListCtrl, LVM_SETIMAGELIST, LVSIL_SMALL,
(LPARAM) ImageList_Create(16, 16, ILC_COLOR8|ILC_MASK, 0, 1));
SendMessage(hApplicationPageListCtrl, LVM_SETIMAGELIST, LVSIL_NORMAL,
(LPARAM) ImageList_Create(32, 32, ILC_COLOR8|ILC_MASK, 0, 1));
UpdateApplicationListControlViewSetting();
/* Start our refresh thread */
CreateThread(NULL, 0, ApplicationPageRefreshThread, NULL, 0, NULL);
return TRUE;
case WM_DESTROY:
/* Close the event handle, this will make the */
/* refresh thread exit when the wait fails */
CloseHandle(hApplicationPageEvent);
break;
case WM_COMMAND:
/* Handle the button clicks */
switch (LOWORD(wParam))
{
case IDC_ENDTASK:
ApplicationPage_OnEndTask();
break;
case IDC_SWITCHTO:
ApplicationPage_OnSwitchTo();
break;
case IDC_NEWTASK:
SendMessage(hMainWnd, WM_COMMAND, MAKEWPARAM(ID_FILE_NEW, 0), 0);
break;
}
break;
case WM_SIZE:
if (wParam == SIZE_MINIMIZED)
return 0;
cx = LOWORD(lParam);
cy = HIWORD(lParam);
nXDifference = cx - nApplicationPageWidth;
nYDifference = cy - nApplicationPageHeight;
nApplicationPageWidth = cx;
nApplicationPageHeight = cy;
/* Reposition the application page's controls */
GetWindowRect(hApplicationPageListCtrl, &rc);
cx = (rc.right - rc.left) + nXDifference;
cy = (rc.bottom - rc.top) + nYDifference;
SetWindowPos(hApplicationPageListCtrl, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
InvalidateRect(hApplicationPageListCtrl, NULL, TRUE);
GetClientRect(hApplicationPageEndTaskButton, &rc);
MapWindowPoints(hApplicationPageEndTaskButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
cx = rc.left + nXDifference;
cy = rc.top + nYDifference;
SetWindowPos(hApplicationPageEndTaskButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
InvalidateRect(hApplicationPageEndTaskButton, NULL, TRUE);
GetClientRect(hApplicationPageSwitchToButton, &rc);
MapWindowPoints(hApplicationPageSwitchToButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
cx = rc.left + nXDifference;
cy = rc.top + nYDifference;
SetWindowPos(hApplicationPageSwitchToButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
InvalidateRect(hApplicationPageSwitchToButton, NULL, TRUE);
GetClientRect(hApplicationPageNewTaskButton, &rc);
MapWindowPoints(hApplicationPageNewTaskButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
cx = rc.left + nXDifference;
cy = rc.top + nYDifference;
SetWindowPos(hApplicationPageNewTaskButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
InvalidateRect(hApplicationPageNewTaskButton, NULL, TRUE);
break;
case WM_NOTIFY:
ApplicationPageOnNotify(wParam, lParam);
break;
}
return 0;
}
static void ApplicationPageShowContextMenu2(void)
void RefreshApplicationPage(void)
{
HMENU hMenu;
HMENU hSubMenu;
POINT pt;
/* Signal the event so that our refresh thread */
/* will wake up and refresh the application page */
SetEvent(hApplicationPageEvent);
}
GetCursorPos(&pt);
void UpdateApplicationListControlViewSetting(void)
{
DWORD dwStyle = GetWindowLong(hApplicationPageListCtrl, GWL_STYLE);
hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_APPLICATION_PAGE_CONTEXT2));
hSubMenu = GetSubMenu(hMenu, 0);
dwStyle &= ~LVS_REPORT;
dwStyle &= ~LVS_ICON;
dwStyle &= ~LVS_LIST;
dwStyle &= ~LVS_SMALLICON;
if (ListView_GetSelectedCount(hApplicationPageListCtrl) == 1)
{
EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_ENABLED);
}
else if (ListView_GetSelectedCount(hApplicationPageListCtrl) > 1)
{
EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
}
if (TaskManagerSettings.View_LargeIcons)
dwStyle |= LVS_ICON;
else if (TaskManagerSettings.View_SmallIcons)
dwStyle |= LVS_SMALLICON;
else
{
EnableMenuItem(hSubMenu, ID_WINDOWS_TILEHORIZONTALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hSubMenu, ID_WINDOWS_TILEVERTICALLY, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hSubMenu, ID_WINDOWS_MINIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hSubMenu, ID_WINDOWS_MAXIMIZE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hSubMenu, ID_WINDOWS_CASCADE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
EnableMenuItem(hSubMenu, ID_WINDOWS_BRINGTOFRONT, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
}
SetMenuDefaultItem(hSubMenu, ID_APPLICATION_PAGE_SWITCHTO, MF_BYCOMMAND);
dwStyle |= LVS_REPORT;
TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL);
SetWindowLong(hApplicationPageListCtrl, GWL_STYLE, dwStyle);
DestroyMenu(hMenu);
RefreshApplicationPage();
}
void ApplicationPage_OnViewLargeIcons(void)
......@@ -944,18 +951,3 @@ void ApplicationPage_OnGotoProcess(void)
}
}
}
static int CALLBACK ApplicationPageCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
LPAPPLICATION_PAGE_LIST_ITEM Param1;
LPAPPLICATION_PAGE_LIST_ITEM Param2;
if (bSortAscending) {
Param1 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam1;
Param2 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam2;
} else {
Param1 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam2;
Param2 = (LPAPPLICATION_PAGE_LIST_ITEM)lParam1;
}
return _tcscmp(Param1->szTitle, Param2->szTitle);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment