?? memwatcher.cpp
字號:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// ****************************************************************************
// 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
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -