(, 下载次数: 1)
•弹出式菜单功能的实现还是比较简单的,我们只要处理WM_CONTEXTMENU消息就可以了,在其消息处理函数中,调用菜单的TRACKPOPUP(),便可在指定的位置弹出菜单;
•WM_CONTEXTMENU消息由用户鼠标右键放开后触发;
•TRACKPOPUP()是菜单类Cmenu处理弹出菜单的函数,这两函数是我们实现右键弹出菜单功能的关键;
实现功能•1.新建一个对话框程序
•2.添加List控件及对应成员变量;
•3.在对话框类的添加WM_CONTEXTMENU消息处理函数,实现弹出菜单的功能 •voidCGkbc8Dlg::OnContextMenu(CWnd* pWnd, CPoint point)
•{
• // TODO: Add your message handler code here
• CMenu m_popmenu;
• m_popmenu.LoadMenu(IDR_POPMENU);
• CMenu* m_submenu = m_popmenu.GetSubMenu(0);
•
• m_submenu->TrackPopupMenu(TPM_LEFTBUTTON|TPM_LEFTALIGN ,point.x,point.y,this);
•
• m_popmenu.DestroyMenu();
•4.另外列表控件内的内容从数据库中读取由函数LoadBookInfo实现
•5.我们结合VC6.0来进行具体的操作,实现当前的功能
void CGkbc8Dlg:oadBookInfo(BOOL IsDesc) sql ="Select * from tb_bookinfo ORDER BY PRICE ASC";
sql ="Select * from tb_bookinfo ORDER BY PRICE desc";
m_pRecord =m_pCon->Execute((_bstr_t)sql,NULL,adCmdText);
while (!m_pRecord->ADOEOF && !m_pRecord->BOF)
m_list.InsertItem(100,"");
fieldvalue =(TCHAR*)(_bstr_t)m_pRecord->GetFields()->GetItem("bookname")->Value;
m_list.SetItemText(i,0,fieldvalue);
fieldvalue =(TCHAR*)(_bstr_t)m_pRecord->GetFields()->GetItem("barcode")->Value;
m_list.SetItemText(i,1,fieldvalue);
fieldvalue=(TCHAR*)(_bstr_t)m_pRecord->GetFields()->GetItem("author")->Value;
m_list.SetItemText(i,2,fieldvalue);
fieldvalue =(TCHAR*)(_bstr_t)m_pRecord->GetFields()->GetItem("bookconcern")->Value;
m_list.SetItemText(i,3,fieldvalue);
fieldvalue=(TCHAR*)(_bstr_t)m_pRecord->GetFields()->GetItem("price")->Value;
m_list.SetItemText(i,4,fieldvalue);
(, 下载次数: 0)
欢迎光临 工控编程吧 (https://www.gkbc8.com/) |
Powered by Discuz! X3.4 |