📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "GetLink.h"
#include "DummyList.h"
#include "ActTreeView.h"
#include "AdrCtrlView.h"
#include "GetLinkDoc.h"
#include "AdrDlg.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define WM_ICON_NOTIFY WM_USER+1
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_ADD, OnAdd)
ON_COMMAND(ID_DELETE, OnDelete)
ON_COMMAND(ID_EDIT_CORD, OnEditCord)
ON_COMMAND(ID_VIEW_MAIN_WINDOW, OnViewMainWindow)
ON_COMMAND(ID_VIEW_DRAG_WINDOW, OnViewDragWindow)
ON_UPDATE_COMMAND_UI(ID_VIEW_MAIN_WINDOW, OnUpdateViewMainWindow)
ON_UPDATE_COMMAND_UI(ID_VIEW_DRAG_WINDOW, OnUpdateViewDragWindow)
ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification)
ON_WM_SYSCOMMAND()
ON_WM_CLOSE()
//}}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)
{
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);
char szTip[30];
wsprintf(szTip,"GetLink1.0版");
//创建托盘图标
if (!m_TrayIcon.Create(this, WM_ICON_NOTIFY,szTip, NULL, IDR_POPUPMENU))
return -1;
m_TrayIcon.SetStandardIcon(IDR_MAINFRAME);
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
cs.style &=~FWS_ADDTOTITLE;
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
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
// create a splitter with 1 row, 2 columns
if (!m_wndSplitter.CreateStatic(this, 1, 2))
{
TRACE0("Failed to CreateStaticSplitter\n");
return FALSE;
}
CRect rect;
GetClientRect(&rect);
// add the first splitter pane - the default view in column 0 左视网址分类视图
if (!m_wndSplitter.CreateView(0, 0,
pContext->m_pNewViewClass, CSize(rect.Width()/4, 0), pContext))
{
TRACE0("Failed to create first pane\n");
return FALSE;
}
// add the second splitter pane - which is a nested splitter with 2 rows
if (!m_wndSplitter2.CreateStatic(
&m_wndSplitter, // our parent window is the first splitter
2, 1, // the new splitter is 2 rows, 1 column
WS_CHILD | WS_VISIBLE | WS_BORDER, // style, WS_BORDER is needed
m_wndSplitter.IdFromRowCol(0, 1)
// new splitter is in the first row, 2nd column of first splitter
))
{
TRACE0("Failed to create nested splitter\n");
return FALSE;
}
// now create the two views inside the nested splitter 右上网址列表视图
if (!m_wndSplitter2.CreateView(0, 0,
RUNTIME_CLASS(CDummyList), CSize(rect.Width()*3/4, rect.Height()/2), pContext))
{
TRACE0("Failed to create second pane\n");
return FALSE;
}
// add the third splitter pane - which is a nested splitter with 2 column
if (!m_wndSplitter3.CreateStatic(
&m_wndSplitter2, // our parent window is the second splitter
1, 2, // the new splitter is 1 rows, 2 column
WS_CHILD | WS_VISIBLE | WS_BORDER, // style, WS_BORDER is needed
m_wndSplitter2.IdFromRowCol(1, 0)
// new splitter is in the first row, 2nd column of first splitter
))
{
TRACE0("Failed to create nested splitter\n");
return FALSE;
}
//左下1操作网址列表视图
if(!m_wndSplitter3.CreateView(0, 0,
RUNTIME_CLASS(CActTreeView), CSize(rect.Width()/4, rect.Height()/2), pContext))
{
TRACE0("Failed to create fourth pane\n");
return FALSE;
}
//左下2被选中网址列表视图
if(!m_wndSplitter3.CreateView(0, 1,
RUNTIME_CLASS(CAdrCtrlView), CSize(0, 0), pContext))
{
TRACE0("Failed to create fifth pane\n");
return FALSE;
}
// it all worked, we now have two splitter windows which contain
// three different views
return TRUE;
}
void CMainFrame::OnAdd()
{
// TODO: Add your command handler code here
CGetLinkDoc *pDoc=(CGetLinkDoc *)GetActiveView()->GetDocument();
CAdrDlg CDlg;
CDlg.m_StrTitle="新建网址";
if(CDlg.DoModal()==IDOK) //调用INITDIALOG()
{
//对话框变量赋给文档变量
pDoc->m_nNO=CDlg.m_IntRank;
pDoc->m_strName=CDlg.m_StrAdr;
int ch='@';
if(strchr(CDlg.m_StrAdr,ch)==NULL||strstr(CDlg.m_StrAdr,"www")!=NULL)
pDoc->m_Type1="网址"; //大类别应通过地址是否含有@来自动判断,不需用户输入
else
pDoc->m_Type1="邮址";
pDoc->m_Type2=CDlg.m_StrType2;
pDoc->m_Type3=CDlg.m_StrType3;
pDoc->m_Mark=CDlg.m_StrMark;
//文档变量赋给记录集
pDoc->set.NO = pDoc->m_nNO;
pDoc->set.Name = pDoc->m_strName;
//set.Type1 = pDoc->m_Type1;
pDoc->set.Type2 = pDoc->m_Type2;
pDoc->set.Type3 = pDoc->m_Type3;
pDoc->set.Mark = pDoc->m_Mark;
if(pDoc->set.AddNew())
{
pDoc->m_Act="添加";
CDummyList* AdrView=(CDummyList*)this->m_wndSplitter2.GetPane(0,0);
AdrView->MyUpdate(); //通知CDummylist添加
}
else
{
pDoc->m_Act="";
AfxMessageBox("Add Failed.");
}
}
}
void CMainFrame::OnDelete()
{
// TODO: Add your command handler code here
CGetLinkDoc *pDoc=(CGetLinkDoc *)GetActiveView()->GetDocument();
if(pDoc->iItem<0) return;
pDoc->set.MoveFirst();
pDoc->set.Move(pDoc->iItem);
if(pDoc->set.Delete())
{
pDoc->m_Act="删除";
CDummyList* AdrView=(CDummyList*)this->m_wndSplitter2.GetPane(0,0);
AdrView->MyUpdate(); //通知CDummylist删除
}
else
{
pDoc->m_Act="";
AfxMessageBox("Delete Failed.");
}
}
void CMainFrame::OnEditCord()
{
// TODO: Add your command handler code here
CGetLinkDoc *pDoc=(CGetLinkDoc *)GetActiveView()->GetDocument();
if (pDoc->iItem < 0) return;
CAdrDlg CDlg;
CDlg.m_StrTitle="编辑网址";
//文档变量赋给对话框初值
CDlg.m_IntRank=pDoc->m_nNO;
CDlg.m_StrAdr=pDoc->m_strName;
//pDoc->m_Type1; 大类别应通过地址是否含有@来自动判断,不需用户输入
CDlg.m_StrType2=pDoc->m_Type2;
CDlg.m_StrType3=pDoc->m_Type3;
CDlg.m_StrMark=pDoc->m_Mark;
if(CDlg.DoModal()==IDOK)
{
//对话框变量赋给文档变量
pDoc->m_nNO=CDlg.m_IntRank;
pDoc->m_strName=CDlg.m_StrAdr;
//pDoc->m_Type1;
pDoc->m_Type2=CDlg.m_StrType2;
pDoc->m_Type3=CDlg.m_StrType3;
pDoc->m_Mark=CDlg.m_StrMark;
pDoc->set.MoveFirst(); //定位记录集
pDoc->set.Move(pDoc->iItem);
//文档变量赋给记录集
pDoc->set.NO = pDoc->m_nNO;
pDoc->set.Name = pDoc->m_strName;
//set.Type1 = m_Type1;
pDoc->set.Type2 = pDoc->m_Type2;
pDoc->set.Type3 = pDoc->m_Type3;
pDoc->set.Mark = pDoc->m_Mark;
if(pDoc->set.Update())
{
pDoc->OnUpdate = TRUE;
pDoc->m_Act="修改";
CDummyList* AdrView=(CDummyList*)this->m_wndSplitter2.GetPane(0,0);
AdrView->MyUpdate(); //通知CDummylist修改
pDoc->OnUpdate = FALSE; //更新完毕,可以重选
}
else
{
pDoc->m_Act="";
AfxMessageBox("错误:更新失败!");
}
}
}
void CMainFrame::OnViewMainWindow()
{
// TODO: Add your command handler code here
if(IsWindowVisible())
{
ShowWindow(SW_SHOWMINIMIZED);
ShowWindow(SW_HIDE);
}
else
{
ShowWindow(SW_SHOW);
ShowWindow(SW_RESTORE);
}
}
void CMainFrame::OnViewDragWindow()
{
// TODO: Add your command handler code here
if(m_pDragWindow!=NULL)
{
if(m_pDragWindow->IsWindowVisible())
m_pDragWindow->ShowWindow(SW_HIDE);
else
m_pDragWindow->ShowWindow(SW_SHOW);
}
}
void CMainFrame::OnUpdateViewMainWindow(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(IsWindowVisible());
}
void CMainFrame::OnUpdateViewDragWindow(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(m_pDragWindow!=NULL)
pCmdUI->SetCheck(m_pDragWindow->IsWindowVisible());
}
LRESULT CMainFrame::OnTrayNotification(WPARAM wParam, LPARAM lParam)
{
//return m_TrayIcon.OnTrayNotification(wParam, lParam);
if (wParam != IDR_POPUPMENU)
return 0L;
CMenu menu, *pSubMenu;
if (LOWORD(lParam) == WM_RBUTTONUP)
{
CPoint pos;
GetCursorPos(&pos);
if (!menu.LoadMenu(IDR_POPUPMENU)) return 0;
if (!(pSubMenu=menu.GetSubMenu(0))) return 0;
::SetMenuDefaultItem(pSubMenu->m_hMenu, 3, TRUE);
SetForegroundWindow();
pSubMenu->TrackPopupMenu(TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON, pos.x, pos.y,
this);
menu.DestroyMenu();
}
else
if (LOWORD(lParam) == WM_LBUTTONDBLCLK)
{
if (!menu.LoadMenu(IDR_POPUPMENU)) return 0;
if (!(pSubMenu = menu.GetSubMenu(0))) return 0;
SetForegroundWindow();
//激活第四个菜单项
SendMessage(WM_COMMAND, pSubMenu->GetMenuItemID(3), 0);
menu.DestroyMenu();
}
return 0;
}
CFrameWnd* CMainFrame::GetActiveFrame()
{
// TODO: Add your specialized code here and/or call the base class
return CFrameWnd::GetActiveFrame();
}
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
CGetLinkApp * App = (CGetLinkApp*)AfxGetApp();
WINDOWPLACEMENT wp;
m_pDragWindow->GetWindowPlacement(&wp);
App->WriteProfileInt("DragWindow", "Visible", m_pDragWindow->IsWindowVisible()?1:0);
App->WriteProfileInt("DragWindow", "Top", wp.rcNormalPosition.top);
App->WriteProfileInt("DragWindow", "Left", wp.rcNormalPosition.left);
CFrameWnd::OnClose();
}
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
// TODO: Add your message handler code here and/or call default
if(nID==SC_MINIMIZE)
{
ShowWindow(SW_SHOWMINIMIZED);
ShowWindow(SW_HIDE);
}
else
CFrameWnd::OnSysCommand(nID, lParam);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -