📄 main.cpp
字号:
case WIS_ICO_DISCONN:
iIDIndex = ITEM_ID_DISC;
break;
case WIS_ICO_SYSTEM:
iIDIndex = ITEM_ID_SYSTEM;
if( hBmp ) {
ghSystem = CreateDIBCopy(hWnd, false, szBuf);
if( !ghSystem )
ghSystem = CreateDIBCopy(hWnd, true, MAKEINTRESOURCE(ResIDs[iIdx]));
}
break;
default :
iIDIndex = -1 ;
break ;
}
if ( iIDIndex != -1 ) {
gItemTbl[iIDIndex].bEnable = gItemTbl[iIDIndex].bDisp = TRUE ;
gItemTbl[iIDIndex].hBmp = hBmp ;
}
}
}
}
}
RegCloseKey( hSubKey );
}
if( gdwDispItems & DISPITEM_SYSTEM ) {
DrawSystemState();
}
// SIP image
gItemTbl[ITEM_ID_SIP].hBmp = CreateDIBCopy( hWnd,TRUE,MAKEINTRESOURCE(IDB_COMPAT) );
gItemTbl[ITEM_ID_SIP].bEnable = TRUE ;
// display order
BYTE cbBuf[ORDER_ID_MAX];
dwType = REG_BINARY ;
dwSize = ORDER_ID_MAX ;
lRet = RegQueryValueEx( hKey,REG_ORDER,0,&dwType,cbBuf,&dwSize );
if ( (lRet == ERROR_SUCCESS) && (dwSize == sizeof(cbBuf)) ) {
CopyMemory( gcbOrder,cbBuf,sizeof(cbBuf) );
}
RegCloseKey( hKey );
// check timer
gnTimer = SetTimer( hWnd,1,CHK_TIMER_INTERVAL,NULL );
// theme timer
gnThemeTimer = SetTimer( hWnd,5,CHK_THEMECHK_INTERVAL,NULL );
// check timer(for bat)
if ( gdwDispItems & DISPITEM_SYSTEM ) {
gnTimerSys = SetTimer( hWnd,2,CHK_SYSTIMER_INTERVAL,NULL );
}
if( gItemTbl[ITEM_ID_CONN].bDisp )
gnConnectTimer = SetTimer( hWnd,7,CHK_CONNECT_TIMER_INTERVAL,NULL );
return( TRUE );
}
/////////////////////////////////////////////////////////////////////////////
// cleanup resources
void ClearnupImgResource()
{
if( ghSystem ) {
DeleteObject(ghSystem);
ghSystem = 0;
}
if ( gnTimer ) {
KillTimer( ghWnd,1 );
gnTimer = 0 ;
}
if ( gnTimerSys ) {
KillTimer( ghWnd,2 );
gnTimerSys = 0 ;
}
if( gnConnectTimer ) {
KillTimer( ghWnd,7 );
gnConnectTimer = 0;
}
if ( gnThemeTimer ) {
KillTimer( ghWnd,5 );
gnThemeTimer = 0 ;
}
if( gnAppointTimer ) {
KillTimer( ghWnd,6 );
gnAppointTimer = 0;
}
if ( ghMemDC != NULL ) {
DeleteDC( ghMemDC );
ghMemDC = NULL ;
}
if( ghGradient != NULL )
{
if( ghPrevGrad != NULL ) {
SelectObject( ghGradient,ghPrevGrad );
ghPrevGrad = NULL;
}
DeleteDC( ghGradient );
ghGradient = NULL;
}
if ( ghBmpWork != NULL ) {
DeleteObject( ghBmpWork );
ghBmpWork = NULL ;
}
if( ghBmpGrad != NULL ) {
DeleteObject( ghBmpGrad );
ghBmpGrad = NULL;
}
for ( DWORD dwIdx = 0 ; dwIdx < gdwNumTaskIcon ; dwIdx++ ) {
if ( gTaskIcons[dwIdx].hIco && gTaskIcons[dwIdx].bUnload ) {
DestroyIcon( gTaskIcons[dwIdx].hIco );
}
}
ZeroMemory( gTaskIcons,sizeof(gTaskIcons) );
gdwNumTaskIcon = 0 ;
ZeroMemory( &gActive,sizeof(gActive) );
if ( ghMenu != NULL ) {
DestroyMenu( ghMenu );
ghMenu = NULL ;
}
if ( ghCloseIcon != NULL ) {
DestroyIcon( ghCloseIcon );
ghCloseIcon = NULL ;
}
if ( ghMenuFont != NULL ) {
DeleteObject( ghMenuFont );
ghMenuFont = NULL ;
}
for ( int iIdx = 0 ; iIdx < ITEM_ID_MAX ; iIdx++ ) {
if ( gItemTbl[iIdx].hBmp ) {
DeleteObject( gItemTbl[iIdx].hBmp );
}
}
if ( gfntTitle.hFont != NULL ) {
DeleteObject( gfntTitle.hFont );
ZeroMemory( &gfntTitle,sizeof(gfntTitle) );
}
if ( gfntDate.hFont != NULL ) {
DeleteObject( gfntDate.hFont );
ZeroMemory( &gfntDate,sizeof(gfntDate) );
}
if ( gfntTime.hFont != NULL ) {
DeleteObject( gfntTime.hFont );
ZeroMemory( &gfntTime,sizeof(gfntTime) );
}
gbSmallDate = FALSE ;
ZeroMemory( gItemTbl,sizeof(gItemTbl) );
for ( iIdx = 0 ; iIdx < ORDER_ID_MAX ; iIdx++ ) {
gcbOrder[iIdx] = (BYTE)iIdx ;
}
gwMinute = 60 ;
gwDay = 0 ;
giCurBtn = -1 ;
ZeroMemory( gszTitle,sizeof(gszTitle) );
// Ps/PC compatible mode
POINT pt = { 0,0 };
ClientToScreen( ghWnd,&pt );
if ( pt.y > 0 ) {
gItemTbl[ITEM_ID_SIP].bDisp = TRUE ;
}
else {
gItemTbl[ITEM_ID_SIP].bDisp = FALSE ;
}
}
/////////////////////////////////////////////////////////////////////////////
// create DIB
HBITMAP CreateDIBCopy( HWND hWnd,BOOL bFromResource,LPCTSTR lpFile )
{
BITMAP bmp ;
HBITMAP hBmp,hBmpRet ;
LPBYTE lpBits ;
// load original
if ( bFromResource ) {
hBmp = LoadBitmap( ghInst,lpFile );
}
else {
hBmp = SHLoadDIBitmap( lpFile );
}
if ( hBmp == NULL ) {
return( NULL );
}
ZeroMemory( &bmp,sizeof(bmp) );
GetObject( hBmp,sizeof(bmp),&bmp );
if ( bmp.bmHeight > 26 ) {
bmp.bmHeight = 26 ;
}
// create copy
BITMAPINFO bmi ;
ZeroMemory( &bmi,sizeof(bmi) );
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = bmp.bmWidth ;
bmi.bmiHeader.biHeight = bmp.bmHeight ;
bmi.bmiHeader.biPlanes = 1 ;
bmi.bmiHeader.biBitCount = 24 ;
bmi.bmiHeader.biCompression = BI_RGB ;
HDC hDC = GetDC( hWnd );
hBmpRet = CreateDIBSection( hDC,&bmi,DIB_RGB_COLORS,(LPVOID*)&lpBits,NULL,0 );
if ( hBmpRet == NULL ) {
ReleaseDC( hWnd,hDC );
return( NULL );
}
HDC hToDC = CreateCompatibleDC( hDC );
HDC hFrDC = CreateCompatibleDC( hDC );
HBITMAP hPrevTo = (HBITMAP)SelectObject( hToDC,hBmpRet );
HBITMAP hPrevFr = (HBITMAP)SelectObject( hFrDC,hBmp );
// tracsfer
BitBlt( hToDC,0,0,bmp.bmWidth,bmp.bmHeight,hFrDC,0,0,SRCCOPY );
SelectObject( hToDC,hPrevTo );
SelectObject( hFrDC,hPrevFr );
DeleteObject( hBmp );
DeleteDC( hToDC );
DeleteDC( hFrDC );
ReleaseDC( hWnd,hDC );
return( hBmpRet );
}
/////////////////////////////////////////////////////////////////////////////
// calc draw range
void CalcRect( HWND hWnd )
{
RECT rc ;
HDC hDC = GetDC( hWnd );
SIZE size,sizeTmp ;
BITMAP bmp ;
int iRcIndex ;
TCHAR szTst[16];
SYSTEMTIME st ;
GetClientRect( GetParent(hWnd),&rc );
if ( gItemTbl[ITEM_ID_BG].bDisp ) {
gItemTbl[ITEM_ID_BG].rc = rc ;
}
// from right side
for ( int iIdx = ORDER_ID_MAX - 1 ; iIdx >= 0 ; iIdx-- ) {
switch ( gcbOrder[iIdx] ) {
case ORDER_ID_DATE:
if ( gbSmallDate ) {
continue ;
}
else {
iRcIndex = ITEM_ID_DATE ;
GetLocalTime( &st );
GetRegionalDate( szTst,sizeof(szTst)/sizeof(TCHAR),&st );
if (gCompactDateTime)
GetDateFormat(LOCALE_USER_DEFAULT,NULL,&st,_T("M'/'d'"),szTst,sizeof(szTst)/sizeof(TCHAR) );
GetTextNeedSize( hDC,gfntDate.hFont,szTst,&size );
size.cy = rc.bottom ;
}
break ;
case ORDER_ID_CLOCK:
iRcIndex = ITEM_ID_CLOCK ;
GetLocalTime( &st );
st.wHour = 23 ;
st.wMinute = 59 ;
if (gCompactDateTime)
GetTimeFormat( LOCALE_USER_DEFAULT,NULL,&st,_T("h':'mm'"),szTst,sizeof(szTst)/sizeof(TCHAR) );
else
GetTimeFormat( LOCALE_USER_DEFAULT,TIME_NOSECONDS,&st,NULL,szTst,sizeof(szTst)/sizeof(TCHAR) );
GetTextNeedSize( hDC,gfntTime.hFont,szTst,&size );
size.cy = rc.bottom ;
break ;
case ORDER_ID_SMALLDATE:
{
if ( !gbSmallDate ) {
continue ;
}
iRcIndex = ITEM_ID_DATE ;
GetLocalTime( &st );
st.wHour = 23 ;
st.wMinute = 59 ;
// Size time
if (gCompactDateTime)
GetTimeFormat( LOCALE_USER_DEFAULT,NULL,&st,_T("h':'mm'"),szTst,sizeof(szTst)/sizeof(TCHAR) );
else
GetTimeFormat( LOCALE_USER_DEFAULT,TIME_NOSECONDS,&st,NULL,szTst,sizeof(szTst)/sizeof(TCHAR) );
GetTextNeedSize( hDC,gfntDate.hFont,szTst,&size );
// size date
GetRegionalDate( szTst,sizeof(szTst)/sizeof(TCHAR),&st );
if (gCompactDateTime)
GetDateFormat( LOCALE_USER_DEFAULT,NULL,&st,_T("M'/'d'"),szTst,sizeof(szTst)/sizeof(TCHAR) );
GetTextNeedSize( hDC,gfntDate.hFont,szTst,&sizeTmp );
if ( size.cx < sizeTmp.cx ) {
size.cx = sizeTmp.cx ;
}
size.cy = rc.bottom ;
}
break ;
case ORDER_ID_SYSTEM:
iRcIndex = ITEM_ID_SYSTEM ;
GetObject( gItemTbl[iRcIndex].hBmp,sizeof(bmp),&bmp );
size.cx = bmp.bmWidth ;
size.cy = bmp.bmHeight ;
break ;
case ORDER_ID_TODAY:
iRcIndex = ITEM_ID_TODAY ;
GetObject( gItemTbl[iRcIndex].hBmp,sizeof(bmp),&bmp );
size.cx = bmp.bmWidth ;
size.cy = bmp.bmHeight ;
break ;
case ORDER_ID_MENU:
iRcIndex = ITEM_ID_LIST ;
GetObject( gItemTbl[iRcIndex].hBmp,sizeof(bmp),&bmp );
size.cx = bmp.bmWidth ;
size.cy = bmp.bmHeight ;
break ;
case ORDER_ID_OKCLOSE:
iRcIndex = ITEM_ID_OK ;
GetObject( gItemTbl[iRcIndex].hBmp,sizeof(bmp),&bmp );
size.cx = bmp.bmWidth ;
size.cy = bmp.bmHeight ;
break ;
case ORDER_ID_NOTIFY:
iRcIndex = ITEM_ID_NOTIFY;
if( bNotify ) {
GetObject( gItemTbl[iRcIndex].hBmp,sizeof(bmp),&bmp );
size.cx = bmp.bmWidth;
size.cy = bmp.bmHeight;
} else {
size.cx = 0;
size.cy = 0;
}
break;
case ORDER_ID_CONNECT:
iRcIndex = ITEM_ID_CONN;
if( gItemTbl[iRcIndex].bDisp ) {
GetObject( gItemTbl[iRcIndex].hBmp,sizeof(bmp),&bmp );
size.cx = bmp.bmWidth;
size.cy = bmp.bmHeight;
}
else
size.cx = size.cy = 0;
break;
default:
continue ;
}
if ( !gItemTbl[iRcIndex].bDisp && (iRcIndex <= ITEM_ID_LIST) ) {
continue ;
}
// calc rect
gItemTbl[iRcIndex].rc.right = rc.right ;
gItemTbl[iRcIndex].rc.left = rc.right - size.cx ;
rc.right = gItemTbl[iRcIndex].rc.left ;
if ( rc.bottom < size.cy ) {
gItemTbl[iRcIndex].rc.top = 0 ;
gItemTbl[iRcIndex].rc.bottom = rc.bottom ;
}
else {
gItemTbl[iRcIndex].rc.top = (rc.bottom - size.cy) / 2 ;
gItemTbl[iRcIndex].rc.bottom = gItemTbl[iRcIndex].rc.top + size.cy ;
}
}
gItemTbl[ITEM_ID_CLOSE].rc = gItemTbl[ITEM_ID_OK].rc ;
gItemTbl[ITEM_ID_DISC].rc = gItemTbl[ITEM_ID_CONN].rc;
// Protectorate region of SIP(for compatibility Ps/PC)
if ( gItemTbl[ITEM_ID_SIP].bDisp ) {
GetObject( gItemTbl[ITEM_ID_SIP].hBmp,sizeof(bmp),&bmp );
gItemTbl[ITEM_ID_SIP].rc.left = rc.right - bmp.bmWidth ;
gItemTbl[ITEM_ID_SIP].rc.right = rc.right ;
rc.right = rc.right - bmp.bmWidth ;
if ( rc.bottom < bmp.bmHeight ) {
gItemTbl[ITEM_ID_SIP].rc.top = 0 ;
gItemTbl[ITEM_ID_SIP].rc.bottom = rc.bottom ;
}
else {
gItemTbl[ITEM_ID_SIP].rc.top = (rc.bottom - bmp.bmHeight) / 2 ;
gItemTbl[ITEM_ID_SIP].rc.bottom = gItemTbl[ITEM_ID_SIP].rc.top + bmp.bmHeight ;
}
//SetTransparent( gItemTbl[ITEM_ID_BG].hBmp,&gItemTbl[ITEM_ID_SIP] );
}
// logo
if ( gItemTbl[ITEM_ID_LOGO].bDisp ) {
if ( gdwDispItems & DISPITEM_SHIFTTITLE ) {
bmp.bmWidth = 27 ;
bmp.bmHeight = 26 ;
}
else {
GetObject( gItemTbl[ITEM_ID_LOGO].hBmp,sizeof(bmp),&bmp );
}
gItemTbl[ITEM_ID_LOGO].rc.left = 0 ;
gItemTbl[ITEM_ID_LOGO].rc.right = bmp.bmWidth ;
rc.left += bmp.bmWidth ;
if ( rc.bottom < bmp.bmHeight ) {
gItemTbl[ITEM_ID_LOGO].rc.top = 0 ;
gItemTbl[ITEM_ID_LOGO].rc.bottom = rc.bottom ;
}
else {
gItemTbl[ITEM_ID_LOGO].rc.top = (rc.bottom - bmp.bmHeight) / 2 ;
gItemTbl[ITEM_ID_LOGO].rc.bottom = gItemTbl[ITEM_ID_LOGO].rc.top + bmp.bmHeight ;
}
}
gItemTbl[ITEM_ID_TITLE].rc = rc ;
}
/////////////////////////////////////////////////////////////////////////////
// create font
BOOL CreateCustomFont( LPTSTR lpFnt,int iSize,DWORD dwStyle,LPFONT_INFO_T pFnt )
{
LOGFONT lf ;
ZeroMemory( &lf,sizeof(lf) );
lf.lfPitchAndFamily = FF_DONTCARE ;
lf.lfHeight = iSize ;
lf.lfCharSet = DEFAULT_CHARSET ;
lf.lfWeight = (dwStyle & FNT_STYLE_BOLD ? FW_BOLD : FW_NORMAL);
lf.lfItalic = (dwStyle & FNT_STYLE_ITALIC ? TRUE : FALSE);
lstrcpy( lf.lfFaceName,lpFnt );
pFnt->hFont = CreateFontIndirect( &lf );
return( pFnt->hFont != NULL );
}
/////////////////////////////////////////////////////////////////////////////
// get system menu font
void GetMenuFont()
{
LOGFONT lf ;
HKEY hKey ;
LONG lRet ;
DWORD dwType,dwSize,dwVal ;
ZeroMemory( &lf,sizeof(lf) );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -