📄 telbookdlg.cpp
字号:
m_pSet.GetFieldValue("电话号码",str);
m_RecordList.SetItemText(nIndex,1,str);
m_pSet.GetFieldValue("手机号",str);
m_RecordList.SetItemText(nIndex,2,str);
m_pSet.GetFieldValue("QQ",str);
m_RecordList.SetItemText(nIndex,3,str);
m_pSet.GetFieldValue("E-mail",str);
m_RecordList.SetItemText(nIndex,4,str);
m_pSet.GetFieldValue("小灵通",str);
m_RecordList.SetItemText(nIndex,5,str);
m_pSet.GetFieldValue("网页",str);
m_RecordList.SetItemText(nIndex,6,str);
m_pSet.GetFieldValue("邮编",str);
m_RecordList.SetItemText(nIndex,7,str);
m_pSet.GetFieldValue("地址",str);
m_RecordList.SetItemText(nIndex,8,str);
m_RecordList.SetItemData(nIndex,nIndex);
}
void CTelBookDlg::OnExit()
{
// TODO: Add your control notification handler code here
CDialog::OnOK();
}
void CTelBookDlg::OnAbout()
{
// TODO: Add your control notification handler code here
CAboutDlg AbDlg;
AbDlg.DoModal();
}
void CTelBookDlg::OnButtonHelp()
{
// TODO: Add your control notification handler code here
ShellExecute(NULL,"open","ReadMe.txt",NULL,NULL,SW_SHOW);
}
void CTelBookDlg::OnDelete()
{
// TODO: Add your control notification handler code here
POSITION pos = m_RecordList.GetFirstSelectedItemPosition();
if(pos==NULL){
MessageBox("请选中你要删除的记录","提示",MB_ICONWARNING);
return;
}
int index = m_RecordList.GetNextSelectedItem(pos); // 得到项目索引
CString del_name=m_RecordList.GetItemText(index,0);
m_RecordList.DeleteItem(index);
m_pSet.m_strFilter="姓名=";
m_pSet.m_strFilter+="'"+del_name+"'";//设置数据库查找的条件 姓名='NAME'
if( m_pSet.Requery()){
m_pSet.Delete();//在数据库中删除记录
m_pSet.MoveNext();
/*
if( m_pSet.IsEOF() )
m_pSet.MoveLast();
if( m_pSet.IsBOF() )
m_pSet.SetFieldNull(NULL);*/
m_pSet.Requery();
UpdateItemData();
}
}
void CTelBookDlg::OnFind()
{
// TODO: Add your control notification handler code here
CFindDlg FinDlg;
if( FinDlg.DoModal()==IDOK ){
int index=m_RecordList.findItem(FinDlg.ColIndex,FinDlg.m_find);
POINT point;
if( index<0 ){
MessageBox("没有找到"+FinDlg.m_find,"提示", MB_ICONSTOP);
return;
}
m_RecordList.GetItemPosition(index-1,&point);//获得的位置是第index条记录的下边位置,所以要减2
m_RecordList.Scroll(CSize(0,point.y));//滚动到指定位置
m_RecordList.SetFocus();
m_RecordList.SetItemState(index, LVNI_SELECTED,LVNI_SELECTED);//设置index项被选中
}
}
void CTelBookDlg::OnModify()
{
// TODO: Add your control notification handler code here
CMyDlg ModifyDlg(NULL,"修改");
POSITION pos = m_RecordList.GetFirstSelectedItemPosition();
if(pos==NULL){
MessageBox("请选中你要修改的记录","提示",MB_ICONWARNING);
return;
}
int index = m_RecordList.GetNextSelectedItem(pos); // 得到项目索引
CString del_name=m_RecordList.GetItemText(index,0);
m_pSet.m_strFilter="姓名=";
m_pSet.m_strFilter+="'"+del_name+"'";
if( m_pSet.Requery()){//在数据库中找到要修改的记录
ModifyDlg.m_name=m_pSet.m_Name;
ModifyDlg.m_pho=m_pSet.m_PhoNo;
ModifyDlg.m_mobi=m_pSet.m_MobNo;
ModifyDlg.m_QQ=m_pSet.m_QQ;
ModifyDlg.m_email=m_pSet.m_E_mail;
ModifyDlg.m_callNo=m_pSet.m_Call_No;
ModifyDlg.m_call=m_pSet.m_Call;
ModifyDlg.m_post=m_pSet.m_Post;
ModifyDlg.m_address=m_pSet.m_Address;
UpdateData(false);//显示出要修改的全部内容
if( ModifyDlg.DoModal()==IDOK){
m_pSet.Edit();
m_pSet.m_Name=ModifyDlg.m_name;
m_pSet.m_PhoNo=ModifyDlg.m_pho;
m_pSet.m_MobNo=ModifyDlg.m_mobi;
m_pSet.m_QQ=ModifyDlg.m_QQ;
m_pSet.m_E_mail=ModifyDlg.m_email;
m_pSet.m_Call_No=ModifyDlg.m_callNo;
m_pSet.m_Call=ModifyDlg.m_call;
m_pSet.m_Post=ModifyDlg.m_post;
m_pSet.m_Address=ModifyDlg.m_address;
m_pSet.Update();/*向数据库写入数据*/
CString str;
/*在ContolList中显示修改后的内容*/
m_pSet.GetFieldValue("姓名",str);
m_RecordList.SetItemText(index,0,str);
m_pSet.GetFieldValue("电话号码",str);
m_RecordList.SetItemText(index,1,str);
m_pSet.GetFieldValue("手机号",str);
m_RecordList.SetItemText(index,2,str);
m_pSet.GetFieldValue("QQ",str);
m_RecordList.SetItemText(index,3,str);
m_pSet.GetFieldValue("E-mail",str);
m_RecordList.SetItemText(index,4,str);
m_pSet.GetFieldValue("小灵通",str);
m_RecordList.SetItemText(index,5,str);
m_pSet.GetFieldValue("网页",str);
m_RecordList.SetItemText(index,6,str);
m_pSet.GetFieldValue("邮编",str);
m_RecordList.SetItemText(index,7,str);
m_pSet.GetFieldValue("地址",str);
m_RecordList.SetItemText(index,8,str);
m_RecordList.SetFocus();
m_RecordList.SetItemState(index, LVNI_SELECTED,LVNI_SELECTED);//设置index项被选中
m_pSet.Requery();
}
}
else
MessageBox("在数据库中没有找到你要修改的记录","提示", MB_ICONERROR);
}
void CTelBookDlg::OnDestroy()
{
m_pSet.Close();
db.Close();
CDialog::OnDestroy();
//UnregisterHotKey(this->m_hWnd,ID_COPY);
// TODO: Add your message handler code here
}
void CTelBookDlg::OnDblclkListCorde(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
POSITION pos = m_RecordList.GetFirstSelectedItemPosition();
if(pos!=NULL)
OnModify();
*pResult = 0;
}
HBRUSH CTelBookDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CreateSolidBrush( RGB(180,210,245) );//CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// bkColor = ;
// TODO: Change any attributes of the DC here
switch( pWnd->GetDlgCtrlID() )
case IDC_STATIC_TITLE:
case IDC_STATIC:
pDC->SetBkColor( RGB(255,255,255) );
// TODO: Return a different brush if the default is not desired
return hbr;
}
int CALLBACK ListCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
CMyListCtrl *pListCtrl = (CMyListCtrl*)lParamSort;
CString temp1;
CString temp2;
temp1 = pListCtrl->GetItemText(lParam1,pListCtrl->SortCol);
temp2 = pListCtrl->GetItemText(lParam2,pListCtrl->SortCol);
int CmpResult = temp1.Compare(temp2);
if( pListCtrl->sequence )
return CmpResult;
else
return (-1)*CmpResult;
}
void CTelBookDlg::OnColumnclickListCorde(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if(pNMListView->iSubItem==8)
return;
// TODO: Add your control notification handler code here
if ( m_RecordList.SortCol==pNMListView->iSubItem ){
m_RecordList.sequence = !m_RecordList.sequence;
}
else{
m_RecordList.SortCol= pNMListView->iSubItem;
m_RecordList.sequence = true;
}
m_RecordList.SortItems(ListCompareFunc,(DWORD)&m_RecordList);
UpdateItemData();
*pResult = 0;
}
void CTelBookDlg::UpdateItemData()
{
int N = m_RecordList.GetItemCount();
for(int i=0;i<N;i++)
m_RecordList.SetItemData(i,i);
}
void CTelBookDlg::OnRclickListCorde(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
POSITION pos = m_RecordList.GetFirstSelectedItemPosition();
if(pos==NULL)
return;
CPoint pt;
CMenu RBMenu;
RBMenu.LoadMenu( IDR_RBD_MENU );
GetCursorPos(&pt);
RBMenu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,pt.x,pt.y,this);/*显示右键菜单*/
*pResult = 0;
}
void CTelBookDlg::OnCopy()
{
POSITION pos = m_RecordList.GetFirstSelectedItemPosition();
if(pos==NULL)
return;
int index = m_RecordList.GetNextSelectedItem(pos); // 得到项目索引
CString source = m_RecordList.GetItemText(index,0);
source += " "+m_RecordList.GetItemText(index,1);
source += " "+m_RecordList.GetItemText(index,2);
source += " "+m_RecordList.GetItemText(index,3);
source += " "+m_RecordList.GetItemText(index,4);
source += " "+m_RecordList.GetItemText(index,5);
source += " "+m_RecordList.GetItemText(index,6);
source += " "+m_RecordList.GetItemText(index,7);
source += " "+m_RecordList.GetItemText(index,8);
if(OpenClipboard())/*打开系统剪切板*/
{
HGLOBAL clipbuffer;
char * buffer;
EmptyClipboard();/*清空系统剪切板*/
clipbuffer = GlobalAlloc(GMEM_DDESHARE, source.GetLength()+1);
buffer = (char*)GlobalLock(clipbuffer);
strcpy(buffer, LPCSTR(source));
GlobalUnlock(clipbuffer);
SetClipboardData(CF_TEXT,clipbuffer);
CloseClipboard();/*关闭系统剪切板*/
}
}
BOOL CTelBookDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message==WM_KEYDOWN ){/*响应注删的热键*/
if( ( GetKeyState(VK_CONTROL)&0x80 )==0x80 )
switch(pMsg->wParam){
case 'C':
if( GetForegroundWindow() == this )/*判断是否为当前活动窗口*/
OnCopy();
default:break;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -