⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 VC++ MFC 用户图形界面设计及改变测试
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "User Interfurce.h"

#include "MainFrm.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_TIMER()
	ON_COMMAND(IDM_TEST, OnTest)
	ON_COMMAND(IDM_TEST_DISPLAY, OnTestDisplay)
	ON_UPDATE_COMMAND_UI(IDM_TEST_DISPLAY, OnUpdateTestDisplay)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR, // status line indicator
 	IDS_TIMER,
	IDS_PROGRESS,
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,


};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	
}

CMainFrame::~CMainFrame()
{
}

extern CUserInterfurceApp theApp;
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);

/*	SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE)&~FWS_ADDTOTITLE);*/
    //  [1/27/2009 15:15:59 Liuj]
    m_hIcons[0] = LoadIcon(theApp.m_hInstance,MAKEINTRESOURCE(IDI_ICON1));
	m_hIcons[1] = LoadIcon(theApp.m_hInstance,MAKEINTRESOURCE(IDI_ICON2));
	m_hIcons[2] = LoadIcon(theApp.m_hInstance,MAKEINTRESOURCE(IDI_ICON3));

	SetTimer(1,1000,NULL);

	SetClassLong(m_hWnd,GCL_HICON,(LONG)m_hIcons[0]);
    if (!m_testToolBar.CreateEx(this,TBSTYLE_FLAT,WS_CHILD|WS_VISIBLE|CBRS_TOP|CBRS_FLYBY|CBRS_GRIPPER/*|CBRS_FLOAT_MULTI*/)||!m_testToolBar.LoadToolBar(IDR_TOOLBAR_TEST))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}
    m_testToolBar.EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_testToolBar);  


	CTime time = CTime::GetCurrentTime();
	CString strTime = time.Format(_T("%H:%M:%S"));

	CClientDC dc(this);
	CSize size = dc.GetTextExtent(strTime);
    int nIndex = 0;
	nIndex = m_wndStatusBar.CommandToIndex(IDS_TIMER);
	m_wndStatusBar.SetPaneInfo(nIndex,IDS_TIMER,WS_CHILD | WS_VISIBLE /*| CBRS_BOTTOM*/,size.cx);
	m_wndStatusBar.SetPaneText(nIndex,strTime);


	// CG: The following line was added by the Splash Screen component.	CStartUp::ShowSplashScreen(this);
    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

    //  [1/27/2009 0:30 Liuj]
// 	cs.cx = 1000;
// 	cs.cy = 600;
/*	cs.lpszName = _T("新浪体育");*/
  /*      cs.style &= ~FWS_ADDTOTITLE;*/

	//  [1/27/2009 0:31:10 Liuj]
/*	WNDCLASS newwndclass;
	newwndclass.cbClsExtra = 0;
	newwndclass.cbWndExtra = 0;
	newwndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	newwndclass.hCursor = LoadCursor(NULL,IDC_CROSS);
	newwndclass.hIcon = LoadIcon(NULL,IDI_WARNING);
	newwndclass.hInstance = AfxGetInstanceHandle();
	newwndclass.lpfnWndProc = ::DefWindowProc;
	newwndclass.lpszClassName = _T("dimple");
	newwndclass.lpszMenuName = NULL;
    newwndclass.style = CS_HREDRAW | CS_VREDRAW;
	RegisterClass(&newwndclass);

	cs.lpszClass = _T("dimple");*/
    //  [1/27/2009 15:35:59 Liuj]
	/*cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,0,0,LoadIcon(NULL,IDI_WARNING));*/

	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


void CMainFrame::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	static int nindex = 0;
	int a = nindex++%3;
	SetClassLong(m_hWnd,GCL_HICON,(LONG)m_hIcons[a]);

    CTime time = CTime::GetCurrentTime();
	CString strTime = time.Format(_T("%H:%M:%S"));

	CClientDC dc(this);
	CSize size = dc.GetTextExtent(strTime);
    int nIndex = 0;
	nIndex = m_wndStatusBar.CommandToIndex(IDS_TIMER);
	m_wndStatusBar.SetPaneInfo(nIndex,IDS_TIMER,WS_CHILD | WS_VISIBLE /*| CBRS_BOTTOM*/,size.cx);
	m_wndStatusBar.SetPaneText(nIndex,strTime);

	m_progress.StepIt();
	CFrameWnd::OnTimer(nIDEvent);
}

void CMainFrame::OnTest() 
{
	// TODO: Add your command handler code here
	int a = 10;
	int& b = a;
	a = 37;
	b=100;
	CString str;
	str.Format(_T("%d"),a);
	AfxMessageBox(str);
	AfxMessageBox(_T("我选择,我喜欢!"));
}

void CMainFrame::OnTestDisplay() 
{
	// TODO: Add your command handler code here
// 	if (m_testToolBar.IsVisible())
// 	{
// 		m_testToolBar.ShowWindow(SW_HIDE);
// 	}
// 	else
// 	{
// 		m_testToolBar.ShowWindow(SW_NORMAL);
// 	}
// 	RecalcLayout(FALSE);
/*	DockControlBar(&m_testToolBar);*/
	ShowControlBar(&m_testToolBar,!m_testToolBar.IsVisible(),FALSE);
}

void CMainFrame::OnUpdateTestDisplay(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_testToolBar.IsVisible());
}

void CMainFrame::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	// [1/28/2009 1:41:40 Liuj]
	CRect rect;
	m_wndStatusBar.GetItemRect(2,&rect);

    
	if (!m_progress.m_hWnd)
	{
		m_progress.Create(WS_VISIBLE|WS_CHILD|PBS_SMOOTH,rect,&m_wndStatusBar,123);
		m_progress.SetRange(0,100);
		m_progress.SetStep(10);
	}
	else
		m_progress.MoveWindow(rect);

	m_progress.SetPos(0);
	// Do not call CFrameWnd::OnPaint() for painting messages
}
#include "Splash.h"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -