热门搜索 :
考研考公

用vc编个记事本程序的小问题

发布网友 发布时间:28分钟前

我来回答

2个回答

热心网友 时间:30分钟前

首先用AppWizard 建个单文档界面的,在最后一页把View 的基类选成CEditView.(这步你应该会)

然后在资源编辑器中 工具栏中添加 按钮, 用ClassWizard 建出View 对它的响应函数(这步你应该会)

在其中:
TCHAR szCurLine[257];
for(int i =0;i<GetEditCtrl().GetLineCount();i++)
{
szCurLine[ GetEditCtrl().GetLine(i,szCurLine, 256) ] ='\0'; //手动添加 字符串结束标志
//在这里szCurLine 的内容就是第i 行的文本了.
}

热心网友 时间:29分钟前

以下代码加入到:MainFrm.cpp里

void CMainFrame::OnUpdateFormatReturn(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here

}

以下代码加入到starliu.cpp里 starliu是我自己起的名字,你可以自己起一个

BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here

char hostname[_MAX_PATH]; //定义主机名
char username[_MAX_PATH]; //定义用户名
DWORD dwSize=_MAX_PATH;
DWORD dwSize1=_MAX_PATH;
MEMORYSTATUS mem_stat; //定义可用物理内存

GlobalMemoryStatus(&mem_stat);

GetComputerName(hostname,&dwSize); //GET
GetUserName(username,&dwSize1);

GetDlgItem(IDC_HOSTNAME)->SetWindowText(hostname); //WRITE
GetDlgItem(IDC_ORGANIZATION)->SetWindowText(username);

CString str;
str.Format("%d,%3dKB",mem_stat.dwTotalPhys/1024/1000,mem_stat.dwTotalPhys/1024-mem_stat.dwTotalPhys/1024/1000*1000);
GetDlgItem(IDC_MEMPHYS)->SetWindowText(str);

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

void CAboutDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
CStatic *pMailto=(CStatic*)GetDlgItem(IDC_MAILTO);
pMailto->GetWindowRect(&rect);
ScreenToClient(&rect);
if(rect.PtInRect(point))
{
HCURSOR cursor=AfxGetApp()->LoadCursor(IDC_MAIL_CURSOR);
SetCursor(cursor);
}
CDialog::OnMouseMove(nFlags, point);
}

void CAboutDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
CStatic *p=(CStatic*)GetDlgItem(IDC_MAILTO);
p->GetWindowRect(&rect);
ScreenToClient(&rect);
if(rect.PtInRect(point))
{
ShellExecute(NULL, "open", "mailto:leomarswu@163.com?subject=反馈&Body=如果您有什么建议请在此写入!", NULL, NULL, SW_SHOWNORMAL);
}

CDialog::OnLButtonDown(nFlags, point);
}

以下代码加入到starliuView.cpp里

void CNotepadView::OnFormatFont()
{
// TODO: Add your command handler code here
//字体修改实现;
LOGFONT lf;
CFont *font=this->GetEditCtrl().GetFont(); //GET当前字体;
if(font==NULL) //if当前无字体,创建默认的字体;
{
font =new CFont;
font->CreatePointFont(120,"Fixedsys");
font->GetLogFont(&lf);
delete font;
}
else
{
font->GetLogFont(&lf);
}
CFontDialog cf(&lf);
if(cf.DoModal()==IDOK)
{
this->m_Font.DeleteObject();

this->m_Font.CreateFontIndirect(&lf);
this->SetFont(&this->m_Font);
}
}

void CNotepadView::OnFormatReturn()
{
// TODO: Add your command handler code here
//自动换行实现
bChk=!bChk;
if(!bChk)
{
ShowScrollBar(SB_HORZ,true);
}
else
{
ShowScrollBar(SB_HORZ,false);
}
}

void CNotepadView::OnUpdateFormatReturn(CCmdUI* pCmdUI) //update UI handler
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(bChk);
}

热心网友 时间:30分钟前

以下代码加入到:MainFrm.cpp里

void CMainFrame::OnUpdateFormatReturn(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here

}

以下代码加入到starliu.cpp里 starliu是我自己起的名字,你可以自己起一个

BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here

char hostname[_MAX_PATH]; //定义主机名
char username[_MAX_PATH]; //定义用户名
DWORD dwSize=_MAX_PATH;
DWORD dwSize1=_MAX_PATH;
MEMORYSTATUS mem_stat; //定义可用物理内存

GlobalMemoryStatus(&mem_stat);

GetComputerName(hostname,&dwSize); //GET
GetUserName(username,&dwSize1);

GetDlgItem(IDC_HOSTNAME)->SetWindowText(hostname); //WRITE
GetDlgItem(IDC_ORGANIZATION)->SetWindowText(username);

CString str;
str.Format("%d,%3dKB",mem_stat.dwTotalPhys/1024/1000,mem_stat.dwTotalPhys/1024-mem_stat.dwTotalPhys/1024/1000*1000);
GetDlgItem(IDC_MEMPHYS)->SetWindowText(str);

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

void CAboutDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
CStatic *pMailto=(CStatic*)GetDlgItem(IDC_MAILTO);
pMailto->GetWindowRect(&rect);
ScreenToClient(&rect);
if(rect.PtInRect(point))
{
HCURSOR cursor=AfxGetApp()->LoadCursor(IDC_MAIL_CURSOR);
SetCursor(cursor);
}
CDialog::OnMouseMove(nFlags, point);
}

void CAboutDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
CStatic *p=(CStatic*)GetDlgItem(IDC_MAILTO);
p->GetWindowRect(&rect);
ScreenToClient(&rect);
if(rect.PtInRect(point))
{
ShellExecute(NULL, "open", "mailto:leomarswu@163.com?subject=反馈&Body=如果您有什么建议请在此写入!", NULL, NULL, SW_SHOWNORMAL);
}

CDialog::OnLButtonDown(nFlags, point);
}

以下代码加入到starliuView.cpp里

void CNotepadView::OnFormatFont()
{
// TODO: Add your command handler code here
//字体修改实现;
LOGFONT lf;
CFont *font=this->GetEditCtrl().GetFont(); //GET当前字体;
if(font==NULL) //if当前无字体,创建默认的字体;
{
font =new CFont;
font->CreatePointFont(120,"Fixedsys");
font->GetLogFont(&lf);
delete font;
}
else
{
font->GetLogFont(&lf);
}
CFontDialog cf(&lf);
if(cf.DoModal()==IDOK)
{
this->m_Font.DeleteObject();

this->m_Font.CreateFontIndirect(&lf);
this->SetFont(&this->m_Font);
}
}

void CNotepadView::OnFormatReturn()
{
// TODO: Add your command handler code here
//自动换行实现
bChk=!bChk;
if(!bChk)
{
ShowScrollBar(SB_HORZ,true);
}
else
{
ShowScrollBar(SB_HORZ,false);
}
}

void CNotepadView::OnUpdateFormatReturn(CCmdUI* pCmdUI) //update UI handler
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(bChk);
}

热心网友 时间:26分钟前

首先用AppWizard 建个单文档界面的,在最后一页把View 的基类选成CEditView.(这步你应该会)

然后在资源编辑器中 工具栏中添加 按钮, 用ClassWizard 建出View 对它的响应函数(这步你应该会)

在其中:
TCHAR szCurLine[257];
for(int i =0;i<GetEditCtrl().GetLineCount();i++)
{
szCurLine[ GetEditCtrl().GetLine(i,szCurLine, 256) ] ='\0'; //手动添加 字符串结束标志
//在这里szCurLine 的内容就是第i 行的文本了.
}
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com
Top