📄 main.cpp
字号:
/////////////////////////////////////////////////////////////////////////////
// wisTask.cpp
//
// 2001/02/16(Fri) 00001 bug fix
/////////////////////////////////////////////////////////////////////////////
//#define DEBUG
#include "stdafx.h"
#include "main.h"
#include <commctrl.h>
#include <aygshell.h>
#include <tlhelp32.h>
#include <commdlg.h>
#include <shlobj.h>
#include <stdlib.h>
#include <winsock.h>
#include "wisBarSetup\\wisbardef.h"
#include "strdefs.h"
/////////////////////////////////////////////////////////////////////////////
#ifdef WIN32
#define LONG2POINT(l, pt) ((pt).x = (SHORT)LOWORD(l), (pt).y = (SHORT)HIWORD(l))
#else
#define LONG2POINT(l, pt) ((pt).x = (INT)LOWORD(l), (pt).y = (INT)HIWORD(l))
#endif
/////////////////////////////////////////////////////////////////////////////
#define CHK_TIMER_INTERVAL 300
#define CHK_SYSTIMER_INTERVAL 20000
#define CHK_CLOSE_TIMER_INTERVAL 300
#define CHK_VOLUME_TIMER_INTERVAL 300
#define CHK_THEMECHK_INTERVAL 6000
#define CHK_APPOINT_TIMER_INTERVALE 300
#define CHK_CONNECT_TIMER_INTERVAL 1000
#define MAX_INTASKS 4
#define MAX_WND 25
#define MAX_APP_TITLE 48
#define MAX_STRING_BUFFER 200
#define SIP_OFFSET 45
/////////////////////////////////////////////////////////////////////////////
#define ITEM_ID_BG 0
#define ITEM_ID_LOGO 1
#define ITEM_ID_TITLE 2
#define ITEM_ID_DATE 3
#define ITEM_ID_CLOCK 4
#define ITEM_ID_SIP 5
#define ITEM_ID_SYSTEM 6
#define ITEM_ID_TODAY 7
#define ITEM_ID_LIST 8
#define ITEM_ID_OK 9
#define ITEM_ID_CLOSE 10
#define ITEM_ID_CLOSE2 11
#define ITEM_ID_MUTE 12
#define ITEM_ID_NOTIFY 13
#define ITEM_ID_OK2 14
#define ITEM_ID_CONN 15
#define ITEM_ID_DISC 16
#define ITEM_ID_MAX 17
typedef enum { LeftColor, RightColor, FontColor } clr;
typedef struct _tagITEM_INFO_T {
HBITMAP hBmp ; // Bitmap
RECT rc ; // RECT
BOOL bDisp ; // display on/off
BOOL bEnable ; // valid
} ITEM_INFO_T,*LPITEM_INFO_T ;
typedef struct _tagFONT_INFO_T {
HFONT hFont ; // font handle
COLORREF cr ; // color
} FONT_INFO_T,*LPFONT_INFO_T ;
typedef struct _tagMENU_TASK_INFO {
BOOL bSysTask ;
HWND hWnd ;
TCHAR szName[MAX_APP_TITLE];
TCHAR szClass[MAX_APP_TITLE];
HICON hIcon;
} MENU_TASK_INFO,*LPMENU_TASK_INFO ;
typedef struct _tagTASK_ICON_INFO {
HWND hWnd ;
HICON hIco ;
BOOL bUnload ;
DWORD dwPid ;
TCHAR szTitle[MAX_APP_TITLE];
TCHAR szClass[MAX_APP_TITLE];
RECT rc ;
} TASK_ICON_INFO,*LPTASK_ICON_INFO ;
/////////////////////////////////////////////////////////////////////////////
// 僌儘乕僶儖曄悢 :
HINSTANCE ghInst = NULL ; // current instance
HWND ghWnd = NULL ;
UINT gnTimer = 0 ; // check timer
UINT gnTimerSys = 0 ; // check timer
UINT gnCloseTimer = 0 ; // close timer
UINT gnVolumeTimer = 0 ; // volume timer
UINT gnThemeTimer = 0 ; // Theme timer
UINT gnAppointTimer = 0 ; // Appointment timer
UINT gnConnectTimer = 0; // Connection timer
POINT ptMenuPoint;
UINT gnUpdateMsg = 0 ;
HMENU ghMenu = NULL ; // popup menu
BOOL gbMenuOn = FALSE ;
DWORD gdwDispItems = 0 ; // display items
BYTE gcbOrder[ORDER_ID_MAX]; // display order
TCHAR gszTitle[MAX_APP_TITLE] = _T("");
DWORD gdwPMail = NULL ;
BOOL gbPMail = FALSE ;
// task ctrl
MENU_TASK_INFO gAppTbl[MAX_WND]; // available windows
DWORD gdwValidTask = 0 ; // number of available windows
TASK_ICON_INFO gTaskIcons[MAX_WND];
DWORD gdwNumTaskIcon = 0 ; // number of icons on taskbar
BOOL gSmartMinimize = TRUE;
WORD gTarget = 2002;
BOOL gGotoToday = FALSE;
BOOL gHideActiveSync = FALSE;
BOOL bGradient = FALSE;
BOOL bDithered = FALSE;
BOOL b2002Theme = FALSE;
BOOL b2002Style = FALSE;
BOOL use2002Fonts = FALSE;
BOOL bNotify = FALSE;
BOOL bTapAppoint = FALSE;
COLORREF cr2002Fonts = RGB( 255,255,255 );
BOOL lastMute;
BOOL lastConnect;
COLORREF cStartCr = GetSysColor( COLOR_ACTIVECAPTION );
COLORREF cEndCr = GetSysColor( COLOR_ACTIVECAPTION );
COLORREF cGrads[GRAD_STEPS];
BOOL gCompactDateTime = TRUE;
BOOL gTHMUTE = TRUE;
BOOL notifyWaiting = true;
// state ctrl
BOOL gbChecking = FALSE ;
HWND ghDlg = NULL ;
TASK_ICON_INFO gActive = { NULL,NULL,FALSE,NULL,_T(""),{0,0,0,0} };
DWORD gIngnoreTasks[MAX_INTASKS]; // ignore process
DWORD gdwNumInTask = 0 ; // number of ignore process
int giCurBtn = ITEM_ID_OK ;
WORD gwMinute = 60 ;
WORD gwDay = 0 ;
int giFocus = -1 ; // focused icon index
int giFocusTask = -1 ; // tapping icon index
BOOL gbSipMsg = FALSE ; // SIP message
BOOL g3dbutton = FALSE ;
int gMenuClose = 0 ;
// table of icons
ITEM_INFO_T gItemTbl[ITEM_ID_MAX];
// fonts
FONT_INFO_T gfntTitle ; // window title font
FONT_INFO_T gfntDate ; // date font
FONT_INFO_T gfntTime ; // time font
HICON ghCloseIcon = NULL ; // close icon for popup menu
BOOL gbSmallDate = FALSE ;
// work
HBITMAP ghBmpWork = NULL ;
HBITMAP ghBmpGrad = NULL;
HBITMAP ghPrevGrad = NULL;
HBITMAP ghSystem = NULL;
HDC ghMemDC = NULL ;
HDC ghGradient = NULL;
POINT gptMenu ;
WNDPROC fnMenu = NULL ;
HFONT ghMenuFont = NULL ;
//WNDPROC HHoldProc;
/////////////////////////////////////////////////////////////////////////////
// ignore processes
LPCTSTR glpIngnoreProc[] = { _T("shell32.exe"),
NULL
};
// ignore windows
LPCTSTR glpIgnore[] = { _T("Pocket PC Emulation"),
_T("CursorWindow"),
NULL
};
// ignore window-classes
LPCTSTR glpIngnoreClass[] = { // _T("Dialog"),
// _T("Worker"),
_T("menu_worker"),
_T("HHTaskBar"),
_T("MS_SIPBUTTON"),
NULL
};
/////////////////////////////////////////////////////////////////////////////
#ifdef DEBUG
/////////////////////////////////////////////////////////////////////////////
// Debug
void MyDebug( TCHAR szBuf[4096] )
{
// TCHAR szBuf[4096];
HANDLE hFile = CreateFile( TEXT("\\cab\\wisdebug.txt"),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL );
if ( hFile == INVALID_HANDLE_VALUE ) {
return ;
}
SetFilePointer( hFile,0,0,FILE_END );
char szDbg[4096];
DWORD dwOsz = (DWORD)WideCharToMultiByte( CP_ACP,0,szBuf,_tcslen(szBuf),szDbg,sizeof(szDbg),NULL,NULL );
DWORD dwWritten ;
WriteFile( hFile,(LPBYTE)szDbg,dwOsz,&dwWritten,NULL );
CloseHandle( hFile );
}
void Debug( LPCTSTR lpszFormat, ... )
{
TCHAR szBuf[4096];
va_list args ;
va_start( args,lpszFormat );
_vsntprintf( szBuf,(sizeof(szBuf)/sizeof(szBuf[0])),lpszFormat,args );
va_end( args );
#ifdef _WIN32_WCE_EMULATION
lstrcat( szBuf,_T("\n") );
OutputDebugString( szBuf );
#else // _WIN32_WCE_EMULATION
lstrcat( szBuf,_T("\r\n") );
HANDLE hFile = CreateFile( TEXT("\\wisdebug.txt"),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL );
if ( hFile == INVALID_HANDLE_VALUE ) {
return ;
}
SetFilePointer( hFile,0,0,FILE_END );
char szDbg[4096];
DWORD dwOsz = (DWORD)WideCharToMultiByte( CP_ACP,0,szBuf,_tcslen(szBuf),szDbg,sizeof(szDbg),NULL,NULL );
DWORD dwWritten ;
WriteFile( hFile,(LPBYTE)szDbg,dwOsz,&dwWritten,NULL );
CloseHandle( hFile );
#endif // _WIN32_WCE_EMULATION
}
/////////////////////////////////////////////////////////////////////////////
#endif // DEBUG
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
ATOM DoRegisterClass( HINSTANCE,LPTSTR );
BOOL InitInstance( HINSTANCE,int );
LRESULT CALLBACK WndProc( HWND,UINT,WPARAM,LPARAM );
//LRESULT CALLBACK HHTaskProc( HWND,UINT,WPARAM,LPARAM );
void calcGradient();
void Draw( HWND );
void Draw2002Style( HWND,RECT );
void DrawGradient( HWND hWnd );
void DrawDitheredGradient( HWND hWnd );
//void DrawGradientRect( HWND, RECT& );
void RefreshGradient( HWND );
BOOL LoadImgResource( HWND hWnd );
void ClearnupImgResource();
COLORREF GetThemeColor(clr);
BOOL getInternetStatus();
void TransparentBlit( HDC hdest,int left,int top,int width,int height,HDC hsrc,int left2,int top2);
HBITMAP CreateDIBCopy( HWND,BOOL,LPCTSTR );
BOOL CreateCustomFont( LPTSTR,int,DWORD,LPFONT_INFO_T );
void GetTextNeedSize( HDC,HFONT,LPCTSTR,SIZE* );
void SetTransparent( HBITMAP,LPITEM_INFO_T/*,BOOL*/ );
BOOL Prepare( HWND );
BOOL CreateDisableImage( HBITMAP );
void RefreshMenuItems();
BOOL EnumProcessList();
BOOL EnumWindowsProc( HWND,LPARAM );
BOOL IsValidClose( HWND,LPTSTR,LPTSTR,LPDWORD,LPBOOL,BOOL );
void SwitchState( HWND,UINT,BOOL );
void CheckBtnState( HWND hWnd );
bool isSystemWindow( HWND hWnd );
BOOL CheckTasks( HWND,LPTSTR,LPCTSTR,DWORD,BOOL );
void RemoveTask( LPTASK_ICON_INFO );
void CopyTask( LPTASK_ICON_INFO,LPTASK_ICON_INFO );
BOOL EnumWindowsProc2( HWND,LPARAM );
// HICON GetIconHandle( HWND,DWORD,LPBOOL );
HICON GetIconHandle( LPTSTR,HWND,DWORD,LPBOOL );
void RefreshTask();
BOOL fileExists( LPTSTR );
void DrawTaskMenuItem( DRAWITEMSTRUCT* );
int MenuItemHitTest( POINT pt );
LRESULT OnCommand( HWND,WPARAM,LPARAM );
LRESULT OnTapUp( HWND,WPARAM,LPARAM );
LRESULT OnTapDown( HWND,WPARAM,LPARAM );
int HitTest( POINT&,LPBOOL );
int TaskIconHitTest( POINT );
BOOL IsSameTask( LPTASK_ICON_INFO,LPTASK_ICON_INFO );
void CloseApp( HWND );
void CloseAppTimer( HWND );
void HandleApp( HWND );
void PushOK( HWND );
void ShowVolume( void );
void PushAppt( void );
void CloseAllTask( BOOL,int );
void SmartMinimize2002 ( HWND );
void SmartMinimize2000 ( HWND );
void GotoToday();
void VolumeTimer( void );
void ThemeTimer();
void DrawClock( RECT );
void DrawSystemState();
void DrawTitleArea( RECT );
void SetFocusedTask( int,BOOL );
void SetFocused( int,BOOL );
LRESULT CALLBACK MenuWndProc( HWND,UINT,WPARAM,LPARAM );
BOOL HookPopupMenu();
LRESULT CALLBACK VolDlgProc( HWND,UINT,WPARAM,LPARAM );
void InitSetup();
BOOL IsInitialExec();
void GetRegionalDate( LPTSTR,int,SYSTEMTIME* );
BOOL IsMute();
DWORD GetMuteVolume();
void SetMuteVolume( DWORD dwVol );
void SetUnMuteVolume( DWORD dwVol );
void MuteToggle();
void GetMenuFont();
void SendSIPMessage( LPARAM );
void ShowPower();
BOOL IsPocketPC2002(void);
/////////////////////////////////////////////////////////////////////////////
// main
int WINAPI WinMain( HINSTANCE hInst,HINSTANCE hPrev,LPTSTR lpCmdLine,int nCmdShow )
{
MSG msg ;
HANDLE hMutex = CreateMutex( NULL,TRUE,WIS_BAR_CLASS );
if( GetLastError() == ERROR_ALREADY_EXISTS ) {
// Look for a previous instance of the program
HWND hWndWis = ::FindWindow( NAV_BAR_CLASS,NULL );
TCHAR szClass[32];
UINT nCmd = GW_CHILD|GW_HWNDFIRST ;
while ( hWndWis = ::GetWindow(hWndWis,nCmd) ) {
GetClassName( hWndWis,szClass,sizeof(szClass)/sizeof(TCHAR) );
if ( lstrcmp(WIS_BAR_CLASS,szClass) == 0 ) {
break ;
}
nCmd = GW_HWNDNEXT ;
}
if ( hWndWis ) {
PostMessage( hWndWis,IDM_APP_POPUP,0,0 );
}
return( 1 );
}
if ( IsInitialExec() ) {
InitSetup();
}
// initialize
if ( !InitInstance(hInst,nCmdShow) ) {
CloseHandle( hMutex );
return( FALSE );
}
// message loop
while ( GetMessage(&msg,NULL,0,0) ) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
// if( HHoldProc )
// ::SetWindowLong(FindWindow(NAV_BAR_CLASS,NULL),GWL_WNDPROC,(LONG)HHoldProc);
CloseHandle( hMutex );
return( msg.wParam );
}
/////////////////////////////////////////////////////////////////////////////
// register class
ATOM DoRegisterClass( HINSTANCE hInst,LPTSTR szWindowClass )
{
WNDCLASS wc ;
ZeroMemory( &wc,sizeof(wc) );
wc.style = CS_HREDRAW | CS_VREDRAW | CS_PARENTDC;
wc.lpfnWndProc = (WNDPROC)WndProc ;
wc.hInstance = hInst ;
wc.hCursor = 0;
wc.hbrBackground = GetSysColorBrush(COLOR_ACTIVECAPTION);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass ;
return( RegisterClass(&wc) );
}
/////////////////////////////////////////////////////////////////////////////
// initialize
BOOL InitInstance( HINSTANCE hInst,int nCmdShow )
{
HWND hWnd = NULL ;
ghInst = hInst ;
InitCommonControls();
// register window class
if ( !DoRegisterClass(hInst,WIS_BAR_CLASS) ) {
return( FALSE );
}
// search taskbar
HWND hWndTashBar = FindWindow( NAV_BAR_CLASS,NULL );
// ignore system pprocess(can't ctrl)
EnumProcessList();
RECT rc ;
GetClientRect( hWndTashBar,&rc );
// create window on taskbar
hWnd = CreateWindow( WIS_BAR_CLASS,_T(""),WS_VISIBLE,
0,0,rc.right,rc.bottom,
hWndTashBar,NULL,hInst,NULL
);
if ( !hWnd ) {
return( FALSE );
}
ghWnd = hWnd ;
// register notification message(for taking effect settings)
gnUpdateMsg = RegisterWindowMessage( MSG_UPDATE_NOTIFY );
if( gdwDispItems & DISPITEM_SYSTEM ) {
DrawSystemState();
InvalidateRect( hWnd,&gItemTbl[ITEM_ID_SYSTEM].rc,TRUE );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -