📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "DriveExplorer.h"
#include "FilePathView.h"
#include "FileShowView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define WM_SYSTRAYNOTIFY WM_USER + 0x0001
#define ID_MYSYSTRAY 1
#define ID_TIMER_ABOUTDLG 1
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_MESSAGE(WM_SYSTRAYNOTIFY, OnSysTrayNotiFy)
ON_COMMAND(IDM_SYSTRAY_OPEN, OnSysTrayOpen)
ON_COMMAND(IDM_SYSTRAY_NAVI, OnSysTrayNavi)
ON_COMMAND(IDM_SYSTRAY_ABOUT, OnSysTrayAbout)
ON_COMMAND(IDM_SYSTRAY_EXIT, OnSysTrayExit)
ON_WM_SYSCOMMAND()
ON_WM_DESTROY()
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
m_pSplitterWnd = NULL;
m_pNfd = NULL;
m_pAboutDlg = NULL;
m_dwTime = 0;
}
CMainFrame::~CMainFrame()
{
if(NULL != m_pSplitterWnd)
{
m_pSplitterWnd->DestroyWindow();
delete m_pSplitterWnd;
m_pSplitterWnd = NULL;
}
if(NULL != m_pNfd)
{
Shell_NotifyIcon(NIM_DELETE, m_pNfd);
delete m_pNfd;
m_pNfd = NULL;
}
if(NULL != m_pAboutDlg)
{
m_pAboutDlg->DestroyWindow();
delete m_pAboutDlg;
m_pAboutDlg = NULL;
}
}
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);
m_pNfd = new NOTIFYICONDATA;
m_pNfd->cbSize = sizeof(NOTIFYICONDATA);
m_pNfd->hIcon = AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_SYSTRAY));
m_pNfd->hWnd = this->GetSafeHwnd();
/*pNfd->szTip = _T("资源管理器");*/
strcpy(m_pNfd->szTip, _T("资源管理器"));
m_pNfd->uCallbackMessage = WM_SYSTRAYNOTIFY;
m_pNfd->uFlags = NIF_ICON | NIF_MESSAGE |NIF_TIP;
m_pNfd->uID = ID_MYSYSTRAY;
if(!Shell_NotifyIcon(NIM_ADD, m_pNfd))
{
AfxMessageBox("创建失败");
return -1;
}
//设置寻找标记
::SetProp(this->GetSafeHwnd(), AfxGetApp()->m_pszAppName, (HANDLE)1);
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;
cs.lpszName = _T("我的资源管理器");
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
m_pSplitterWnd = new CSplitterWnd;
if(NULL == m_pSplitterWnd)
{
return FALSE;
}
if(FALSE == m_pSplitterWnd->CreateStatic(this, 1, 2))
{
AfxMessageBox("Unable to create splitterwnd");
return FALSE;
}
if(!m_pSplitterWnd->CreateView(0, 0, RUNTIME_CLASS(CFilePathView), CSize(150, 0), pContext))
return FALSE;
if(!m_pSplitterWnd->CreateView(0, 1, RUNTIME_CLASS(CFileShowView), CSize(0, 0), pContext))
return FALSE;
m_pSplitterWnd->RecalcLayout();
return TRUE;
//return CFrameWnd::OnCreateClient(lpcs, pContext);
}
LRESULT CMainFrame::OnSysTrayNotiFy(WPARAM wParam, LPARAM lParam)
{
if(wParam != ID_MYSYSTRAY)
return 0;
switch(lParam)
{
case WM_LBUTTONDBLCLK:
{
if(this->IsWindowVisible())
{
this->ShowWindow(SW_HIDE);
}
else
{
this->ShowWindow(SW_RESTORE);
this->SetForegroundWindow();
}
}
break;
case WM_RBUTTONDOWN:
CMenu menu;
if(!menu.LoadMenu(MAKEINTRESOURCE(IDR_MENU_SYSTRAY)))
return 0;
CMenu* pPopMenu = NULL;
pPopMenu = menu.GetSubMenu(0);
if(NULL == pPopMenu)
return 0;
POINT pt;
::GetCursorPos(&pt);
pPopMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, this);
break;
}
return S_OK;
}
LRESULT CMainFrame::OnSysTrayOpen(WPARAM wParam, LPARAM lParam)
{
if(this->IsWindowVisible())
{
this->ShowWindow(SW_SHOWNORMAL);
this->SetForegroundWindow();
}
else
{
this->BringWindowToTop();
}
return S_OK;
}
LRESULT CMainFrame::OnSysTrayNavi(WPARAM wParam, LPARAM lParam)
{
ShellExecute(NULL, NULL, _T("http://xiaonei.com/getuser.do?id=48604345"), NULL, NULL, SW_SHOWNORMAL);
return S_OK;
}
LRESULT CMainFrame::OnSysTrayAbout(WPARAM wParam, LPARAM lParam)
{
if(NULL == m_pAboutDlg)
{
m_pAboutDlg = new CDialog;
m_pAboutDlg->Create(MAKEINTRESOURCE(IDD_MYDIALOG), this);
SetWindowLong(m_pAboutDlg->GetSafeHwnd(), GWL_EXSTYLE,
GetWindowLong(m_pAboutDlg->GetSafeHwnd(), GWL_EXSTYLE)^0x80000 & ~WS_CAPTION);
}
if(m_pAboutDlg)
{
SetTimer(ID_TIMER_ABOUTDLG, 50, NULL);
m_dwTime = GetTickCount();
CRect rc;
::SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);
CRect m_curRect;
m_pAboutDlg->GetWindowRect(m_curRect);
//设置位置
m_curRect.left = rc.right - m_curRect.Width();
m_curRect.top = rc.bottom - m_curRect.Height();
m_curRect.right = rc.right;
m_curRect.bottom = rc.bottom;
//移动右下角
m_pAboutDlg->MoveWindow(m_curRect);
HANDLE hInst = LoadLibrary("User32.DLL"); //显式加载DLL
::SetWindowPos(m_pAboutDlg->GetSafeHwnd(),HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);//设置窗体大小位置不可变
if(hInst)
{
typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
MYFUNC fun = NULL;
fun=(MYFUNC)GetProcAddress((HMODULE)hInst, "SetLayeredWindowAttributes");//取得SetLayeredWindowAttributes函数指针
if(fun)
fun(m_pAboutDlg->GetSafeHwnd(), 0, 0, 2);
FreeLibrary((HMODULE)hInst);
m_nAlpha = 0;
}
m_pAboutDlg->ShowWindow(SW_SHOWNORMAL);
}
return S_OK;
}
LRESULT CMainFrame::OnSysTrayExit(WPARAM wParam, LPARAM lParam)
{
PostMessage(WM_CLOSE);
return S_OK;
}
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam )
{
if(nID == SC_CLOSE)
{
this->ShowWindow(SW_HIDE);
return;
}
CFrameWnd::OnSysCommand(nID, lParam);
}
void CMainFrame::OnDestroy()
{
CFrameWnd::OnDestroy();
// TODO: Add your message handler code here
//删除寻找标识
::RemoveProp(this->GetSafeHwnd(), AfxGetApp()->m_pszAppName);
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent == ID_TIMER_ABOUTDLG)
{
if(GetTickCount() - m_dwTime <= 3000)
{
if(m_nAlpha >= 255)
return;
HANDLE hInst = LoadLibrary("User32.DLL"); //显式加载DLL
if(hInst)
{
typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
MYFUNC fun = NULL;
fun=(MYFUNC)GetProcAddress((HMODULE)hInst, "SetLayeredWindowAttributes");//取得SetLayeredWindowAttributes函数指针
if(fun)
fun(m_pAboutDlg->GetSafeHwnd(), 0, (BYTE)m_nAlpha, 2);
FreeLibrary((HMODULE)hInst);
}
m_nAlpha += 10;
}
else
{
if(m_nAlpha <= 0)
{
KillTimer(ID_TIMER_ABOUTDLG);
m_pAboutDlg->ShowWindow(SW_HIDE);
m_dwTime = 0;
return;
}
HANDLE hInst = LoadLibrary("User32.DLL"); //显式加载DLL
if(hInst)
{
typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
MYFUNC fun = NULL;
fun=(MYFUNC)GetProcAddress((HMODULE)hInst, "SetLayeredWindowAttributes");//取得SetLayeredWindowAttributes函数指针
if(fun)
fun(m_pAboutDlg->GetSafeHwnd(), 0, (BYTE)m_nAlpha, 2);
FreeLibrary((HMODULE)hInst);
}
m_nAlpha -= 10;
}
}
CFrameWnd::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -