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

📄 mainfrm.cpp

📁 文本文件读写及图形显示.(1) 自学随机数的生成
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "ZhengyAppWizard.h"
#include "MainFrm.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()
	//}}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
	
}

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);
    
	
	    //加载图标
	    zy_Icons[0]=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON_Z));
		zy_Icons[1]=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON_h));
		zy_Icons[2]=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON_e));
		zy_Icons[3]=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON_n));
		zy_Icons[4]=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON_g));
		zy_Icons[5]=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON_y));
		SetClassLong(m_hWnd,GCL_HICON,(LONG)zy_Icons[0]);//替换第1次
		
	 	
		//显示时间

     	CTime  zy_time=CTime::GetCurrentTime();
        CString  zy_timestr=zy_time.Format("%H:%M:%S");
        CClientDC  zy_dc(this);
        CSize   zy_timesz=zy_dc.GetTextExtent(zy_timestr);
        m_wndStatusBar.SetPaneInfo(1,1,SBPS_NORMAL,zy_timesz.cx);//设置状态栏信息
        m_wndStatusBar.SetPaneText(1,zy_timestr);//设置文本
		
		//添加时钟
		SetTimer(1,1000,NULL);	
	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="ZhengyAppWizard";
	
	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 index=1;
	SetClassLong(m_hWnd,GCL_HICON,(LONG)zy_Icons[index]);//替换所属类的结构
	index=++index%6;  //让变量在0-6之间 取模
  
	//显示时间

	CTime  zy_time=CTime::GetCurrentTime();//获取时间
    CString  zy_timestr=zy_time.Format("%H:%M:%S");//转为字符
    CClientDC  zy_dc(this);
    CSize   zy_timesz=zy_dc.GetTextExtent(zy_timestr);//获取显示的时间文本信息
	RECT zy_rect;
	GetClientRect(&zy_rect);
    m_wndStatusBar.SetPaneInfo(1,1,SBPS_NORMAL,zy_timesz.cx);//设置状态栏信息
    m_wndStatusBar.SetPaneText(1,zy_timestr);//设置文本

    //跑马灯
	static CString  zy_str1="                                                                                                                                          软件0508班  郑岩 051201254";
    static int zy_i=(zy_rect.right-zy_rect.left-250)/4;//长度
	static int zy_j=zy_i;//保留
    //char ch[4];
	//itoa(zy_i,ch,10);
	//m_wndStatusBar.SetPaneText(0, ch);
	if(zy_i>0)
	{ 
	   zy_i=zy_i-3;
       m_wndStatusBar.SetPaneText(0, zy_str1.Right(zy_i));//设置
	}
    else zy_i=zy_j;
	
	
	CFrameWnd::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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