📄 helperdlg.cpp
字号:
// HelperDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Helper.h"
#include "QuickRemindDlg.h"
#include "MessageDlg.h"
#include "SettimerDlg.h"
#include "DownloadDlg.h"
#include "hyperlink.h"
BOOL DebugOut(LPCTSTR lpTxt);
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CHyperLink m_clsMyHomepage;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
afx_msg void OnMyhomepage();
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Control(pDX, IDC_MYHOMEPAGE, m_clsMyHomepage);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_BN_CLICKED(IDC_MYHOMEPAGE, OnMyhomepage)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHelperDlg dialog
CHelperDlg::CHelperDlg()
{
//{{AFX_DATA_INIT(CHelperDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_nNumBeginX = 0;
m_nNumBeginY = 0;
m_bShow = TRUE;
m_nHourDigit1 = 0;
m_nHourDigit2 = 0;
m_nMinuteDigit1 = 0;
m_nMinuteDigit2 = 0;
m_nSecondDigit1 = 0;
m_nSecondDigit2 = 0;
m_nCurrentSecond = 0;
}
CHelperDlg::~CHelperDlg()
{
}
BEGIN_MESSAGE_MAP(CHelperDlg, CWnd)
//{{AFX_MSG_MAP(CHelperDlg)
ON_WM_PAINT()
ON_WM_TIMER()
ON_COMMAND(ID_EXIT, OnExit)
ON_WM_LBUTTONDOWN()
ON_WM_ERASEBKGND()
ON_WM_CONTEXTMENU()
ON_COMMAND(ID_MENU_SETTIMER, OnMenuSettimer)
ON_COMMAND(ID_MENU_QUICKREMIND, OnMenuQuickremind)
ON_COMMAND(ID_MENU_SHOW, OnMenuShow)
ON_COMMAND(ID_MENU_ABOUT, OnMenuAbout)
ON_WM_CLOSE()
ON_COMMAND(ID_MENU_ALWAYSONTOP, OnMenuAlwaysontop)
ON_WM_DESTROY()
ON_WM_MEASUREITEM()
ON_WM_MENUCHAR()
ON_WM_INITMENUPOPUP()
ON_WM_SYSCOMMAND()
ON_WM_QUERYDRAGICON()
ON_COMMAND(ID_MENU_DOWNLOAD, OnMenuDownload)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_CLICK_TRAYICON,OnClickTrayIcon)
END_MESSAGE_MAP()
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CHelperDlg::OnPaint()
{
CPaintDC dc(this);
CDC memDC;
memDC.CreateCompatibleDC( &dc );
CBitmap* pOldBitmap = memDC.SelectObject( &m_bmpNumber );
dc.BitBlt( m_nNumBeginX, m_nNumBeginY, 2, 25, &memDC, 160, 0, SRCCOPY );
dc.BitBlt( m_nNumBeginX+70, m_nNumBeginY, 8, 25, &memDC, 150, 0, SRCCOPY );
//秒
dc.BitBlt( m_nNumBeginX+2 , m_nNumBeginY, 15, 25, &memDC, m_nHourDigit1*15, 0, SRCCOPY );
dc.BitBlt( m_nNumBeginX+17 , m_nNumBeginY, 15, 25, &memDC, m_nHourDigit2*15, 0, SRCCOPY );
//时
dc.BitBlt( m_nNumBeginX+40, m_nNumBeginY, 15, 25, &memDC, m_nMinuteDigit1*15, 0, SRCCOPY );
dc.BitBlt( m_nNumBeginX+55, m_nNumBeginY, 15, 25, &memDC, m_nMinuteDigit2*15, 0, SRCCOPY );
//:
dc.BitBlt( m_nNumBeginX+32, m_nNumBeginY, 8, 25, &memDC, 150, 0, SRCCOPY );
//分
dc.BitBlt( m_nNumBeginX+78, m_nNumBeginY, 15, 25, &memDC, m_nSecondDigit1*15, 0, SRCCOPY );
dc.BitBlt( m_nNumBeginX+93, m_nNumBeginY, 15, 25, &memDC, m_nSecondDigit2*15, 0, SRCCOPY );
//:
dc.BitBlt( m_nNumBeginX+108, m_nNumBeginY, 2, 25, &memDC, 150, 0, SRCCOPY );
memDC.SelectObject( pOldBitmap );
// char lpClassName[255];
// ::GetClassName(GetSafeHwnd(), lpClassName, 255);
}
void CHelperDlg::CreateTransparentDialog(LPCTSTR pTitle)
{
if(m_bmpFrame.LoadBitmap(IDB_FRAME_BITMAP)==NULL) return ;
if(m_bmpNumber.LoadBitmap(IDB_NUMBER_BITMAP)==NULL) return ;
// if(LoadBMPImage("e:\\frame.bmp", m_bmpFrame, NULL)==NULL)return;
// if(LoadBMPImage("e:\\number.bmp", m_bmpNumber, NULL)==NULL)return;
// CDib dib("e:\\frame.bmp");
int nWidth;// = dib.m_nWidth;
int nHeight;// = dib.m_nHeight;
BITMAP bm;
m_bmpFrame.GetBitmap(&bm);
nWidth = bm.bmWidth;
nHeight = bm.bmHeight;
CRect rect(0, 0, bm.bmWidth, bm.bmHeight);
int nResult = CreateEx(0,//WS_EX_TOOLWINDOW,
AfxRegisterWndClass(0),
pTitle,
WS_POPUP | WS_SYSMENU,//|WS_EX_TOOLWINDOW,
rect,
NULL,
NULL,
NULL );
SetFrame(GetWindowDC());//set the region of frame
SetTimer(HELPER_TIMER_CREATE, HELPER_TIMELAG_CREATE, NULL);
NOTIFYICONDATA tnd;
tnd.cbSize=sizeof(NOTIFYICONDATA);
tnd.hWnd=this->m_hWnd;
tnd.uID=IDR_MAINFRAME;
tnd.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
tnd.uCallbackMessage=WM_CLICK_TRAYICON;
tnd.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
strcpy(tnd.szTip,"Helper");
Shell_NotifyIcon(NIM_ADD,&tnd);
// SetWindowPos(
// (GetExStyle() & WS_EX_TOPMOST) ? &CWnd::wndNoTopMost : &CWnd::wndTopMost,
// 0,0,0,0,
// SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
HCURSOR hCursor;
// Load a cursor resource that was originally created using
hCursor = AfxGetApp()->LoadCursor(IDC_CURSOR1);
SetCursor(hCursor);
//加入WS_EX_LAYERED扩展属性
SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE,
GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^0x80000);
HINSTANCE hInst = LoadLibrary("User32.DLL");
if(hInst)
{
typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
MYFUNC fun = NULL;
//取得SetLayeredWindowAttributes函数指针
fun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
if(fun)fun(this->GetSafeHwnd(),0,200,2);
FreeLibrary(hInst);
}
HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR);//SM_CXICON
HICON hPrevIcon = (HICON)AfxGetMainWnd()->SendMessage(WM_SETICON,ICON_BIG,(LPARAM)hIcon);
ReadArrayThingFromFile();
SetTimer(HELPER_TIMER_SETTIMER, HELPER_TIMELAG_SETTIMER, NULL);
}
CHelperDlg::SetFrame(CDC *pDC)
{
CDC memDC;
CBitmap* pOldMemBmp = NULL;
COLORREF col,maskcol;
CRect cRect;
CRgn wndRgn, rgnTemp;
int sum;
GetWindowRect(&cRect);
memDC.CreateCompatibleDC(pDC);
pOldMemBmp = memDC.SelectObject(&m_bmpFrame);
wndRgn.CreateRectRgn(0, 0, cRect.Width(), cRect.Height());
maskcol=memDC.GetPixel(0, 0);
for(int x=0; x<=cRect.Width(); x++)
{
for(int y=0; y<=cRect.Height(); y++)
{
col = memDC.GetPixel(x, y);
// TRACE("col = %d\n", col);
if(col == maskcol)
{
rgnTemp.CreateRectRgn(x, y, x+1, y+1);
wndRgn.CombineRgn(&wndRgn, &rgnTemp, RGN_XOR);
rgnTemp.DeleteObject();
}
else
{
int temp;
temp=0;
if (col == 0)
{
sum=0;
for(int k=0;k<25;k++)
{
sum=sum+memDC.GetPixel(x, y+k)+memDC.GetPixel(x+109, y+k);
if (sum!=0)
break;
}
if (sum==0) //得到起始点x,y
{
m_nNumBeginX=x;
m_nNumBeginY=y;
}
}
}
}
}
if (pOldMemBmp) memDC.SelectObject(pOldMemBmp);
SetWindowRgn((HRGN)wndRgn, TRUE);
char buf[256];
GetClassName(this->GetSafeHwnd(), buf, 256);
DebugOut(buf);
}
void CHelperDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent)
{
case HELPER_TIMER_CREATE:
{
CTime cCurrentTime;
cCurrentTime = CTime::GetCurrentTime();
int h=cCurrentTime.GetHour();
int f=cCurrentTime.GetMinute();
int s=cCurrentTime.GetSecond();
if (m_nCurrentSecond == s)
return;
else
m_nCurrentSecond = s;
m_nSecondDigit1 = s/10;
m_nSecondDigit2 = s%10;
m_nHourDigit1 = h/10;
m_nHourDigit2 = h%10;
m_nMinuteDigit1 = f/10;
m_nMinuteDigit2 = f%10;
//只重绘时钟区域
Invalidate(FALSE);
break;
}
case HELPER_TIMER_QUICKREMIND:
{
CTime time;
time = CTime::GetCurrentTime();
int hour = time.GetHour();
int minute = time.GetMinute();
int second = time.GetSecond();
int nCurrentTime = hour*3600+minute*60+second;
if(nCurrentTime - m_nSettimerBegin > m_nSetTime)
{
KillTimer(HELPER_TIMER_QUICKREMIND);
CMessageDlg * pDlg = new CMessageDlg;
ASSERT_VALID( pDlg);
pDlg->m_strThingToRemind = m_strThingToRemind;
BOOL bResult = pDlg->Create(IDD_MESSAGEDIALOG);
ASSERT(bResult);
CRect rWorkArea, rClientArea;
SystemParametersInfo(SPI_GETWORKAREA, 0, &rWorkArea, FALSE);
pDlg->GetWindowRect(&rClientArea);
pDlg->MoveWindow((rWorkArea.right-rClientArea.Width())/2, (rWorkArea.bottom-rClientArea.Height())/2,
rClientArea.Width(), rClientArea.Height(), TRUE);
// pDlg->CenterWindow();
// MessageBox("do your thing!");
break;
}
}
case HELPER_TIMER_SETTIMER:
{
KillTimer(HELPER_TIMER_SETTIMER);
CTime cCurrentTime;
cCurrentTime = CTime::GetCurrentTime();
int nTotal = m_arrayThing.GetSize();
for(int i=0; i<nTotal; i++)
{
int nyear, nmonth, nday;
nyear = m_arrayThing[i].nYear;
nmonth = m_arrayThing[i].nMonth;
nday = m_arrayThing[i].nDay;
CTime cTime(m_arrayThing[i].nYear, m_arrayThing[i].nMonth, m_arrayThing[i].nDay,
m_arrayThing[i].nHour, m_arrayThing[i].nMinute, m_arrayThing[i].nSecond);
/* char buf[256];
sprintf(buf, "current time: %4d-%02d-%02d %02d:%02d:%02d", cCurrentTime.GetYear(), cCurrentTime.GetMonth(), cCurrentTime.GetDay(),
cCurrentTime.GetHour(), cCurrentTime.GetMinute(), cCurrentTime.GetSecond());
DebugOut(buf);
sprintf(buf, "set time: %4d-%02d-%02d %02d:%02d:%02d", cTime.GetYear(), cTime.GetMonth(), cTime.GetDay(),
cTime.GetHour(), cTime.GetMinute(), cTime.GetSecond());
DebugOut(buf);
*/
if(cTime<cCurrentTime)
{
//signalling
CMessageDlg * pDlg = new CMessageDlg;
ASSERT_VALID( pDlg);
pDlg->m_strThingToRemind = m_arrayThing[i].strThing;
BOOL bResult = pDlg->Create(IDD_MESSAGEDIALOG);
ASSERT(bResult);
CRect rWorkArea, rClientArea;
SystemParametersInfo(SPI_GETWORKAREA, 0, &rWorkArea, FALSE);
pDlg->GetWindowRect(&rClientArea);
pDlg->MoveWindow((rWorkArea.right-rClientArea.Width())/2, (rWorkArea.bottom-rClientArea.Height())/2,
rClientArea.Width(), rClientArea.Height(), TRUE);
m_arrayThing.RemoveAt(i);
WriteArrayThingToFile();
i--; nTotal--;
}
}
SetTimer(HELPER_TIMER_SETTIMER, HELPER_TIMELAG_SETTIMER, NULL);
}
}
CWnd::OnTimer(nIDEvent);
}
void CHelperDlg::OnClickTrayIcon(WPARAM wParam, LPARAM lParam)
{
if(wParam!=IDR_MAINFRAME)
return;
switch(lParam)
{
case WM_RBUTTONUP://右键起来时弹出快捷菜单,这里只有一个“关闭”
{
BCMenu m_menu;
BCMenu *pMenu;
LPPOINT lpoint = new POINT;
::GetCursorPos(lpoint);//得到鼠标位置
m_menu.LoadMenu(IDR_MENU_POPUP);
// m_menu.LoadToolbar(IDR_MAINFRAME);
m_menu.LoadToolbar(IDR_TOOLBAR);
pMenu = (BCMenu*)m_menu.GetSubMenu(0);
pMenu->SetMenuDrawMode(BCMENU_DRAWMODE_XP);
m_bShow?(pMenu->CheckMenuItem(ID_MENU_SHOW, MF_CHECKED|MF_BYCOMMAND)):
pMenu->CheckMenuItem(ID_MENU_SHOW, MF_UNCHECKED|MF_BYCOMMAND);
(GetExStyle() & WS_EX_TOPMOST) ? (pMenu->CheckMenuItem(ID_MENU_ALWAYSONTOP, MF_CHECKED|MF_BYCOMMAND)):
(pMenu->CheckMenuItem(ID_MENU_ALWAYSONTOP, MF_UNCHECKED|MF_BYCOMMAND));
pMenu->TrackPopupMenu (TPM_LEFTALIGN,lpoint->x,lpoint->y,this);
m_menu.DestroyMenu();
delete lpoint;
}
break;
case WM_LBUTTONDBLCLK:
{
this->ShowWindow(SW_SHOW);
}
break;
}
return;
}
void CHelperDlg::OnExit()
{
// TODO: Add your command handler code here
SendMessage(WM_CLOSE,0,0);
}
BOOL CHelperDlg::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
void CHelperDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -