📄 memplug.cpp
字号:
///////////////////////////////////////////////////////////////////////////////
//
// This is "Sample Code" and is distributable subject to the terms of the end
// user license agreement.
//
///////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <memory.h>
#include <ocidl.h>
#include <home.h>
#include "resource.h"
//#include <afxwin.h>
//#include <Winuser.h>
//#include "Afxwin.h"
/*
Add this to your .home.xml file to see this plugin:
If you are creating a new plugin based on this code
you absolutely must change the clsid!
<plugin clsid="{55EE36E7-7CC3-47e8-85E2-1D8644280E7A}">
</plugin>
*/
#define COMPILE_FLAG 2
ULONG g_dwDLLRefCount = 0;
#define INITGUID
#include "initguid.h"
HKEY hKeyIndexOfFocusIcon = NULL;
//{55EE36E7-7CC3-47e8-85E2-1D8644280E7A}
// If you are creating a new plugin based on this code
// you absolutely must change the clsid!
//7819499e-d8e8-4810-b749-c079339b9ee2
#if COMPILE_FLAG==0
#define IMAGENAME TEXT("homeskin4_0.dll")
DEFINE_GUID(CLSID_PLUGMEM,
0xc1ad3e7d, 0x29f2, 0x4109, 0x9c, 0x1e, 0x85, 0xf9, 0x71, 0x3, 0x20, 0x2);
#define CLSIDTEXT__PLUGMEM TEXT("C1AD3E7D-29F2-4109-9C1E-85F971032002")
#elif COMPILE_FLAG==1
#define IMAGENAME TEXT("homeskin4_1.dll")
DEFINE_GUID(CLSID_PLUGMEM,
0xbc1e2a88, 0xde4e, 0x4c08, 0x97, 0xf, 0x23, 0x43, 0x78, 0x1e, 0xda, 0xae);
#define CLSIDTEXT__PLUGMEM TEXT("BC1E2A88-DE4E-4c08-970F-2343781EDAAE")
#else
#define IMAGENAME TEXT("homeskin4_2.dll")
DEFINE_GUID(CLSID_PLUGMEM,
0xe5462248, 0x3bd5, 0x439d, 0xab, 0xbe, 0x4c, 0xb4, 0x7, 0x70, 0xce, 0x25);
#define CLSIDTEXT__PLUGMEM TEXT("E5462248-3BD5-439d-ABBE-4CB40770CE25")
#endif
// define all IID GUIDs
DEFINE_GUID(IID_IHomePlugin, 0x7F0C58E9, 0x4F30, 0x47bb, 0x96, 0x93, 0xd7, 0x78, 0xe9, 0x99, 0xc4, 0x33);
DEFINE_GUID(IID_IHomePluginEnvironment, 0xFF328DC0, 0x22F5, 0x4AC1, 0xA1, 0x03, 0x19, 0xB3, 0x89, 0xC6, 0x33, 0xFA);
DEFINE_GUID(IID_IHomePluginEnvironment2, 0xE01A8A84, 0xDDEF, 0x438e, 0x90, 0x04, 0x3F, 0xB2, 0xA9, 0x08, 0xE4, 0x65);
DEFINE_GUID(IID_IPersistStream, 0x00000109, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
DEFINE_GUID(IID_IPersist, 0x0000010c, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
DEFINE_GUID(IID_IObjectWithSite, 0xFC4801A3, 0x2BA9, 0x11CF, 0xA2, 0x29, 0x00, 0xAA, 0x00, 0x3D, 0x73, 0x52);
//#include "home.h"
#include <COGUID.H>
#undef INITGUID
//andy
#include <Tapi.h>
#include <extapi.h>
#include <Tsp.h>
#pragma comment( lib,"cellcore")
//hopper test
#include <tlhelp32.h>
#pragma comment (lib,"toolhelp.lib")
#include <cfgmgrapi.h>
#pragma comment (lib,"aygshell.lib")
#define HOMESCREEN_BITMAP
#define TOTALBALLICON 3
#define TOTALBITMAP 6
#define GET_INCREASED_BITMAP(i) (i>=TOTALBITMAP?0:i)
#define GET_DECREASED_BITMAP(i) (i<0?TOTALBITMAP-1:i)
#define TAPI_API_LOW_VERSION 0x00020000
#define TAPI_API_HIGH_VERSION 0x00020000
#define EXT_API_LOW_VERSION 0x00010000
#define EXT_API_HIGH_VERSION 0x00010000
#if 1
struct homeScreenBitmap
{
UINT xIcon;
UINT yIcon;
LPTSTR iconName;
UINT xBall;
UINT yBall;
}g_hsBitmap[TOTALBITMAP]=
{
{41+1,51-1,MAKEINTRESOURCE(IDI_ICON_MAIL),37,44},
{101+1,51+1,MAKEINTRESOURCE(IDI_ICON_CAMERA),97,44},
{11-1,99+5+1-1,MAKEINTRESOURCE(IDI_ICON_QQ),6,92+5},
{134+1,99+5+1,MAKEINTRESOURCE(IDI_ICON_SETTING),129,92+5},
{41+1,155+2,MAKEINTRESOURCE(IDI_ICON_HISTORY),37,148},
{101+2,155+1,MAKEINTRESOURCE(IDI_ICON_CALENDAR),97,148},
};
#else
struct homeScreenBitmap
{
UINT xIcon;
UINT yIcon;
LPTSTR iconName;
UINT xBall;
UINT yBall;
}g_hsBitmap[TOTALBITMAP]=
{
{40,49,MAKEINTRESOURCE(IDI_ICON_MAIL),33-1,37+1},
{101+1,49+1,MAKEINTRESOURCE(IDI_ICON_CAMERA),94,37+1},
{11,99,MAKEINTRESOURCE(IDI_ICON_WM),4,87},
{134+1,96+4,MAKEINTRESOURCE(IDI_ICON_SETTING),126,87},
{41,154+2,MAKEINTRESOURCE(IDI_ICON_HISTORY),33,143-1},
{102+2,154+2,MAKEINTRESOURCE(IDI_ICON_CALENDAR),94+2,143-1},
};
#endif
struct timeLocation
{
LONG xTime;
LONG yTime;
LONG widthTime;
LONG heightTime;
}g_timeLoc[5]=
{
{59+2,107,12,20},
{72+2,107,12,20},
{84+2,113,3,12},
{89+2,107,12,20},
{102+2,107,12,20}
};
static LPTSTR digitRource[10]=
{
MAKEINTRESOURCE(IDI_ICON_DIG_0),
MAKEINTRESOURCE(IDI_ICON_DIG_1),
MAKEINTRESOURCE(IDI_ICON_DIG_2),
MAKEINTRESOURCE(IDI_ICON_DIG_3),
MAKEINTRESOURCE(IDI_ICON_DIG_4),
MAKEINTRESOURCE(IDI_ICON_DIG_5),
MAKEINTRESOURCE(IDI_ICON_DIG_6),
MAKEINTRESOURCE(IDI_ICON_DIG_7),
MAKEINTRESOURCE(IDI_ICON_DIG_8),
MAKEINTRESOURCE(IDI_ICON_DIG_9)
};
static LPCTSTR progName[TOTALBITMAP]=
{
TEXT("\\windows\\tmail.exe"),
TEXT("\\Windows\\PhoneCamera.exe"),
TEXT("\\Storage\\Windows\\Start Menu\\QQ.lnk"),
TEXT("\\Windows\\settings.exe"),
TEXT("\\windows\\clog.exe"),
TEXT("\\Storage\\windows\\Start Menu\\Calendar.lnk")
};
static const LPTSTR ballName[TOTALBALLICON]={MAKEINTRESOURCE(IDI_ICON_BALL_A),MAKEINTRESOURCE(IDI_ICON_BALL_B),MAKEINTRESOURCE(IDI_ICON_BALL_C)};
static HDC g_hdc;
static UINT g_focusIconIndex,g_ballIndex;
static bool g_bSecondTurn,g_bFocusChange=false;
static UINT g_networkTimerID;
static SYSTEMTIME g_oldTime;
static TCHAR g_opertorName[32];
static RECT g_operatorRect;
static bool g_hasfoundOperator=false;
static HANDLE g_hEvent,g_hThread;
void ShowDebugInfo(TCHAR* buffer1,TCHAR* buffer2)
{
MessageBox(NULL,buffer1,buffer2,MB_OK);
}
void CreateLogFile(void)
{
#ifdef LOG_FILE
FILE *fw = fopen("\\Windows\\andy_log_file.txt","a+");
fprintf(fw,"\n");
fclose(fw);
#endif
}
BOOL isProcessRuning(LPCTSTR szRunName)
{
HANDLE hSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe;
if(hSnap == (HANDLE)-1)
DWORD dwError = GetLastError();
pe.dwSize = sizeof(pe);
BOOL bNext=Process32First(hSnap, &pe);
while(bNext)
{
if(wcsicmp(pe.szExeFile,szRunName)==0)
{
//program is running
CloseToolhelp32Snapshot (hSnap);
return TRUE;
}
bNext=Process32Next(hSnap, &pe);
}
CloseToolhelp32Snapshot (hSnap);
return FALSE;
}
void DrawBall(HDC hdc,UINT iconIndex,UINT ballIndex)
{
HICON hBall=LoadIcon(GetModuleHandle(IMAGENAME),ballName[ballIndex]);
//DrawIcon(hdc,g_hsBitmap[iconIndex].xBall,g_hsBitmap[iconIndex].yBall,hBall);
DrawIconEx(
hdc,//HDC hdc,
g_hsBitmap[iconIndex].xBall,//int xLeft,
g_hsBitmap[iconIndex].yBall,//int yTop,
hBall,//HICON hIcon,
41,//int cxWidth,
46,//int cyWidth,
0,//UINT istepIfAniCur,
NULL,//HBRUSH hbrFlickerFreeDraw,
DI_NORMAL//UINT diFlags
);
}
void DrawProgIcon(HDC hdc,UINT iconIndex)
{
HICON hIcon=LoadIcon(GetModuleHandle(IMAGENAME),g_hsBitmap[iconIndex].iconName);
DrawIcon(hdc,g_hsBitmap[iconIndex].xIcon,g_hsBitmap[iconIndex].yIcon,hIcon);
}
void DrawAllIcons(HDC hdc,bool bSelect)
{
if(COMPILE_FLAG==0)
{
if(g_focusIconIndex<2&&bSelect)
{
DrawBall(hdc,g_focusIconIndex,g_ballIndex);
}
for(int i=0;i<2;i++)
{
DrawProgIcon(hdc,i);
}
}
else if(COMPILE_FLAG==1)
{
if((g_focusIconIndex==2||g_focusIconIndex==3)&&bSelect)
{
DrawBall(hdc,g_focusIconIndex,g_ballIndex);
}
for(int i=2;i<4;i++)
{
DrawProgIcon(hdc,i);
}
}
else
{
if((g_focusIconIndex>=4&&g_focusIconIndex<TOTALBITMAP)&&bSelect)
{
DrawBall(hdc,g_focusIconIndex,g_ballIndex);
}
for(int i=4;i<TOTALBITMAP;i++)
{
DrawProgIcon(hdc,i);
}
}
}
void CALLBACK iconTimerProc(
HWND hwnd,
UINT uMsg,
UINT idEvent,
DWORD dwTime
)
{
if(g_ballIndex<TOTALBALLICON)
{
HDC hdc=GetDC(NULL);
if(!g_ballIndex)
{
DrawBall(hdc, g_focusIconIndex,g_ballIndex);
DrawProgIcon(hdc,g_focusIconIndex);
ReleaseDC(NULL,hdc);
return;
}
DrawBall(hdc, g_focusIconIndex,g_ballIndex);
DrawProgIcon(hdc,g_focusIconIndex);
ReleaseDC(NULL,hdc);
g_ballIndex++;
if(g_ballIndex>=TOTALBALLICON)
{
g_ballIndex=0;
}
}
}
VOID FAR PASCAL andylineCallbackFunc(
DWORD hDevice,
DWORD dwMsg,
DWORD dwCallbackInstance,
DWORD dwParam1,
DWORD dwParam2,
DWORD dwParam3
)
{
}
DWORD GetTSPLineDeviceID(const HLINEAPP hLineApp, const DWORD dwNumberDevices, const DWORD dwAPIVersionLow, const DWORD dwAPIVersionHigh, const TCHAR *const psTSPLineName)
{
DWORD dwReturn = 0xffffffff;
for(DWORD dwCurrentDevID = 0 ; dwCurrentDevID < dwNumberDevices ; dwCurrentDevID++)
{
DWORD dwAPIVersion;
LINEEXTENSIONID LineExtensionID;
if(0 == lineNegotiateAPIVersion(hLineApp, dwCurrentDevID,
dwAPIVersionLow, dwAPIVersionHigh,
&dwAPIVersion, &LineExtensionID))
{
LINEDEVCAPS LineDevCaps;
LineDevCaps.dwTotalSize = sizeof(LineDevCaps);
if(0 == lineGetDevCaps(hLineApp, dwCurrentDevID,
dwAPIVersion, 0, &LineDevCaps))
{
BYTE* pLineDevCapsBytes = new BYTE[LineDevCaps.dwNeededSize];
if(0 != pLineDevCapsBytes)
{
LINEDEVCAPS* pLineDevCaps = (LINEDEVCAPS*)pLineDevCapsBytes;
pLineDevCaps->dwTotalSize = LineDevCaps.dwNeededSize;
if(0 == lineGetDevCaps(hLineApp, dwCurrentDevID,
dwAPIVersion, 0, pLineDevCaps))
{
if(0 == _tcscmp((TCHAR*)((BYTE*)pLineDevCaps+pLineDevCaps->dwLineNameOffset),
psTSPLineName))
{
dwReturn = dwCurrentDevID;
}
}
delete[] pLineDevCapsBytes;
}
}
}
}
return dwReturn;
}
DWORD WINAPI ThreadProcGetOperatorName(LPVOID lpParameter)
{
HLINEAPP hLineApp;
HLINE hLine;
LINEINITIALIZEEXPARAMS liep = {0};
DWORD dwDevNum;
DWORD dwAPIVersion=TAPI_API_HIGH_VERSION;
LONG lResult;
static LINEOPERATOR lineOperator;
static LINEOPERATORSTATUS lineOperatorStatus;
DWORD dwTAPILineDeviceID = 0;
const DWORD dwMediaMode = LINEMEDIAMODE_DATAMODEM | LINEMEDIAMODE_INTERACTIVEVOICE;
RECT operatorRect;
while(true)
{
//WaitForSingleObject(g_hEvent,INFINITE);
// set the line init params
liep.dwTotalSize = sizeof(liep);
liep.dwOptions = LINEINITIALIZEEXOPTION_USEEVENT;
lResult=lineInitializeEx(
&hLineApp,
GetModuleHandle(IMAGENAME),
andylineCallbackFunc,//NULL,
IMAGENAME,
&dwDevNum,
&dwAPIVersion,
&liep
);
if(lResult)
{
lineShutdown(hLineApp);
continue;
}
// get the device ID
dwTAPILineDeviceID = GetTSPLineDeviceID( hLineApp , dwDevNum , TAPI_API_LOW_VERSION ,
TAPI_API_HIGH_VERSION , CELLTSP_LINENAME_STRING ) ;
if ( 0xffffffff == dwTAPILineDeviceID )
{
lineShutdown(hLineApp);
continue;
}
if(!lResult)
{
lResult=lineOpen(
hLineApp,
dwTAPILineDeviceID,//DWORD dwDeviceID,
(LPHLINE)&hLine,
dwAPIVersion,
0,
NULL,
LINECALLPRIVILEGE_MONITOR + LINECALLPRIVILEGE_OWNER,
dwMediaMode,
NULL
);
}
else
{
lineShutdown(hLineApp);
continue;
}
if(!lResult)
{
lineOperator.dwIndex = LINEOPERATOR_USEFIRSTAVAILABLEINDEX;
lineOperator.dwValidFields = LINEOPFORMAT_ALPHALONG;
lResult=lineGetCurrentOperator(
hLine,
(LPLINEOPERATOR)&lineOperator
);
}
else
{
lineClose(hLine);
lineShutdown(hLineApp);
continue;
}
if(!lResult)
{
{
lineOperator.dwIndex = LINEOPERATOR_USEFIRSTAVAILABLEINDEX;
lineOperator.dwValidFields = LINEOPFORMAT_ALPHALONG;
//lineOperator.dwStatus = LINEOPSTATUS_CURRENT;
lResult=lineGetCurrentOperator(
hLine,
(LPLINEOPERATOR)&lineOperator
);
}
}
else
{
lineClose(hLine);
lineShutdown(hLineApp);
continue;
}
//backup the op name and rect
memset(g_opertorName,0,sizeof(g_opertorName));
if(wcslen(lineOperator.lpszLongName))
{
wcscpy(g_opertorName,lineOperator.lpszLongName);
}
else if(wcslen(lineOperator.lpszShortName))
{
wcscpy(g_opertorName,lineOperator.lpszShortName);
}
else if(wcslen(lineOperator.lpszNumName))
{
wcscpy(g_opertorName,lineOperator.lpszNumName);
}
else
{
wcscpy(g_opertorName,L"Searching");
}
lineClose(hLine);
lineShutdown(hLineApp);
Sleep(6000);
}
}
void drawOperator(HDC hdc)
{
DrawText(hdc, g_opertorName, -1, const_cast<RECT*>(&g_operatorRect),
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
void drawLastOperator(HDC hdc)
{
DrawText(hdc, g_opertorName, -1, const_cast<RECT*>(&g_operatorRect),
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
void DrawTimeAndDate(HDC hdc)
{
if(COMPILE_FLAG==1)
{
//draw the time
static SYSTEMTIME localTime;
static RECT timeRect[5],rect;
static LPTSTR timeDigCol[5];
UINT fstPartOfHour,secPartOfHour,fstPartOfMin,secPartOfMin;
HICON hIcon;
GetLocalTime(&localTime);
g_oldTime=localTime;
fstPartOfHour=localTime.wHour/10;
secPartOfHour=localTime.wHour%10;
fstPartOfMin=localTime.wMinute/10;
secPartOfMin=localTime.wMinute%10;
timeDigCol[0]=digitRource[fstPartOfHour];
timeDigCol[1]=digitRource[secPartOfHour];
timeDigCol[2]=MAKEINTRESOURCE(IDI_ICON_COL);
timeDigCol[3]=digitRource[fstPartOfMin];
timeDigCol[4]=digitRource[secPartOfMin];
rect.left=0;
rect.right=176;
rect.top=90;
rect.bottom=130;
TCHAR timeStr[50]={0};
TCHAR dateStr[50]={0};
swprintf(timeStr,L"%02d:%02d",localTime.wHour,localTime.wMinute);
swprintf(dateStr,L"%d/%d/%d",localTime.wYear,localTime.wMonth,localTime.wDay);
SetTextColor(hdc, RGB(255,255,255));
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = 28,//-30 * ::GetDeviceCaps(hdc, LOGPIXELSY) / 55;
lf.lfWeight = FW_BOLD;
GetTextFace(hdc,LF_FACESIZE,lf.lfFaceName);
HFONT hFont = CreateFontIndirect(&lf);
HFONT hOldFont =(HFONT) SelectObject(hdc,hFont);
DrawText(hdc, timeStr, -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
SelectObject(hdc, hOldFont);
DeleteObject(hFont);
rect.left=0;
rect.right=176;
rect.top=128;
rect.bottom=140;
DrawText(hdc, dateStr, -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
#if 0
for(int i=0;i<5;i++)
{
timeRect[i].left=g_timeLoc[i].xTime;
timeRect[i].top=g_timeLoc[i].yTime;
timeRect[i].right=g_timeLoc[i].xTime+g_timeLoc[i].widthTime;
timeRect[i].bottom=g_timeLoc[i].yTime+g_timeLoc[i].heightTime;
//DrawText(hdc, timeDigCol[i], -1, const_cast<RECT*>(&timeRect[i]),
// DT_SINGLELINE | DT_CENTER | DT_VCENTER);
hIcon=LoadIcon(GetModuleHandle(IMAGENAME),timeDigCol[i]);
DrawIcon(hdc,g_timeLoc[i].xTime,g_timeLoc[i].yTime,hIcon);
}
//draw the date
static wchar_t dateStr[80];
memset(dateStr,0,sizeof(dateStr));
wchar_t yearStr[20],monStr[20],dayStr[20];
_itow(localTime.wYear,yearStr,10);
_itow(localTime.wMonth,monStr,10);
_itow(localTime.wDay,dayStr,10);
wcscpy(dateStr,yearStr);
wcscat(dateStr,(const wchar_t *)"/");
wcscat(dateStr,monStr);
wcscat(dateStr,(const wchar_t *)"/");
wcscat(dateStr,dayStr);
RECT dateRect;
dateRect.left=0;
dateRect.top=129;
dateRect.right=176;
dateRect.bottom=dateRect.top+10;
DrawText(hdc, dateStr, -1, const_cast<RECT*>(&dateRect),
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
#endif
}
}
#if 0
void CALLBACK networkAndTimeDateTimerProc(
HWND hwnd,
UINT uMsg,
UINT idEvent,
DWORD dwTime
)
{
HDC hdc=GetDC(NULL);
//HDC hdc=g_hdc;
SYSTEMTIME oldTime,newTime;
oldTime=g_oldTime;
GetLocalTime(&newTime);
if((oldTime.wYear==newTime.wYear)&&(oldTime.wMonth==newTime.wMonth)
&&(oldTime.wDay==newTime.wDay)&&(oldTime.wHour==newTime.wHour)
&&(oldTime.wMinute==newTime.wMinute))
{
SetBkMode(hdc, TRANSPARENT);
SetTextColor( hdc, RGB(255,255,255));
DrawTimeAndDate(hdc);
drawOperator(hdc);
//SetBkMode(hdc, oldBkMode);
}
ReleaseDC(NULL,hdc);
}
#endif
void HomeScreenRelease(void)
{
if(g_hThread)
{
TerminateThread(g_hThread, 0);
CloseHandle(g_hThread);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -