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

📄 textfrm.cpp

📁 《Visual C++.NET MFC类库应用详解》程序实例
💻 CPP
字号:
// TextFrm.cpp : implementation of the CTextFrame class
//

#include "stdafx.h"
#include "MThread.h"
#include "TextFrm.h"
#include "math.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CTextFrame

IMPLEMENT_DYNCREATE(CTextFrame, CMDIChildWnd)

BEGIN_MESSAGE_MAP(CTextFrame, CMDIChildWnd)
	ON_COMMAND(ID_FILE_CLOSE, OnFileClose)
	ON_WM_SETFOCUS()
	ON_WM_CREATE()
	ON_COMMAND(ID_FILE_PRIME, OnFilePrime)
END_MESSAGE_MAP()

// CTextFrame construction/destruction

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

CTextFrame::~CTextFrame()
{
}

BOOL CTextFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	if( !CMDIChildWnd::PreCreateWindow(cs) )
		return FALSE;

	cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
	cs.lpszClass = AfxRegisterWndClass(0);

	return TRUE;
}



// CTextFrame diagnostics

#ifdef _DEBUG
void CTextFrame::AssertValid() const
{
	CMDIChildWnd::AssertValid();
}

void CTextFrame::Dump(CDumpContext& dc) const
{
	CMDIChildWnd::Dump(dc);
}

#endif //_DEBUG

// CTextFrame message handlers
void CTextFrame::OnFileClose() 
{
	// To close the frame, just send a WM_CLOSE, which is the equivalent
	// choosing close from the system menu.

	SendMessage(WM_CLOSE);
}

int CTextFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// create a view to occupy the client area of the frame
	if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, 
		CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
	{
		TRACE0("Failed to create view window\n");
		return -1;
	}

	return 0;
}

void CTextFrame::OnSetFocus(CWnd* pOldWnd) 
{
	CMDIChildWnd::OnSetFocus(pOldWnd);

	m_wndView.SetFocus();
}

BOOL CTextFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
{
	// let the view have first crack at the command
	if (m_wndView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
		return TRUE;
	
	// otherwise, do default handling
	return CMDIChildWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

UINT Calculateprime(LPVOID hWnd)
{
	long m,k,i;
    int n=0;
	CString str;
    for(m=1;m<=1000000;m=m+2)
    {
       k=sqrt(m);
       for(i=2;i<=k;i++)
      	  if(m%i==0)break;
       if(i>=k+1)
		   n=n+1;
   }	
   str.Format("The Prime Numbers from 1 to 1000000 is %ld.",n);
   AfxMessageBox(str);
   return (0);
}

void CTextFrame::OnFilePrime() 
{
	// TODO: Add your command handler code here
    AfxBeginThread(Calculateprime,&m_hWnd,THREAD_PRIORITY_BELOW_NORMAL,0);
}

⌨️ 快捷键说明

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