VC++题目,求解
课程题目:创建一个含有两个编辑框控件和两个按钮控件的应用程序,按钮功能分别死“显示字符”和“显示字符数”,当在编辑框中输入某一个字符串并单击“显示字符”按钮时,在另外一个编辑框中输出此字符串;当单击“显示字符串”按钮时,在输出框中显示该字符串的字符个数。若能帮忙吧这个作业成功解决,可留下QQ号码,春节前后将酌情给予QB,急急急!!!
追问:来自手机问问不用了,作业已经弄好了,请留下号码,到时根据作业分数酌情送QB,春节前后直接充入帐号
追问:来自手机问问不用了,作业已经弄好了,请留下号码,到时根据作业分数酌情送QB,春节前后直接充入帐号
答案:运行截图
程序:
// XRabbitMFCDlg.cpp : implementation file
//#include "stdafx.h"
#include "XRabbitMFC.h"
#include "XRabbitMFCDlg.h"
#include "afxdialogex.h"#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CXRabbitMFCDlg dialog
CXRabbitMFCDlg::CXRabbitMFCDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CXRabbitMFCDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_Edit1 = _T("");
m_Edit2 = _T("");
}void CXRabbitMFCDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, m_Edit1);
DDX_Text(pDX, IDC_EDIT2, m_Edit2);
DDX_Control(pDX, IDC_BUTTON1, m_Btn1);
DDX_Control(pDX, IDC_BUTTON2, m_Btn2);
}BEGIN_MESSAGE_MAP(CXRabbitMFCDlg, CDialogEx)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, &CXRabbitMFCDlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, &CXRabbitMFCDlg::OnBnClickedButton2)
END_MESSAGE_MAP()
// CXRabbitMFCDlg message handlersBOOL CXRabbitMFCDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.void CXRabbitMFCDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for paintingSendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CXRabbitMFCDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CXRabbitMFCDlg::OnBnClickedButton1()
{
UpdateData(TRUE); // 从控件读数据
m_Edit2 = m_Edit1; // 赋值
UpdateData(FALSE); // 更新控件数据
}
void CXRabbitMFCDlg::OnBnClickedButton2()
{
UpdateData(TRUE); // 从控件读数据
m_Edit2.Format(_T("字符长度为 %d"), m_Edit1.GetLength());
UpdateData(FALSE);
}
上一个:vc++编程求解
下一个:什么是Win32 MFC VB VC++ ?