📄 main.cpp
字号:
lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,_T("SYSTEM\\GWE\\Menu\\PopFnt"),0,0,&hKey );
if ( lRet != ERROR_SUCCESS ) {
return ;
}
dwType = REG_DWORD ;
dwSize = sizeof( DWORD );
lRet = RegQueryValueEx( hKey,_T("CS"),0,&dwType,(LPBYTE)&dwVal,&dwSize );
if ( lRet != ERROR_SUCCESS ) {
RegCloseKey( hKey );
return ;
}
lf.lfCharSet = (BYTE)dwVal ;
dwType = REG_DWORD ;
dwSize = sizeof( DWORD );
lRet = RegQueryValueEx( hKey,_T("Wt"),0,&dwType,(LPBYTE)&dwVal,&dwSize );
if ( lRet != ERROR_SUCCESS ) {
RegCloseKey( hKey );
return ;
}
lf.lfWeight = dwVal ;
dwType = REG_DWORD ;
dwSize = sizeof( DWORD );
lRet = RegQueryValueEx( hKey,_T("It"),0,&dwType,(LPBYTE)&dwVal,&dwSize );
if ( lRet != ERROR_SUCCESS ) {
RegCloseKey( hKey );
return ;
}
lf.lfItalic = (BYTE)dwVal ;
dwType = REG_DWORD ;
dwSize = sizeof( DWORD );
lRet = RegQueryValueEx( hKey,_T("Ht"),0,&dwType,(LPBYTE)&dwVal,&dwSize );
if ( lRet != ERROR_SUCCESS ) {
RegCloseKey( hKey );
return ;
}
//lf.lfHeight = dwVal ;
lf.lfHeight = -(12 * GetDeviceCaps(ghMemDC,LOGPIXELSY)) / 96;
dwType = REG_SZ ;
dwSize = sizeof(lf.lfFaceName);
lRet = RegQueryValueEx( hKey,_T("Nm"),0,&dwType,(LPBYTE)lf.lfFaceName,&dwSize );
if ( lRet != ERROR_SUCCESS ) {
RegCloseKey( hKey );
return ;
}
RegCloseKey( hKey );
lf.lfPitchAndFamily = FF_DONTCARE ;
ghMenuFont = CreateFontIndirect( &lf );
}
/////////////////////////////////////////////////////////////////////////////
// calc required size for displaying strings
void GetTextNeedSize( HDC hDC,HFONT hFont,LPCTSTR lpText,SIZE* pSize )
{
HFONT hPrevFont ;
if ( hFont != NULL ) {
hPrevFont = (HFONT)SelectObject( hDC,hFont );
}
GetTextExtentPoint32( hDC,lpText,lstrlen(lpText),pSize );
if ( hFont != NULL ) {
SelectObject( hDC,hPrevFont );
}
pSize->cx += 4 ;
}
/////////////////////////////////////////////////////////////////////////////
BOOL Prepare( HWND hWnd )
{
// 愝掕抣偺庢傝崬傒偲僀儊乕僕偺儘乕僪
if ( !LoadImgResource(hWnd) ) {
return( FALSE );
}
// 椞堟寁嶼
CalcRect( hWnd );
// 摟夁僀儊乕僕傪嶌惉
for ( int iIdx = ITEM_ID_LOGO ; iIdx < ITEM_ID_MAX ; iIdx++ ) {
if ( iIdx == ITEM_ID_SIP ) {
continue ;
}
if ( gItemTbl[iIdx].hBmp ) {
//SetTransparent( gItemTbl[ITEM_ID_BG].hBmp,&gItemTbl[iIdx]/*,FALSE*/ );
}
}
return( TRUE );
}
/////////////////////////////////////////////////////////////////////////////
// create transparent image
void SetTransparent( HBITMAP hBGBmp,LPITEM_INFO_T pDst/*,BOOL bDisableImg*/ )
{
RGBTRIPLE rgb,rgbClr ;
RGBTRIPLE* pRgb ;
RGBTRIPLE* pRgbSrc ;
BITMAP bmpSrc,bmpDst ;
int iOffset ;
GetObject( pDst->hBmp,sizeof(bmpDst),&bmpDst );
if ( bmpDst.bmWidthBytes % 4 != 0 ) {
bmpDst.bmWidthBytes += (4 - bmpDst.bmWidthBytes % 4);
}
// color of transparent
rgbClr = *((RGBTRIPLE*)bmpDst.bmBits);
// exist gbimage?
if ( hBGBmp == NULL ) {
// bkcolor
COLORREF cr = GetSysColor( COLOR_ACTIVECAPTION );
rgb.rgbtRed = GetRValue( cr );
rgb.rgbtGreen = GetGValue( cr );
rgb.rgbtBlue = GetBValue( cr );
for ( int iLine = 0 ; iLine < bmpDst.bmHeight ; iLine++ ) {
pRgb = (RGBTRIPLE*)((LPBYTE)bmpDst.bmBits + bmpDst.bmWidthBytes*iLine);
for ( int iCol = 0 ; iCol < bmpDst.bmWidth ; iCol++,pRgb++ ) {
if ( (pRgb->rgbtBlue == rgbClr.rgbtBlue) &&
(pRgb->rgbtGreen == rgbClr.rgbtGreen) &&
(pRgb->rgbtRed == rgbClr.rgbtRed) ) {
*pRgb = rgb ;
}
}
}
return ;
}
GetObject( hBGBmp,sizeof(bmpSrc),&bmpSrc );
if ( bmpSrc.bmWidthBytes % 4 != 0 ) {
bmpSrc.bmWidthBytes += (4 - bmpSrc.bmWidthBytes % 4);
}
for ( int iLine = 0 ; iLine < bmpDst.bmHeight ; iLine++ ) {
pRgb = (RGBTRIPLE*)((LPBYTE)bmpDst.bmBits + bmpDst.bmWidthBytes*iLine);
iOffset = (iLine + bmpSrc.bmHeight - pDst->rc.bottom) * bmpSrc.bmWidthBytes ;
pRgbSrc = (RGBTRIPLE*)((LPBYTE)bmpSrc.bmBits + iOffset);
pRgbSrc += pDst->rc.left ;
for ( int iCol = 0 ; iCol < bmpDst.bmWidth ; iCol++,pRgb++,pRgbSrc++ ) {
if ( (pRgb->rgbtBlue == rgbClr.rgbtBlue) &&
(pRgb->rgbtGreen == rgbClr.rgbtGreen) &&
(pRgb->rgbtRed == rgbClr.rgbtRed) ) {
// over write bit
*pRgb = *pRgbSrc ;
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
// create graysclae
BOOL CreateDisableImage( HBITMAP hBmp )
{
BITMAP bmp ;
RGBTRIPLE rgbClr ;
RGBTRIPLE* pRgb ;
DWORD dwR ;
GetObject( hBmp,sizeof(bmp),&bmp );
rgbClr = *((RGBTRIPLE*)bmp.bmBits);
if ( bmp.bmWidthBytes % 4 != 0 ) {
bmp.bmWidthBytes += (4 - bmp.bmWidthBytes % 4);
}
for ( int iLine = 0 ; iLine < bmp.bmHeight ; iLine++ ) {
pRgb = (RGBTRIPLE*)((LPBYTE)bmp.bmBits + bmp.bmWidthBytes*iLine);
for ( int iCol = 0 ; iCol < bmp.bmWidth ; iCol++,pRgb++ ) {
if ( (pRgb->rgbtBlue != rgbClr.rgbtBlue) ||
(pRgb->rgbtGreen != rgbClr.rgbtGreen) ||
(pRgb->rgbtRed != rgbClr.rgbtRed) ) {
dwR = (DWORD)pRgb->rgbtRed + pRgb->rgbtGreen + pRgb->rgbtBlue ;
dwR /= 3 ;
pRgb->rgbtBlue = pRgb->rgbtGreen = pRgb->rgbtRed = (BYTE)dwR ;
}
}
}
return( TRUE );
}
/////////////////////////////////////////////////////////////////////////////
// draw clock
void DrawClock( RECT rcDraw )
{
COLORREF crTxtPrev ;
HFONT hFntPrev ;
TCHAR szTime[32];
RECT rcInt ;
SYSTEMTIME st ;
HBITMAP hPrevBmp = (HBITMAP)SelectObject( ghMemDC,ghBmpWork );
GetLocalTime( &st );
// small?
if ( gbSmallDate ) {
if ( IntersectRect(&rcInt,&gItemTbl[ITEM_ID_DATE].rc,&rcDraw) ) {
if ( gfntDate.hFont ) {
hFntPrev = (HFONT)SelectObject( ghMemDC,gfntDate.hFont );
}
if( use2002Fonts )
crTxtPrev = SetTextColor( ghMemDC,cr2002Fonts );
else
crTxtPrev = SetTextColor( ghMemDC,gfntDate.cr );
RECT rcDate = gItemTbl[ITEM_ID_DATE].rc ;
rcDate.top = 2 ;
rcDate.bottom /= 2 ;
// 00001 wsprintf( szTime,_T("%d/%d"),st.wMonth,st.wDay );
GetRegionalDate( szTime,sizeof(szTime)/sizeof(TCHAR),&st );
if (gCompactDateTime)
GetDateFormat( LOCALE_USER_DEFAULT,NULL,&st,_T("M'/'d'"),szTime,sizeof(szTime)/sizeof(TCHAR) );
DrawText( ghMemDC,szTime,lstrlen(szTime),&rcDate,DT_CENTER|DT_VCENTER );
rcDate.top = rcDate.bottom ;
rcDate.bottom += (rcDate.top - 2 );
if (gCompactDateTime)
GetTimeFormat( LOCALE_USER_DEFAULT,NULL,&st,_T("h':'mm'"),szTime,sizeof(szTime)/sizeof(TCHAR) );
else
GetTimeFormat( LOCALE_USER_DEFAULT,TIME_NOSECONDS,&st,NULL,szTime,sizeof(szTime)/sizeof(TCHAR) );
// wsprintf( szTime,_T("%d:%02d%s"),st.wHour,st.wMinute,szAMPM );
DrawText( ghMemDC,szTime,lstrlen(szTime),&rcDate,DT_CENTER|DT_VCENTER );
if ( gfntDate.hFont ) {
SelectObject( ghMemDC,hFntPrev );
}
SetTextColor( ghMemDC,crTxtPrev );
}
}
else {
// normal size date
if ( gdwDispItems & DISPITEM_DATE ) {
if ( IntersectRect(&rcInt,&gItemTbl[ITEM_ID_DATE].rc,&rcDraw) ) {
if ( gfntDate.hFont ) {
hFntPrev = (HFONT)SelectObject( ghMemDC,gfntDate.hFont );
}
if( use2002Fonts )
crTxtPrev = SetTextColor( ghMemDC,cr2002Fonts );
else
crTxtPrev = SetTextColor( ghMemDC,gfntDate.cr );
// 00001 wsprintf( szTime,_T("%d/%d"),st.wMonth,st.wDay );
GetRegionalDate( szTime,sizeof(szTime)/sizeof(TCHAR),&st );
if (gCompactDateTime)
GetDateFormat( LOCALE_USER_DEFAULT,NULL,&st,_T("M'/'d'"),szTime,sizeof(szTime)/sizeof(TCHAR) );
DrawText( ghMemDC,szTime,lstrlen(szTime),&gItemTbl[ITEM_ID_DATE].rc,DT_CENTER|DT_VCENTER );
if ( gfntDate.hFont ) {
SelectObject( ghMemDC,hFntPrev );
}
SetTextColor( ghMemDC,crTxtPrev );
}
}
if ( gdwDispItems & DISPITEM_CLOCK ) {
if ( IntersectRect(&rcInt,&gItemTbl[ITEM_ID_CLOCK].rc,&rcDraw) ) {
if ( gfntTime.hFont ) {
hFntPrev = (HFONT)SelectObject( ghMemDC,gfntTime.hFont );
}
if( use2002Fonts )
crTxtPrev = SetTextColor( ghMemDC,cr2002Fonts );
else
crTxtPrev = SetTextColor( ghMemDC,gfntTime.cr );
if (gCompactDateTime)
GetTimeFormat( LOCALE_USER_DEFAULT,NULL,&st,_T("h':'mm'"),szTime,sizeof(szTime)/sizeof(TCHAR) );
else
GetTimeFormat( LOCALE_USER_DEFAULT,TIME_NOSECONDS,&st,NULL,szTime,sizeof(szTime)/sizeof(TCHAR) );
// wsprintf( szTime,_T("%d:%02d%s"),st.wHour,st.wMinute,szAMPM );
DrawText( ghMemDC,szTime,lstrlen(szTime),&gItemTbl[ITEM_ID_CLOCK].rc,DT_CENTER|DT_VCENTER );
if ( gfntTime.hFont ) {
SelectObject( ghMemDC,hFntPrev );
}
SetTextColor( ghMemDC,crTxtPrev );
}
}
}
SelectObject( ghMemDC,hPrevBmp );
}
void DrawSystemState()
{
SYSTEM_POWER_STATUS_EX p;
int power_level;
int memory_level;
// Get the power state
ZeroMemory(&p, sizeof(p));
GetSystemPowerStatusEx(&p, true);
// Get the power state
if( p.BatteryFlag != 255 ) {
if( !(p.BatteryFlag & 128) ) {
if( p.BatteryLifePercent == 255 ) {
if( p.BatteryFlag != 255 ) {
if( p.BatteryFlag & 1 ) {
power_level = 9;
}
else if( p.BatteryFlag & 2 ) {
power_level = 4;
}
else if( p.BatteryFlag & 4 ) {
power_level = 1;
}
}
}
else {
power_level = p.BatteryLifePercent / 10 - 1 ;
}
}
}
else
power_level = 0;
// Get the memory state
MEMORYSTATUS m;
ZeroMemory(&m, sizeof(m));
m.dwLength = sizeof(m);
GlobalMemoryStatus(&m);
memory_level = ((m.dwAvailPhys * 10) / m.dwTotalPhys) - 1;
// Drawing variables
RGBTRIPLE *rgb;
RGBTRIPLE *rgb_dest;
RGBTRIPLE rgbLevel;
RGBTRIPLE rgbBad;
BITMAP bmp;
BITMAP bmp_dest;
// Create the status color
rgbLevel.rgbtRed = 0;
rgbLevel.rgbtGreen = 255;
rgbLevel.rgbtBlue = 128;
rgbBad.rgbtRed = 255;
rgbBad.rgbtGreen = 0;
rgbBad.rgbtBlue = 0;
// Get the bitmap information
GetObject(gItemTbl[ITEM_ID_SYSTEM].hBmp, sizeof(bmp_dest), &bmp_dest);
GetObject(ghSystem, sizeof(bmp), &bmp);
// Align the bitmap along word boundaries
if( bmp.bmWidthBytes % 4 != 0 )
bmp.bmWidthBytes += (4 - bmp.bmWidthBytes % 4);
for(int y = 0; y < bmp.bmHeight; y ++) {
rgb = (RGBTRIPLE*)((LPBYTE)bmp.bmBits + y * bmp.bmWidthBytes);
rgb_dest = (RGBTRIPLE*)((LPBYTE)bmp_dest.bmBits + y * bmp.bmWidthBytes);
for(int x = 0; x < bmp.bmWidth; x ++) {
// Draw the power level
if( (rgb[x].rgbtRed == 255) && (rgb[x].rgbtBlue == 255) &&
(rgb[x].rgbtGreen > 239) && (rgb[x].rgbtGreen < 250) ) {
if( rgb[x].rgbtGreen > 240 + power_level )
rgb_dest[x] = rgbBad;
else
rgb_dest[x] = rgbLevel;
}
// Draw the memory level
if( (rgb[x].rgbtRed == 255) && (rgb[x].rgbtGreen == 255) &&
(rgb[x].rgbtBlue > 239) && (rgb[x].rgbtBlue < 250) ) {
if( rgb[x].rgbtBlue > 240 + memory_level )
rgb_dest[x] = rgbBad;
else
rgb_dest[x] = rgbLevel;
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
// draw memory & bat state
void DrawSystemState2()
{
int iBatt = 0 ;
int iMem = 0 ;
MEMORYSTATUS mem ;
hyper nRatio ;
SYSTEM_POWER_STATUS_EX sts ;
ZeroMemory( &sts,sizeof(sts) );
GetSystemPowerStatusEx( &sts,TRUE );
if ( sts.BatteryFlag != 255 ) {
if ( !(sts.BatteryFlag & 128) ) {
if ( sts.BatteryLifePercent == 255 ) {
if ( sts.BatteryFlag != 255 ) {
if ( sts.BatteryFlag & 1 ) {
iBatt = 9 ;
}
else if ( sts.BatteryFlag & 2 ) {
iBatt = 4 ;
}
else if ( sts.BatteryFlag & 4 ) {
iBatt = 1 ;
}
}
}
else {
iBatt = sts.BatteryLifePercent / 10 - 1 ;
}
}
}
ZeroMemory( &mem,sizeof(mem) );
mem.dwLength = sizeof(mem);
GlobalMemoryStatus( &mem );
nRatio = (hyper)mem.dwAvailPhys * 10 / mem.dwTotalPhys ;
iMem = (int)nRatio - 1 ;
// draw graph
RGBTRIPLE* pRgb ;
RGBTRIPLE rgbOk,rgbNg ;
BITMAP bmp ;
UINT tblLines[] = { 3,4,6,7,9,10,12,13,15,16,0 };
GetObject( gItemTbl[ITEM_ID_SYSTEM].hBmp,sizeof(bmp),&bmp );
if ( bmp.bmWidthBytes % 4 != 0 ) {
bmp.bmWidthBytes += (4 - bmp.bmWidthBytes % 4);
}
rgbOk.rgbtRed = 0 ;
rgbOk.rgbtGreen = 255 ;
rgbOk.rgbtBlue = 128 ;
rgbNg.rgbtRed = 255 ;
rgbNg.rgbtGreen = 0 ;
rgbNg.rgbtBlue = 0 ;
for ( int iLine = 0 ; tblLines[iLine] ; iLine++ ) {
pRgb = (RGBTRIPLE*)((LPBYTE)bmp.bmBits + bmp.bmWidthBytes*tblLines[iLine]);
if ( iMem >= iLine ) {
pRgb[3] = pRgb[4] = pRgb[5] = rgbOk ;
}
else {
pRgb[3] = pRgb[4] = pRgb[5] = rgbNg ;
}
if ( iBatt >= iLine ) {
pRgb[11] = pRgb[12] = pRgb[13] = rgbOk ;
}
else {
pRgb[11] = pRgb[12] = pRgb[13] = rgbNg ;
}
}
}
///////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -