📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "PainterUsePattern.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//============================================================
//
//============================================================
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code !
ON_WM_CREATE()
ON_COMMAND(ID_VIEW_FULLSCREEN, OnFullscreen)
ON_COMMAND(ID_VIEW_STATUSBAR , OnHideStatusbar)
ON_COMMAND(ID_VIEW_TOOLBAR , OnHideToolbar)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//============================================================
//
//============================================================
/*状态栏元素*/
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_CLOCK,
ID_INDICATOR_MOUSE,
ID_INDICATOR_RECORD_NUM,//记录序号;
ID_INDICATOR_TABLE_NAME,//表名称;
};
//============================================================
//
//============================================================
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
m_fullScreen = false;
}
//============================================================
//
//============================================================
CMainFrame::~CMainFrame()
{
}
//============================================================
//
//============================================================
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
/*创建状态栏*/
CreateStatusBar();
/*创建工具栏*/
CreateToolBar();
/*创建画图工具栏*/
CreatePaintToolBar();
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
return TRUE;
}
//============================================================
//
//============================================================
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
//============================================================
//
//============================================================
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
//============================================================
//
//============================================================
int CMainFrame::CreateStatusBar()
{
//状态条
if( !m_wndStatusBar.Create( this ) ||
! m_wndStatusBar.SetIndicators( indicators,sizeof( indicators )/sizeof(UINT)))
{
TRACE0( "Failed to create status bar\n");
return -1;
}
CPoint point;
point.x = 0 ;
point.y = 0 ;
UpdateStatusBar( point , 0 , "NoName" );
return 1;
}
//============================================================
//
//============================================================
int CMainFrame::CreatePaintToolBar()
{
if (!m_painterToolBar.CreateEx(this, TBSTYLE_FLAT , WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_painterToolBar.LoadToolBar( IDR_PAINTER ))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
m_painterToolBar.EnableDocking( CBRS_ALIGN_ANY );//TOP|CBRS_ALIGN_BOTTOM).
EnableDocking( CBRS_ALIGN_ANY );
DockControlBar( &m_painterToolBar );
return 1;
}
//============================================================
//
//============================================================
int CMainFrame::CreateToolBar()
{
//-------------------------------------------------------------
//工具条
//-------------------------------------------------------------
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
}
/*加载工具条位图*/
/*
CImageList imageList;
CBitmap bitmap;
//Create and set the normal toolbar image list.
imageList.Create( 36, 36 , ILC_COLOR32 , 10 ,1 );
bitmap.LoadBitmap( IDB_HOT_NEW_FILE );//_COLD);
imageList.Add( &bitmap , RGB(255,0,255) );
bitmap.Detach();
bitmap.LoadBitmap( IDB_HOT_OPEN_FILE );//_COLD);
imageList.Add( &bitmap , RGB(255,0,255) );
bitmap.Detach();
bitmap.LoadBitmap( IDB_HOT_SAVE_FILE );//_COLD);
imageList.Add( &bitmap , RGB(255,0,255) );
bitmap.Detach();
bitmap.LoadBitmap( IDB_HOT_TOOL );//_COLD);
imageList.Add( &bitmap , RGB(255,0,255) );
bitmap.Detach();
bitmap.LoadBitmap( IDB_HOT_HELP );//_COLD);
imageList.Add( &bitmap , RGB(255,0,255) );
bitmap.Detach();
bitmap.LoadBitmap( IDB_FULL_SCREEN_1 );//_COLD);
imageList.Add( &bitmap , RGB(255,0,255) );
bitmap.Detach();
m_wndToolBar.SendMessage( TB_SETIMAGELIST , 0, ( LPARAM)imageList.m_hImageList );
imageList.Detach();
SIZE sizeButton,sizeImage;
sizeButton.cx = 45;
sizeButton.cy = 45;
sizeImage.cx = 36;
sizeImage.cy = 36;
m_wndToolBar.SetSizes( sizeButton , sizeImage );
*/
//设置工具条的停靠属性。
m_wndToolBar.EnableDocking( CBRS_ALIGN_ANY );//TOP|CBRS_ALIGN_BOTTOM).
EnableDocking( CBRS_ALIGN_ANY );
DockControlBar( &m_wndToolBar );
return 1;
}
//============================================================
//
//============================================================
void CMainFrame::UpdateStatusBar(CPoint point , int recordNum, CString tableName )
{
CString time;
CString mousePosition;
CString record;
CString table;
SYSTEMTIME tm;
BOOL bPM = TRUE;
if( m_fullScreen == false )
{
GetLocalTime( &tm );
if( tm.wHour >= 0 && tm.wHour < 12 )
bPM = FALSE;
if( tm.wHour > 12 )
tm.wHour -= 12;
else if( tm.wHour == 0 )
tm.wHour = 12;
time.Format( _T(" %d : %02.2d %s "), tm.wHour, tm.wMinute, ((bPM) ? _T("PM"):_T("AM")));
mousePosition.Format( _T("%d,%d"),point.x , point.y );
record.Format( _T("%d") , recordNum );
table = tableName;
UINT nID ;
UINT nStyle;
int nWidth ;
int nIndexClock;
int nIndexMouse;
int nIndexRecord;
int nIndexTable;
nIndexClock = m_wndStatusBar.CommandToIndex ( ID_INDICATOR_CLOCK );
nIndexMouse = m_wndStatusBar.CommandToIndex ( ID_INDICATOR_MOUSE );
nIndexRecord = m_wndStatusBar.CommandToIndex( ID_INDICATOR_RECORD_NUM);
nIndexTable = m_wndStatusBar.CommandToIndex( ID_INDICATOR_TABLE_NAME);
CClientDC dc(&m_wndStatusBar);
CFont* pOldFont = dc.SelectObject( m_wndStatusBar.GetFont());
CSize szExtentTime = dc.GetTextExtent( time , time.GetLength());
CSize szExtentMouse = dc.GetTextExtent( mousePosition,mousePosition.GetLength());
CSize szExtentRecord = dc.GetTextExtent( record , record.GetLength() );
CSize szExtentTable = dc.GetTextExtent( table , tableName.GetLength() );
dc.SelectObject( pOldFont );
m_wndStatusBar.GetPaneInfo( nIndexClock , nID , nStyle , nWidth );
m_wndStatusBar.SetPaneInfo( nIndexClock , nID , nStyle ,szExtentTime.cx );
m_wndStatusBar.SetPaneText( nIndexClock , time);
m_wndStatusBar.GetPaneInfo( nIndexMouse , nID , nStyle , nWidth );
m_wndStatusBar.SetPaneInfo( nIndexMouse , nID , nStyle ,szExtentMouse.cx );
m_wndStatusBar.SetPaneText( nIndexMouse , mousePosition );
m_wndStatusBar.GetPaneInfo( nIndexRecord , nID , nStyle , nWidth );
m_wndStatusBar.SetPaneInfo( nIndexRecord , nID , nStyle ,szExtentRecord.cx );
m_wndStatusBar.SetPaneText( nIndexRecord , record);
m_wndStatusBar.GetPaneInfo( nIndexTable , nID , nStyle , nWidth );
m_wndStatusBar.SetPaneInfo( nIndexTable , nID , nStyle ,szExtentTable.cx );
m_wndStatusBar.SetPaneText( nIndexTable , table);
}
}
//==================================================================================
//显示/隐藏状态栏;
//==================================================================================
void CMainFrame::OnHideStatusbar()
{
// TODO: Add your command handler code here
ShowControlBar( &m_wndStatusBar, !m_wndStatusBar.IsVisible(), FALSE);
}
//==================================================================================
//显示/隐藏工具条;
//==================================================================================
void CMainFrame::OnHideToolbar()
{
// TODO: Add your command handler code here
ShowControlBar( &m_wndToolBar, !m_wndToolBar.IsVisible(), FALSE);
}
//==================================================================================
//全屏显示功能;
//==================================================================================
void CMainFrame::OnFullscreen()
{
// TODO: Add your command handler code here
m_fullScreen = ( m_fullScreen == true ? false:true);
RECT rectDesktop;
WINDOWPLACEMENT wpNew;
if ( m_fullScreen == true )
{
// need to hide all status bars
if( m_wndToolBar.IsVisible() )
OnHideToolbar();
if( m_wndStatusBar.IsVisible() )
OnHideStatusbar();
// We'll need these to restore the original state.
GetWindowPlacement (&m_wpPrev);
m_wpPrev.length = sizeof m_wpPrev;
//Adjust RECT to new size of window
::GetWindowRect ( ::GetDesktopWindow(), &rectDesktop );
::AdjustWindowRectEx( &rectDesktop, GetStyle(), TRUE, GetExStyle());
// Remember this for OnGetMinMaxInfo()
m_FullScreenWindowRect = rectDesktop;
wpNew = m_wpPrev;
wpNew.showCmd = SW_SHOWNORMAL;
wpNew.rcNormalPosition = rectDesktop;
m_pwndFullScrnBar = new CToolBar;
if (!m_pwndFullScrnBar->Create(this,CBRS_SIZE_DYNAMIC|CBRS_FLOATING) ||
!m_pwndFullScrnBar->LoadToolBar(IDR_FULLSCREEN))
{
TRACE0("Failed to create toolbar\n");
return; // fail to create
}
//don't allow the toolbar to dock
m_pwndFullScrnBar->EnableDocking(0);
m_pwndFullScrnBar->SetWindowPos(0, 100,100, 0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW);
m_pwndFullScrnBar->SetWindowText(_T("Full Screen"));
FloatControlBar(m_pwndFullScrnBar, CPoint(100,100));
}
else
{
if( !m_wndToolBar.IsVisible() )
OnHideToolbar();
if( !m_wndStatusBar.IsVisible() )
OnHideStatusbar();
m_pwndFullScrnBar->DestroyWindow();
delete m_pwndFullScrnBar;
wpNew = m_wpPrev;
}
SetWindowPlacement ( &wpNew );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -