//+-------------------------------------------------------------------------
//
//  TaskMan - NT TaskManager
//  Copyright (C) Microsoft
//
//  File:       TaskMan.H
//
//  History:    Nov-10-95   DavePl  Created
//
//--------------------------------------------------------------------------

#define WM_FINDPROC       (WM_USER + 1)
#define PM_NOTIFYWAITING  (WM_USER + 2)
#define PM_QUITTRAYTHREAD (WM_USER + 3)

extern  CRITICAL_SECTION  g_CSTrayThread;
extern  DWORD             g_idTrayThread;
extern  LONG              g_minWidth;
extern  LONG              g_minHeight;

DWORD TrayThreadMessageLoop(LPVOID);

#define TASK_PAGE 0
#define PROC_PAGE 1
#define PERF_PAGE 2
#define NUM_PAGES 3


#define MIN_DLG_SIZE_X 203
#define MIN_DLG_SIZE_Y 224
#define DLG_SCALE_X    4
#define DLG_SCALE_Y    8

//
// Process Page Column ID enumeration
//

typedef enum COLUMNID
{
    COL_IMAGENAME           = 0,
    COL_PID                 = 1,
    COL_CPU                 = 2,
    COL_CPUTIME             = 3,
    COL_MEMUSAGE            = 4,
    COL_MEMUSAGEDIFF        = 5,
    COL_PAGEFAULTS          = 6, 
    COL_PAGEFAULTSDIFF      = 7,
    COL_COMMITCHARGE        = 8,
    COL_PAGEDPOOL           = 9,
    COL_NONPAGEDPOOL        = 10,
    COL_BASEPRIORITY        = 11,
    COL_HANDLECOUNT         = 12,
    COL_THREADCOUNT         = 13
};


#define MAX_COLUMN      13
#define NUM_COLUMN      (MAX_COLUMN + 1)

#define IDS_FIRSTCOL    20001       // 20000 is first column name ID in rc file

// GetLastHRESULT
//
// Little wrapper func that returns the GetLastError value as an HRESULT

inline HRESULT GetLastHRESULT()
{
    return HRESULT_FROM_WIN32(GetLastError());
}

// Possible values for the viewmode

typedef enum 
{
    VM_LARGEICON,
    VM_SMALLICON,
    VM_DETAILS
} VIEWMODE;
#define VM_FIRST IDM_LARGEICONS
#define VM_LAST  IDM_DETAILS

// Possible values for the cpu history mode

typedef enum
{   
    CM_SUM,
    CM_PANES
} CPUHISTMODE;
#define CM_FIRST IDM_ALLCPUS
#define CM_LAST  IDM_MULTIGRAPH

// Possible values for the update speed option

typedef enum
{
    US_HIGH,
    US_NORMAL,
    US_LOW,
    US_PAUSED
} UPDATESPEED;
#define US_FIRST IDM_HIGH
#define US_LAST  IDM_PAUSED

// COptions
//
// App's persistent state across sessions, saved in the registry

class COptions
{
public:

    DWORD       m_cbSize;
    DWORD       m_dwTimerInterval;
    VIEWMODE    m_vmViewMode;
    CPUHISTMODE m_cmHistMode;
    UPDATESPEED m_usUpdateSpeed;
    RECT        m_rcWindow;
    INT         m_iCurrentPage;

    COLUMNID    m_ActiveProcCol[NUM_COLUMN + 1];
    INT         m_ColumnWidths[NUM_COLUMN + 1];

    BOOL        m_fMinimizeOnUse : 1;
    BOOL        m_fConfirmations : 1;
    BOOL        m_fAlwaysOnTop   : 1;
    BOOL        m_fKernelTimes   : 1;
    BOOL        m_fNoTitle       : 1;
    BOOL        m_fHideWhenMin   : 1;
    BOOL        m_fShow16Bit     : 1;

    BOOL        bUnused;
    BOOL        bUnused2;

    HRESULT     Load();
    HRESULT     Save();

    // SetDefaultValues
    //
    // Uses to init the options to a default state when the saved copy
    // cannot be found, is damaged, or is not the correct version

    void SetDefaultValues()
    {
        ZeroMemory(this, sizeof(COptions));

        m_cbSize           = sizeof(COptions);
    
        BOOL bScreenReader = FALSE;
        if (SystemParametersInfo(SPI_GETSCREENREADER, 0, (PVOID) &bScreenReader, 0) && bScreenReader)
        {
            // No automatic updates for machines with screen readers
            m_dwTimerInterval = 0;
        }
        else
        {
            m_dwTimerInterval  = 1000;            
        }
    
        m_vmViewMode       = VM_DETAILS;
        m_cmHistMode       = CM_PANES;
        m_usUpdateSpeed    = US_NORMAL;
        m_fMinimizeOnUse   = TRUE;
        m_fConfirmations   = TRUE;
        m_fAlwaysOnTop     = TRUE;
        m_fShow16Bit       = TRUE;
        
        m_iCurrentPage     = -1;
        m_rcWindow.top     = (GetSystemMetrics(SM_CYMAXIMIZED) - g_minHeight) / 2;
        m_rcWindow.left    = (GetSystemMetrics(SM_CXMAXIMIZED) - g_minWidth) / 2;
        m_rcWindow.bottom  = m_rcWindow.top + g_minHeight;
        m_rcWindow.right   = m_rcWindow.left + g_minWidth;

        // Columns which are visible, by default, in the process view

        m_ActiveProcCol[0] = COL_IMAGENAME;          
        m_ActiveProcCol[1] = COL_PID;                
        m_ActiveProcCol[2] = COL_CPU;                
        m_ActiveProcCol[3] = COL_CPUTIME;            
        m_ActiveProcCol[4] = COL_MEMUSAGE;           
        m_ActiveProcCol[5] = (COLUMNID) -1;

        // Set all of the columns widths to -1 
            
        FillMemory(m_ColumnWidths, sizeof(m_ColumnWidths), 0xFF);
    }

    COptions()
    {
        SetDefaultValues();
    }
};

// CTrayNotification
//
// Class to encapsulate all of the info needed to do a tray notification

class CTrayNotification
{
public:

    CTrayNotification()
    {
        ASSERT(0 && "Some bozo is using the default constuctor for CTrayNotification");
        ZeroMemory(this, sizeof(*this));
    }

    CTrayNotification(HWND    hWnd,
                      UINT    uCallbackMessage,
                      DWORD   Message,
                      HICON   hIcon,
                      LPTSTR  pszTip)
    {
        m_hWnd              = hWnd;
        m_uCallbackMessage  = uCallbackMessage;
        m_Message           = Message;
        m_hIcon             = hIcon;
        
        if (pszTip)
            lstrcpyn(m_szTip, pszTip, ARRAYSIZE(m_szTip));
        else
            m_szTip[0] = TEXT('\0');
    }

    HWND    m_hWnd;
    UINT    m_uCallbackMessage;
    DWORD   m_Message;
    HICON   m_hIcon;
    TCHAR   m_szTip[MAX_PATH];
};

BOOL DeliverTrayNotification(CTrayNotification * pNot);