📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "htmlhelp.h"
#include "imageCAM.h"
#include "imageCAMDoc.h"
#include "imageCAMView.h"
#include "MainFrm.h"
#include "toolbase.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_PALETTECHANGED()
ON_WM_QUERYNEWPALETTE()
ON_COMMAND(IDC_FULLSCREEN, OnFullscreen)
ON_UPDATE_COMMAND_UI(IDC_FULLSCREEN, OnUpdateFullscreen)
ON_WM_GETMINMAXINFO()
ON_COMMAND(IDM_PAINTTOOL, OnPainttool)
ON_UPDATE_COMMAND_UI(IDM_PAINTTOOL, OnUpdatePainttool)
ON_COMMAND(IDM_PAINTPARAM, OnPaintparam)
ON_UPDATE_COMMAND_UI(IDM_PAINTPARAM, OnUpdatePaintparam)
ON_COMMAND(IDM_TEXTTOOL, OnTexttool)
ON_UPDATE_COMMAND_UI(IDM_TEXTTOOL, OnUpdateTexttool)
ON_WM_KEYDOWN()
ON_COMMAND(IDM_VIEWTOOL, OnViewtool)
ON_UPDATE_COMMAND_UI(IDM_VIEWTOOL, OnUpdateViewtool)
//}}AFX_MSG_MAP
// Global help commands
ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_SEPARATOR,
ID_SEPARATOR,
ID_SEPARATOR,
ID_SEPARATOR,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
m_bFullScreen=false;
m_wndStatusBarVisible=false;
m_wndToolBarVisible=false;
m_wndTextToolBarVisible=false;
m_wndPaintToolBarVisible=false;
m_wndPaintParamBarVisible=false;
m_wndViewToolBarVisible=false;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::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
}
// initialize m_wndStatusBar.....
// add panes
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
}
m_wndStatusBar.SetPaneInfo( PANE_LENGTH_UNIT, ID_SEPARATOR, SBPS_NORMAL, 25);
m_wndStatusBar.SetPaneInfo( PANE_CURSOR_POSITION, ID_SEPARATOR, SBPS_NORMAL, 72);
m_wndStatusBar.SetPaneInfo( PANE_IMAGE_SIZE, ID_SEPARATOR, SBPS_NORMAL, 72);
m_wndStatusBar.SetPaneInfo( PANE_BIT_COUNT, ID_SEPARATOR, SBPS_NORMAL, 28);
// 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);
// initialize m_wndPaintToolBar.....
if (!m_wndPaintToolBar.Create(this, WS_CHILD|CBRS_SIZE_FIXED|CBRS_RIGHT|CBRS_TOOLTIPS, 0x1208) ||
!m_wndPaintToolBar.LoadToolBar(IDR_PAINTTOOL))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
m_wndPaintToolBar.SetWindowText(_T("绘图工具"));
m_wndPaintToolBar.EnableDocking(CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT);
DockControlBar(&m_wndPaintToolBar);
m_wndPaintToolBar.SetColumns(1);
// Initialize m_wndPaintParamBar.....
if (!m_wndPaintParamBar.Create(this, IDD_PAINTPARAM, CBRS_TOOLTIPS|CBRS_LEFT|CBRS_FLYBY|CBRS_HIDE_INPLACE,0x1209))
{
TRACE0("Failed to create dialogbar m_wndPaintParamBar\n");
return -1; // fail to create
}
m_wndPaintParamBar.SetWindowText(_T("调色板"));
m_wndPaintParamBar.EnableDocking(CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT);
DockControlBar(&m_wndPaintParamBar);
ShowControlBar(&m_wndPaintParamBar, FALSE, FALSE);
// initialize text toolbar...
if (!m_wndTextToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, CRect(0, 0, 0, 0), 0x1210) ||
!m_wndTextToolBar.LoadToolBar(IDR_TEXTTOOL))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
m_wndTextToolBar.SetWindowText(_T("文字工具栏"));
m_wndTextToolBar.EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndTextToolBar);
if (!m_wndViewToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, CRect(0, 0, 0, 0), 0x1211) ||
!m_wndViewToolBar.LoadToolBar(IDR_VIEWTOOL))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
m_wndViewToolBar.SetWindowText(_T("视图工具栏"));
m_wndViewToolBar.EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndViewToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWnd::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_MAXIMIZE;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnPaletteChanged(CWnd* pFocusWnd)
{
CMDIFrameWnd::OnPaletteChanged(pFocusWnd);
// TODO: Add your message handler code here
// always realize the palette for the active view
CMDIChildWnd* pMDIChildWnd = MDIGetActive();
if (pMDIChildWnd == NULL)
return; // no active MDI child frame
CView* pView = pMDIChildWnd->GetActiveView();
ASSERT(pView != NULL);
// notify all child windows that the palette has changed
SendMessageToDescendants(WM_REALIZEPAL, (WPARAM)pView->m_hWnd);
}
BOOL CMainFrame::OnQueryNewPalette()
{
// TODO: Add your message handler code here and/or call default
// always realize the palette for the active view
CMDIChildWnd* pMDIChildWnd = MDIGetActive();
if (pMDIChildWnd == NULL)
return FALSE; // no active MDI child frame (no new palette)
CView* pView = pMDIChildWnd->GetActiveView();
ASSERT(pView != NULL);
// just notify the target view
pView->SendMessage(WM_REALIZEPAL, (WPARAM)pView->m_hWnd);
return TRUE;
}
void CMainFrame::OnFullscreen()
{//全屏幕显示的处理函数
RECT rectDesktop;
WINDOWPLACEMENT wpNew;
//m_bFullScreen=!m_bFullScreen;
if (!m_bFullScreen)
{//全屏幕显示模式
//隐藏工具条和状态条
m_wndStatusBarVisible=m_wndStatusBar.IsWindowVisible();
if(m_wndStatusBarVisible)
m_wndStatusBar.ShowWindow(SW_HIDE);
m_wndToolBarVisible=m_wndToolBar.IsWindowVisible();
if(m_wndToolBarVisible)
m_wndToolBar.ShowWindow(SW_HIDE);
m_wndTextToolBarVisible=m_wndTextToolBar.IsWindowVisible();
if(m_wndTextToolBarVisible)
m_wndTextToolBar.ShowWindow(SW_HIDE);
m_wndPaintToolBarVisible=m_wndPaintToolBar.IsWindowVisible();
if(m_wndPaintToolBarVisible)
m_wndPaintToolBar.ShowWindow(SW_HIDE);
m_wndPaintParamBarVisible=m_wndPaintParamBar.IsWindowVisible();
if(m_wndPaintParamBarVisible)
m_wndPaintParamBar.ShowWindow(SW_HIDE);
m_wndViewToolBarVisible=m_wndViewToolBar.IsWindowVisible();
if(m_wndPaintParamBarVisible)
m_wndViewToolBar.ShowWindow(SW_HIDE);
//保存正常视图时的窗口位置信息以便恢复原来状态
GetWindowPlacement (&m_wpPrev);
m_wpPrev.length = sizeof( m_wpPrev);
//调整RECT为新的窗口尺寸
::GetWindowRect ( ::GetDesktopWindow(), &rectDesktop );
::AdjustWindowRectEx(&rectDesktop, GetStyle(), TRUE,
GetExStyle());
//保存RECT以便OnGetMinMaxInfo()使用
m_FullScreenWindowRect = rectDesktop;
wpNew = m_wpPrev;
wpNew.showCmd = SW_SHOWNORMAL;
wpNew.rcNormalPosition = rectDesktop;
//生成新的工具条
m_wndFullScreenBar=new CToolBar;
if(!m_wndFullScreenBar->Create(this,
CBRS_SIZE_DYNAMIC|CBRS_FLOATING)
|| !m_wndFullScreenBar->LoadToolBar(IDR_FULLSCREEN))
{
TRACE0("Failed to create toolbar\n");
return; // fail to create
}
//不允许工具条停泊
m_wndFullScreenBar->EnableDocking(FALSE);
m_wndFullScreenBar->SetWindowPos(0,100,100,0,0,SWP_NOSIZE
|SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW);
m_wndFullScreenBar->SetWindowText(_T("全屏幕显示"));
FloatControlBar(m_wndFullScreenBar, CPoint(100,100));
m_bFullScreen=TRUE;
}
else
{//正常显示模式
//删除全屏幕工具条
m_wndFullScreenBar->DestroyWindow();
delete m_wndFullScreenBar;
m_bFullScreen=FALSE;
//恢复工具条和状态条
if(m_wndStatusBarVisible)
m_wndStatusBar.ShowWindow(SW_SHOWNORMAL);
if(m_wndToolBarVisible)
m_wndToolBar.ShowWindow(SW_SHOWNORMAL);
if(m_wndTextToolBarVisible)
m_wndTextToolBar.ShowWindow(SW_SHOWNORMAL);
if(m_wndPaintToolBarVisible)
m_wndPaintToolBar.ShowWindow(SW_SHOWNORMAL);
if(m_wndPaintParamBarVisible)
m_wndPaintParamBar.ShowWindow(SW_SHOWNORMAL);
if(m_wndViewToolBarVisible)
m_wndViewToolBar.ShowWindow(SW_SHOWNORMAL);
wpNew = m_wpPrev;
}
//设置窗口显示状态
SetWindowPlacement ( &wpNew );
}
void CMainFrame::OnUpdateFullscreen(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable();
pCmdUI->SetCheck(m_bFullScreen);
}
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// TODO: Add your message handler code here and/or call default
if (m_bFullScreen)
{
lpMMI->ptMaxSize.y = m_FullScreenWindowRect.Height();
lpMMI->ptMaxTrackSize.y = lpMMI->ptMaxSize.y;
lpMMI->ptMaxSize.x = m_FullScreenWindowRect.Width();
lpMMI->ptMaxTrackSize.x = lpMMI->ptMaxSize.x;
}
// CMDIFrameWnd::OnGetMinMaxInfo(lpMMI);
}
/*void CMainFrame::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar==VK_ESCAPE)
{
SendMessage(WM_COMMAND,0,IDC_FULLSCREEN);
}
CMDIFrameWnd::OnKeyDown(nChar, nRepCnt, nFlags);
}*/
void CMainFrame::OnPainttool()
{
// TODO: Add your command handler code here
BOOL bVisible = ((m_wndPaintToolBar.GetStyle() & WS_VISIBLE) != 0);
ShowControlBar(&m_wndPaintToolBar, !bVisible, FALSE);
RecalcLayout();
GetMenu()->CheckMenuItem(IDM_PAINTTOOL,
(bVisible ? MF_UNCHECKED : MF_CHECKED)|MF_BYCOMMAND);
}
void CMainFrame::OnUpdatePainttool(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
BOOL bVisible = ((m_wndPaintToolBar.GetStyle() & WS_VISIBLE) != 0);
pCmdUI->SetCheck(bVisible);
}
void CMainFrame::OnPaintparam()
{
// TODO: Add your command handler code here
BOOL bVisible = ((m_wndPaintParamBar.GetStyle() & WS_VISIBLE) != 0);
ShowControlBar(&m_wndPaintParamBar, !bVisible, FALSE);
RecalcLayout();
GetMenu()->CheckMenuItem(IDM_PAINTPARAM,
(bVisible ? MF_UNCHECKED : MF_CHECKED)|MF_BYCOMMAND);
}
void CMainFrame::OnUpdatePaintparam(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
BOOL bVisible = ((m_wndPaintParamBar.GetStyle() & WS_VISIBLE) != 0);
pCmdUI->SetCheck(bVisible);
}
void CMainFrame::OnTexttool()
{
// TODO: Add your command handler code here
BOOL bVisible = ((m_wndTextToolBar.GetStyle() & WS_VISIBLE) != 0);
ShowControlBar(&m_wndTextToolBar, !bVisible, FALSE);
RecalcLayout();
GetMenu()->CheckMenuItem(IDM_TEXTTOOL,
(bVisible ? MF_UNCHECKED : MF_CHECKED)|MF_BYCOMMAND);
}
void CMainFrame::OnUpdateTexttool(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
BOOL bVisible = ((m_wndTextToolBar.GetStyle() & WS_VISIBLE) != 0);
pCmdUI->SetCheck(bVisible);
}
void CMainFrame::OnViewtool()
{
// TODO: Add your command handler code here
BOOL bVisible = ((m_wndViewToolBar.GetStyle() & WS_VISIBLE) != 0);
ShowControlBar(&m_wndViewToolBar, !bVisible, FALSE);
RecalcLayout();
GetMenu()->CheckMenuItem(IDM_VIEWTOOL,
(bVisible ? MF_UNCHECKED : MF_CHECKED)|MF_BYCOMMAND);
}
void CMainFrame::OnUpdateViewtool(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
BOOL bVisible = ((m_wndViewToolBar.GetStyle() & WS_VISIBLE) != 0);
pCmdUI->SetCheck(bVisible);
}
void CMainFrame::WinHelp(DWORD dwData, UINT nCmd)
{
// TODO: Add your specialized code here and/or call the base class
CWinApp* pApp = AfxGetApp();
ASSERT_VALID(pApp);
ASSERT(pApp->m_pszHelpFilePath != NULL);
CWaitCursor wait;
if (IsFrameWnd())
{
// CFrameWnd windows should be allowed to exit help mode first
CFrameWnd* pFrameWnd = (CFrameWnd*)this;
pFrameWnd->ExitHelpMode();
}
// cancel any tracking modes
SendMessage(WM_CANCELMODE);
SendMessageToDescendants(WM_CANCELMODE, 0, 0, TRUE, TRUE);
// need to use top level parent (for the case where m_hWnd is in DLL)
CWnd* pWnd = GetTopLevelParent();
pWnd->SendMessage(WM_CANCELMODE);
pWnd->SendMessageToDescendants(WM_CANCELMODE, 0, 0, TRUE, TRUE);
// attempt to cancel capture
HWND hWndCapture = ::GetCapture();
if (hWndCapture != NULL)
::SendMessage(hWndCapture, WM_CANCELMODE, 0, 0);
int command;
switch (nCmd)
{
case HELP_CONTEXT:
TRACE("HELP_CONTEXT request\n");
command = HH_HELP_CONTEXT;
break;
case HELP_FINDER:
TRACE("HELP_FINDER request\n");
command = HH_DISPLAY_TOPIC;
break;
}
TRACE3("In HtmlHelp: pszHelpFile = '%s', dwData: $%lx, fuCommand: %d.\n",
pApp->m_pszHelpFilePath, dwData, nCmd);
// finally, run the Windows Help engine
if (!HtmlHelp(pWnd->m_hWnd, pApp->m_pszHelpFilePath, command, dwData))
AfxMessageBox(AFX_IDP_FAILED_TO_LAUNCH_HELP);
//CMDIFrameWnd::WinHelp(dwData, nCmd);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -