救救我!

tbq 2002-10-13 12:36:11
就是先建一个数据库,里面就有两项,一个是单词,你可以先写两个,另一个就是解释,然后就建一个工程,有一个form1就够了。上面有一个command1按钮,一个list1,一个text1,运行。在text1里打一个单词,点command1,然后在list1里显示解释就行了。
13号5:00前
我的联系方式是:tbq_tbq@sina.com
谢谢!谢谢!谢谢!谢谢!谢谢!谢谢!谢谢!谢谢!谢谢!谢谢!谢谢!谢谢!
...全文
27 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
GoogleGeek 2002-10-13
  • 打赏
  • 举报
回复
too easy
练一练手!
arcnode 2002-10-13
  • 打赏
  • 举报
回复
来了,蹭分
GoogleGeek 2002-10-13
  • 打赏
  • 举报
回复
程序已经发过去
GoogleGeek 2002-10-13
  • 打赏
  • 举报
回复
说明:我的测试例子使用的是sqlserver 2000
1、先运行脚本word_script.sql进行数据库及表的创建
2、接着运行编译create_dsn.cpp 进行odbc数据源的创建,记住用你的sa用户登陆数据库
3、编译工程Word_db
--------------------
run and enjoy it!
关键代码:
void CWordEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default

CString strWord;
this->GetWindowText(strWord);
CEdit::OnChar(nChar, nRepCnt, nFlags);

if(VK_RETURN==nChar&&strWord!="")
{
CWord_dbSet *pWordSet;
CWord_dbDoc *pDoc;
CWord_dbView *pView;
CMainFrame *pMainFrame;
CSplitterWnd *pSplitter;

pMainFrame=(CMainFrame*)AfxGetMainWnd();
pDoc=(CWord_dbDoc*)pMainFrame->GetActiveDocument();
pWordSet=&pDoc->m_word_dbSet;
pSplitter=&pMainFrame->m_wndSplitter;

pView=(CWord_dbView*)pSplitter->GetPane(0,0);//find the pirst pane!
CListBox *pListBox=(CListBox*)
pView->GetDlgItem(IDC_WORD_DESC_LIST);//find the listbox control!

if(pWordSet->IsOpen())
{
//shift the pointer to the beinning of the result set!
if(!pWordSet->IsBOF())
pWordSet->MoveFirst();

while(!pWordSet->IsEOF())//search all the word in the table:word_db of the database:csdn_db
{
if(!strWord.CompareNoCase(pWordSet->m_word_name))//match ! so jump out the loop!
break;
else//continue to search the word!
pWordSet->MoveNext();
}

if(!pWordSet->IsEOF())//have found the word! display it!
{
pListBox->AddString(pWordSet->m_word_desc);
}
else
MessageBox("Cannot find the word you gived! \nyou should update your database","很抱歉!");
}
else
MessageBox("Cannot search this word,because failed to connect the database!");

CSize sz;
CString str;
int dx=0;
CDC* pDC = pListBox->GetDC();
for (int i=0;i < pListBox->GetCount();i++)
{
pListBox->GetText( i, str );
sz = pDC->GetTextExtent(str);
if (sz.cx > dx)
dx = sz.cx;
}
pListBox->ReleaseDC(pDC);

// Set the horizontal extent so every character of all strings
// can be scrolled to.
pListBox->SetHorizontalExtent(dx);
SetWindowText("");//set the caption to NULL
}
-------------------------------
void CWordListView::OnInitialUpdate()
{
// TODO: Add your specialized code here and/or call the base class
CListView::OnInitialUpdate();

CWord_dbDoc * pDoc =(CWord_dbDoc*) GetDocument();
CWord_dbSet *pWordSet=&pDoc->m_word_dbSet;


CListCtrl& theCtrl = GetListCtrl();
long style=theCtrl.GetStyle();
style|=LVS_REPORT;
::SetWindowLong(theCtrl.m_hWnd,GWL_STYLE,style);
theCtrl.SetBkColor(RGB(207,226,248));
theCtrl.SetTextBkColor(RGB(207,226,248));
theCtrl.SetTextColor(RGB(0,0,255));
theCtrl.InsertColumn(0,"当前数据库中的英语单词",LVCFMT_CENTER,200,0);
if(pWordSet->IsOpen())
{
pWordSet->MoveFirst();
while(!pWordSet->IsEOF())
{
theCtrl.InsertItem(0,pWordSet->m_word_name);
pWordSet->MoveNext();
}

pWordSet->MoveFirst();
}

}
---------------------------------
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class

if(!this->m_wndSplitter.CreateStatic(this,1,2))
return false;
if(!this->m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CWord_dbView),CSize(700,0),pContext))
return false;
if(!this->m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CWordListView),CSize(0,0),pContext))
return false;
this->m_wndSplitter.SetActivePane(0,0);
return true;
}
---------------------------
itanynj@msn.com

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧