www.pudn.com > PBMS.rar > MainFrm.cpp
//==================================================================//
// 此项目飞狼工作室制作
//项 目 名: PBMS
//项目描述: 这是为了方便图书管理的软件。 功能特点:多用户、信息保密、还书提醒、资料保存。
//作 者: 龚勋
//日 期: 2003-11-14
//-=================================================================//
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "PBMS.h"
#include "MainFrm.h"
#include "LeftView.h"
#include "PBMSView.h"
#include "Splash.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_PAINT()
ON_COMMAND(ID_SYS_DISPLAY, OnSysDisplay)
ON_COMMAND(ID_HELP_INDEX, OnHelpIndex)
//}}AFX_MSG_MAP
ON_UPDATE_COMMAND_UI_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnUpdateViewStyles)
ON_COMMAND_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnViewStyle)
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);
//*========修改工具栏显示===========================*//
Create256ToolBarImage(&m_ToolBarImage);
m_wndToolBar.GetToolBarCtrl().SetImageList(&m_ToolBarImage);
//***=根据分辨率来确定工具栏的高度=***//
DEVMODE lpDevMode;
::EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&lpDevMode);
if (lpDevMode.dmPelsWidth == 800)//分辨率在800 * 600
{
m_wndToolBar.SetSizes(CSize(50,50),CSize(32,32));
}
else//分辨率在1024 * 768
{
m_wndToolBar.SetSizes(CSize(60,60),CSize(32,32));
}
//***==============================***//
m_wndToolBar.SetButtonText(0," 添加用户 ");
m_wndToolBar.SetButtonText(1," 删除用户 ");
m_wndToolBar.SetButtonText(2," 添加图书馆 ");
m_wndToolBar.SetButtonText(3," 删除图书馆 ");
m_wndReBar.Create(this);
m_wndReBar.AddBar(&m_wndToolBar);
//*=================================================*//
// CG: The following line was added by the Splash Screen component.
CSplashWnd::ShowSplashScreen(this);
return 0;
}
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
CCreateContext* pContext)
{
// create splitter window
if (!m_wndSplitter.CreateStatic(this, 1, 2, WS_CHILD | WS_VISIBLE))
return FALSE;
if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftView), CSize(200, 100), pContext) ||
!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CPBMSView), CSize(100, 100), pContext))
{
m_wndSplitter.DestroyWindow();
return FALSE;
}
return TRUE;
}
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 = WS_OVERLAPPED | WS_CAPTION //| FWS_ADDTOTITLE//去掉“无标题”
| WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MINIMIZE;
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
CPBMSView* CMainFrame::GetRightPane()
{
CWnd* pWnd = m_wndSplitter.GetPane(0, 1);
CPBMSView* pView = DYNAMIC_DOWNCAST(CPBMSView, pWnd);
return pView;
}
void CMainFrame::OnUpdateViewStyles(CCmdUI* pCmdUI)
{
// TODO: customize or extend this code to handle choices on the
// View menu.
CPBMSView* pView = GetRightPane();
// if the right-hand pane hasn't been created or isn't a view,
// disable commands in our range
if (pView == NULL)
pCmdUI->Enable(FALSE);
else
{
DWORD dwStyle = pView->GetStyle() & LVS_TYPEMASK;
// if the command is ID_VIEW_LINEUP, only enable command
// when we're in LVS_ICON or LVS_SMALLICON mode
if (pCmdUI->m_nID == ID_VIEW_LINEUP)
{
if (dwStyle == LVS_ICON || dwStyle == LVS_SMALLICON)
pCmdUI->Enable();
else
pCmdUI->Enable(FALSE);
}
else
{
// otherwise, use dots to reflect the style of the view
pCmdUI->Enable();
BOOL bChecked = FALSE;
switch (pCmdUI->m_nID)
{
case ID_VIEW_DETAILS:
bChecked = (dwStyle == LVS_REPORT);
break;
case ID_VIEW_SMALLICON:
bChecked = (dwStyle == LVS_SMALLICON);
break;
case ID_VIEW_LARGEICON:
bChecked = (dwStyle == LVS_ICON);
break;
case ID_VIEW_LIST:
bChecked = (dwStyle == LVS_LIST);
break;
default:
bChecked = FALSE;
break;
}
pCmdUI->SetRadio(bChecked ? 1 : 0);
}
}
}
void CMainFrame::OnViewStyle(UINT nCommandID)
{
// TODO: customize or extend this code to handle choices on the
// View menu.
CPBMSView* pView = GetRightPane();
// if the right-hand pane has been created and is a CPBMSView,
// process the menu commands...
if (pView != NULL)
{
DWORD dwStyle = -1;
switch (nCommandID)
{
case ID_VIEW_LINEUP:
{
// ask the list control to snap to grid
CListCtrl& refListCtrl = pView->GetListCtrl();
refListCtrl.Arrange(LVA_SNAPTOGRID);
}
break;
// other commands change the style on the list control
case ID_VIEW_DETAILS:
dwStyle = LVS_REPORT;
break;
case ID_VIEW_SMALLICON:
dwStyle = LVS_SMALLICON;
break;
case ID_VIEW_LARGEICON:
dwStyle = LVS_ICON;
break;
case ID_VIEW_LIST:
dwStyle = LVS_LIST;
break;
}
// change the style; window will repaint automatically
if (dwStyle != -1)
pView->ModifyStyle(LVS_TYPEMASK, dwStyle);
}
}
/*=========================Create256ToolBarImage======================================
说明:
创建256色的CImageList,图形来自Icon.
参数:
pImageList:即是返回的CImageList
====================================================================================*/
void CMainFrame::Create256ToolBarImage(CImageList *pImageList)
{
//设置ToolBar的图标列表
pImageList->Create(32, 32, TRUE | ILC_COLOR32, 4, 0);
HICON hIcon = NULL;
hIcon = (HICON)::LoadImage(::AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_TOOL_ICON1), IMAGE_ICON, 32, 32, 0);
pImageList->Add(hIcon);
hIcon = (HICON)::LoadImage(::AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_TOOL_ICON2), IMAGE_ICON, 32, 32, 0);
pImageList->Add(hIcon);
hIcon = (HICON)::LoadImage(::AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_TOOL_ICON3), IMAGE_ICON, 32, 32, 0);
pImageList->Add(hIcon);
hIcon = (HICON)::LoadImage(::AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_TOOL_ICON4), IMAGE_ICON, 32, 32, 0);
pImageList->Add(hIcon);
}
void CMainFrame::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CFrameWnd::OnPaint() for painting messages
}
/*=========================WindowProc================================================
说明:
重载此函数主要是为了处理托盘消息
====================================================================================*/
LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
//处理托盘信息
switch(message)
{
//若是点击托盘的消息
case WM_MYTRAY:
//由托盘类自行处理具体事件
mmtray.DealMessage(wParam,lParam);
return 0;
case WM_SYSCOMMAND:
//截获最小化消息
if(wParam==SC_MINIMIZE)
{
mmtray.SetProper(IDR_TRAY,IDR_MAINFRAME,WM_MYTRAY,"个人图书管理系统");
mmtray.SetIcon();
return 0;
}
break;
case WM_MINI:
mmtray.SetProper(IDR_TRAY,IDR_MAINFRAME,WM_MYTRAY,"个人图书管理系统");
mmtray.SetIcon();
return 0;
default:
break;
}//end-switch
return CFrameWnd::WindowProc(message, wParam, lParam);
}
/*=========================OnSysDisplay===============================================
说明:
托盘菜单处理函数:恢复主框架显示
====================================================================================*/
void CMainFrame::OnSysDisplay()
{
mmtray.ResumeMain();
}
BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
return CFrameWnd::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext);
}
void CMainFrame::OnHelpIndex()
{
//*===============首先指定帮助文件存放路径============*//
char dbpath[128]; //数据库Path
::GetModuleFileName(NULL,dbpath,128); //获取路径
int index,i=0;
while(dbpath[i] != '\0')
{
if( dbpath[i] == '\\' )
{
index = i;
}
i ++ ;
}
char *filename = "帮助.chm";
while ( *filename != '\0')
{
dbpath[++index] = *filename;
filename ++;
}
dbpath[++index] = '\0'; //添加字符串结束符
//*=================================================*//
HWND helpwnd = HtmlHelp(GetSafeHwnd(),dbpath,HH_DISPLAY_INDEX,(DWORD)"帮助");
}