📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "Clock.h"
#include "MainFrm.h"
#include "ClockConfig.h"
#include "PromptDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define WM_SYSTRAY (WM_USER+100)
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_MESSAGE(WM_SYSTRAY, OnSysTray)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CClockApp* cApp = (CClockApp*)AfxGetApp();
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
pnid.cbSize = sizeof(NOTIFYICONDATA);
pnid.hIcon = LoadIcon(AfxGetApp()->m_hInstance,
MAKEINTRESOURCE(IDR_MAINFRAME));
pnid.hWnd = m_hWnd;
sprintf(pnid.szTip,"Kukee时钟");
pnid.uCallbackMessage = WM_SYSTRAY;
pnid.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP;
pnid.uID = ID_CLOCK;
Shell_NotifyIcon(NIM_ADD,&pnid);
ShowWindow(SW_HIDE);
int time = cApp->m_pConfig->GetTime();
//SetMainTimer(cApp->m_pConfig->GetTime());
SetTimer(3,60*1000*time,NULL);
//SetTimer(3,30000,NULL);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnSysTray(WPARAM wParam,LPARAM lParam)
{
CPoint pt;
CClockApp* app = (CClockApp*)AfxGetApp();
switch(lParam)
{
case WM_RBUTTONUP:
{
//显示弹出菜单
GetCursorPos(&pt);
HMENU hmenu = LoadMenu(AfxGetApp()->m_hInstance,
MAKEINTRESOURCE(IDM_CONTEXTMENU));
HMENU hpopup = GetSubMenu(hmenu,0);
switch(TrackPopupMenu(hpopup,
TPM_RETURNCMD|
TPM_RIGHTBUTTON,
pt.x,
pt.y,
0,
m_hWnd,
NULL))
{
case ID_APP_EXIT:
PostQuitMessage(0);
Shell_NotifyIcon(NIM_DELETE,&pnid);
break;
case ID_APP_ABOUT:
app->OnAppAbout();
break;
case ID_CONFIG:
app->OnConfig();
break;
}
}/**
case WM_LBUTTONUP:
{
//显示弹出菜单
GetCursorPos(&pt);
HMENU hmenu = LoadMenu(AfxGetApp()->m_hInstance,
MAKEINTRESOURCE(IDM_CONTEXTMENU));
HMENU hpopup = GetSubMenu(hmenu,0);
switch(TrackPopupMenu(hpopup,
TPM_RETURNCMD|
TPM_RIGHTBUTTON,
pt.x,
pt.y,
0,
m_hWnd,
NULL))
{
case ID_APP_EXIT:
PostQuitMessage(0);
Shell_NotifyIcon(NIM_DELETE,&pnid);
break;
case ID_APP_ABOUT:
app->OnAppAbout();
break;
case ID_CONFIG:
app->OnConfig();
break;
}
}*/
//case WM_LBUTTONDBLCLK:
// ShowWindow(SW_SHOWDEFAULT);
}
}
LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
LRESULT result = CFrameWnd::WindowProc(message,wParam,lParam);
if(wParam == SC_MINIMIZE)
{
ShowWindow(SW_HIDE);
}
return result;
//return CFrameWnd::WindowProc(message, wParam, lParam);
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
switch (nIDEvent)
{
case 3:
CPromptDlg pDlg;
pDlg.DoModal();
break;
}
}
void CMainFrame::SetMainTimer(int time)
{
CClockApp* cApp = (CClockApp*)AfxGetApp();
//SetTimer(3,60*1000*time,NULL);
SetTimer(3,1000,NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -