⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memwatcher.cpp

📁 在Windows Mobile 5.0 Pocket PC下
💻 CPP
📖 第 1 页 / 共 2 页
字号:



// ****************************************************************************
// FILE: memwatcher.cpp
// ABTRACT: Main implementation file for the today item
// ****************************************************************************
//

#include "stdafx.h"


#define INVALID_HEIGHT            0xFFFFFFFF

// flags bits for options - we use negative logic to make the default (0)
// show both
#define FLAGS_HIDE_STORAGE    0x1
#define FLAGS_HIDE_PROGRAM    0x2


//global variables    
HICON               g_hIcon;
UINT                g_plugInHeight;
HINSTANCE           g_hInst;
HWND                g_hWnd;
BOOL                g_bFirstDisplay         = TRUE;
HWND                g_hStorageProgressBar;
HWND                g_hProgramProgressBar;
UINT                g_StorageMemUsed;
UINT                g_ProgramMemUsed;
BOOL                g_fShowStorage          = TRUE;
BOOL                g_fShowProgram          = TRUE;


// forward function declarations
static INT InitializeClasses();

/*************************************************************************/
/* Entry point for the dll                                                 */
/*************************************************************************/
BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:            
        
        // The DLL is being loaded for the first time by a given process.
        // Perform per-process initialization here.  If the initialization
        // is successful, return TRUE; if unsuccessful, return FALSE.
        g_hInst = (HINSTANCE)hModule;
        
        //load the icon
        g_hIcon = (HICON)LoadImage(g_hInst, MAKEINTRESOURCE(IDI_DISPLAYICON), IMAGE_ICON, DRA::SCALEX(16), DRA::SCALEY(16) ,LR_DEFAULTCOLOR);
        
        //initilize the application class, and set the global window handle
        UnregisterClass((LPCTSTR)LoadString(g_hInst, IDS_TODAY_STORAGE_APPNAME,0,0), g_hInst);
        InitializeClasses();
        g_hWnd = 0;
        
        break;
        
    case DLL_PROCESS_DETACH:
        // The DLL is being unloaded by a given process.  Do any
        // per-process clean up here, such as undoing what was done in
        // DLL_PROCESS_ATTACH.    The return value is ignored.
        
        DestroyIcon(g_hIcon);
        
        UnregisterClass((LPCTSTR)LoadString(g_hInst, IDS_TODAY_STORAGE_APPNAME,0,0), g_hInst);
        g_hInst = NULL;
        break;           
    }
    
    return TRUE;
}

/*************************************************************************/
/* Handle any messages that may be needed for the plugin                 */
/* Handled messages:                                                     */
/*        WM_TODAYCUSTOM_QUERYREFRESHCACHE                                 */
/*        WM_CREATE                                                         */
/*        WM_LBUTTONUP                                                     */
/*        WM_PAINT                                                         */
/*        WM_DESTROY                                                         */
/*************************************************************************/
LRESULT CALLBACK WndProc (HWND hwnd, UINT uimessage, WPARAM wParam, LPARAM lParam) 
{
    switch (uimessage)
    {          
        //check to see if a refresh is required
    case WM_TODAYCUSTOM_QUERYREFRESHCACHE: 
        {
            TODAYLISTITEM *ptliItem;
            MEMORYSTATUS MemStatus;
            STORE_INFORMATION StoreInfo;
            INT iItemHeight;
            
            UINT iCurrentStore;
            DOUBLE dCurrentStore;
            BOOL    bReturn = FALSE;
            
            // get the pointer to the item from the Today screen
            ptliItem = (TODAYLISTITEM*)wParam;

            if ((NULL == ptliItem) || (WaitForSingleObject(SHELL_API_READY_EVENT, 0) == WAIT_TIMEOUT))
            {
                return FALSE;
            }
            
            g_fShowStorage = !(ptliItem->grfFlags & FLAGS_HIDE_STORAGE);
            g_fShowProgram = !(ptliItem->grfFlags & FLAGS_HIDE_PROGRAM);

            // adjust the height of the today item based on showing one or two bars
            if (g_fShowProgram && g_fShowStorage)
            {
                iItemHeight = DRA::SCALEY(40);
            }
            else
            {
                iItemHeight = DRA::SCALEY(20);
            }
            
            // determine % memory space and see if it has changed
            GlobalMemoryStatus(&MemStatus);
            if(g_ProgramMemUsed != MemStatus.dwMemoryLoad)
            {
                g_ProgramMemUsed = MemStatus.dwMemoryLoad;
                bReturn = TRUE;
            }
            
            // determine % storage space and see if it has changed
            GetStoreInformation(&StoreInfo);
            dCurrentStore = ((((DOUBLE)StoreInfo.dwStoreSize - (DOUBLE)StoreInfo.dwFreeSize) / (DOUBLE)StoreInfo.dwStoreSize) * 100);
            iCurrentStore = (INT)dCurrentStore;
            
            if(g_StorageMemUsed != iCurrentStore)
            {
                g_StorageMemUsed = iCurrentStore;
                bReturn = TRUE;
            }
            
            if (0 == ptliItem->cyp)
            {
                ptliItem->cyp = iItemHeight;
                bReturn = TRUE;
            }
            
            return bReturn;
            
            
        }        
        
    case WM_CREATE:         
        break;
        
    case WM_LBUTTONUP: 
        MessageBox(NULL, TEXT("Detected Screen Tap!"), TEXT("StorageCheck Today Item:"), MB_OK);
        break;          
        
    case WM_PAINT: 
        PAINTSTRUCT     ps;
        RECT            rcWindBounds; 
        RECT            rcMyBounds;
        HDC             hDC;
        HFONT            hFontOld;
        TCHAR            szTextBuffer[10];
        COLORREF        crText;

        GetWindowRect( hwnd, &rcWindBounds); 
        
        hDC = BeginPaint(hwnd, &ps);
        
        // create a custom rectangle relative to the client area
        rcMyBounds.left = 0;
        rcMyBounds.top = DRA::SCALEY(2);
        rcMyBounds.right = rcWindBounds.right - rcWindBounds.left;
        rcMyBounds.bottom = rcWindBounds.bottom - rcWindBounds.top;          
        
        // draw the icon on the screen
        SetBkMode(hDC, TRANSPARENT);
        DrawIcon(hDC, 2, 0, g_hIcon);
        
        BOOL bIsFarEast;
        LOGFONT lf;
        HFONT hSysFont;
        HFONT hFont;

        //determine if this is a Far East platform
        switch (PRIMARYLANGID(LANGIDFROMLCID(GetSystemDefaultLCID())))
        {
        case LANG_CHINESE:
        case LANG_KOREAN:
        case LANG_JAPANESE:
            bIsFarEast = TRUE;
            break;
            
        default:
            bIsFarEast = FALSE;
            break;
        }

        hSysFont = (HFONT) GetStockObject(SYSTEM_FONT);
        GetObject(hSysFont, sizeof(LOGFONT), &lf);
        // If it is far east, use a normal font at 9 points,
        //  otherwise use a bold font as 8 points
        if (bIsFarEast)
        {
            lf.lfWeight = FW_NORMAL;
            // Calculate the font size, making sure to round the result to the nearest integer
            lf.lfHeight = (long) -((9.0 * (double)GetDeviceCaps(hDC, LOGPIXELSY) / 72.0)+.5);
        }
        else
        {
            lf.lfWeight = FW_BOLD;
            // Calculate the font size, making sure to round the result to the nearest integer
            lf.lfHeight = (long) -((8.0 * (double)GetDeviceCaps(hDC, LOGPIXELSY) / 72.0)+.5);
        }

        // create the font
        hFont = CreateFontIndirect(&lf);
    
        // Select the system font into the device context
        hFontOld = (HFONT) SelectObject(hDC, hFont);

        // determine the theme's current text color
        //  this color will change when the user picks a new theme,
        //  so get it each time the display needs to be painted
        crText = SendMessage(GetParent(hwnd), TODAYM_GETCOLOR, (WPARAM) TODAYCOLOR_TEXT, NULL);

        // set that color
        SetTextColor(hDC, crText);

        // determine if there is one or two bars to paint
        if(g_fShowProgram && g_fShowStorage)
        {
            // update and paint storage status bar
            SendMessage(g_hStorageProgressBar, PBM_SETPOS, g_StorageMemUsed, NULL);
            SetWindowPos(g_hStorageProgressBar, g_hWnd, DRA::SCALEX(85), DRA::SCALEY(4), DRA::SCALEX(120), DRA::SCALEY(10), SWP_SHOWWINDOW);
            
            // update and paint program status bar
            SendMessage(g_hProgramProgressBar, PBM_SETPOS, g_ProgramMemUsed, NULL);
            SetWindowPos(g_hProgramProgressBar, g_hWnd, DRA::SCALEX(85), DRA::SCALEY(24), DRA::SCALEX(120), DRA::SCALEY(10), SWP_SHOWWINDOW);

            // draw the storage item text

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -