博文

Custom Draw ListView Controls(1)(2009-01-20 11:35:00)

摘要: Custom Draw ListView Controls
The first is the most extreme. You handle the WM_PAINT messages and do all the painting yourself. You get no help at all from Windows with this method. You have to create a device context, determine where and how big your control is, what state it is in, and then draw it all yourself. Most programmers tend to shy away from this. Owner-draw (or self-draw) controls are a little easier. Here, Windows sets up the device context for you. It also fills in a structure that gives you the rectangle that the control occupies, the state the control is in, and flags to say how much drawing you need to do. You still need to do all the drawing yourself, but with all this information handed to you, it is not such a chore. In particular, for controls like list boxes and ListView controls, Windows will go line by line through the control and ask you to draw each individual item; you don't need to know how to draw the entire control. To make things easy for owner-dra......

阅读全文(4016) | 评论:2

如何重载CListview中的CListctrl 讨论(2009-01-20 11:27:00)

摘要:经常有一个已经重载的CListCtrl,然后想把它用到CListView中,但是问题多多。 首先,利用Subclasswindow是绝对不行的,原因不详。 其次,这种方法非常复杂, 在listview中定义一个listctrl成员变量,然后在listview中响应wm_create消息,在oncreate中把listctrl创建出来,再响应wm_size消息,在onsize中将listctrl   movewindow填充listview就可以了,一点都不方便。 再次,不用CListView,而是用CFormView。这时可以用Subclasswindow子类化 最后,如果CListCtrl使用了DrawItem的自绘方法,那么只能使用CListView的CustomDraw,把CListCtrl的绘制代码copy过来。   如果有更好的方法,请联系我: qq: 281417474  ......

阅读全文(3003) | 评论:1

工具栏上快速添加文字(2007-07-17 18:31:00)

摘要:    m_wndToolBar.SetButtonText(0," 控制 ");
 m_wndToolBar.SetButtonText(1," 编辑 ");
 /////////////调整工具条/////////////////
 CRect rc(0, 0, 0, 0);
 CSize sizeMax(0, 0);
 CToolBarCtrl& bar = m_wndToolBar.GetToolBarCtrl();
 //可能由于字数的不同,所以要找到一个图形最大的工具栏项
 for (int nIndex = bar.GetButtonCount() - 1; nIndex >= 0; nIndex--)
 {
  bar.GetItemRect(nIndex, rc);
  rc.NormalizeRect();
  sizeMax.cx = __max(rc.Size().cx, sizeMax.cx);
  sizeMax.cy = __max(rc.Size().cy, sizeMax.cy);
 }
 m_wndToolBar.SetSizes(sizeMax, CSize(16,15));......

阅读全文(2819) | 评论:0

推荐一个皮肤软件(2007-05-20 19:39:00)

摘要:转 http://www.gissky.net/blog/user2/yuqiexing/archives/2007/13853.html......

阅读全文(2262) | 评论:0

CTreeCtrl学习笔记3--专题篇(2007-01-25 14:26:00)

摘要: 如何给树控件加入工具提示  
l 首先给树控件加入TVS_INFOTIP属性风格,如下所示:
if (!m_ctrlTree.Create(WS_CHILD|WS_VISIBLE|
TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT|TVS_SHOWSELALWAYS|TVS_INFOTIP, //加入提示TVS_INFOTIP,jingzhou xu(树控件ID:100)
  CRect(0, 0, 0, 0), &m_wndTreeBar, 100))
  {
    TRACE0("Failed to create instant bar child\n");
     return -1;
  }

2 其次加入映射消息声明,如下所示:
afx_msg void OnGetInfoTip(NMHDR* pNMHDR,LRESULT* pResult);       //树控件上加入提示消息
ON_NOTIFY(TVN_GETINFOTIP, 100, OnGetInfoTip)                     //树控件条目上加入提示
3最后加入呼应涵数处理:
void CCreateTreeDlg::OnGetInfoTip(NMHDR* pNMHDR, LRESULT* pResult) 
......

阅读全文(3715) | 评论:0

CTreeCtrl学习笔记2-专题篇(2007-01-25 14:25:00)

摘要:           如何对CTreeCtrl的项进行拖曳   (1) 取消TVS_DISABLEDRAGDROP 样式,该样式会禁止发送TVN_BEGINDRAG消息     (2) 派生一个类于CTreeCtrl,定义几个成员变量:     CImageList *m_pDragImage;//拖曳图像列表指针     BOOL m_bLDragging;//是否拖曳     HTREEITEM m_hitemDrag,m_hitemDrop;//拖曳项和目标项     (3)响应拖曳消息TVN_BEGINDRAG void CTreeCtrlEx::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult) {     NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;     // TODO: Add your control notification handler code here     m_hitemDrag=pNMTreeView->itemNew.hItem;//获得拖曳项     m_hitemDrop=NULL;     m_pDragImage=CreateDragImage(m_hitemDrag);//创建拖曳图像     if(!m_pDragImage)            return;     this->m_bLDragging=TRUE;     m_pDragImage->BeginDrag(0,CPo......

阅读全文(5623) | 评论:0

CTreeCtrl学习笔记1--基础篇(2007-01-25 14:21:00)

摘要:以下的说明中,注意以下变量的定义:  CTreeCtrl  m_treectrl;//是关联变量       1. 如何获得选中项句柄? HTREEITEM h=m_treectrl.GetSelectedItem();   2.如何获得右击项句柄?   void CLayerDialog::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) {        // TODO: Add your control notification handler code here        NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;        //右击获取所选项        CPoint   point,p;          TVHITTESTINFO   HitTestInfo;          GetCursorPos(&point);        m_treectrl.ScreenToClient(&point);          HitTestInfo.pt   =   point;          HTREEITEM h   =   m_treectrl.HitTest(&HitTestInf......

阅读全文(5385) | 评论:1

CListCtrl学习笔记(4)---中级篇(3)(2007-01-03 17:56:00)

摘要: 专题3:如何使列头响应右击消息? 我们知道在ClistCtrl中是可以响应列头单击的,如响应消息LVN_COLUMNCLICK,但是不能响应右击.怎么办呢? (1) 实际上我们可以把CListCtrl(Report风格)看成由子窗口CHeaderCtrl和下面的视图组成,所以我们决定重写CHeaderCtrl. 派生一个类于CHeaderCtrl,响应右击: void CMyHeadCtrl::OnRButtonDown(UINT nFlags, CPoint point)
{
 // TODO: Add your message handler code here and/or call default
 CHeaderCtrl::OnRButtonDown(nFlags, point);
 
} 在其中编写你想要的代码.这里完成了第一步.   (2) 此时还没有安装到ClistCtrl 上呢?想什么办法安装呢?以前在重写控件的时候,是通过在ClassWizard中定义变量来实现的,现在显然不行.因为ClistCtrl自己就是一个控件了.难道就没有办法了吗? 有.在CListCtrl中不是有个函数是GetHeaderCtrl吗?它不就是获得列头的指针吗?我们应该怎样利用它呢? 在想想子类化的方法: 如果我们重写了一个控件,如CMyEdit(派生于CEdit),现在要安装,除了在classwizard中安装以外,还可以在OnInitDialog中进行子类化: .h: CMyEdit m_edit; .cpp: m_edit.SubClassDlgItem(IDC_EDIT1,this);   (3) 回到我们这里的话题.显然不能用subclassDlgItem了,因为列头没有什么标识号,不过还可以用SubClassWindow,参数正好是一个句柄. 实现如下: 重写Cmylist(CListCtrl的派生类)虚函数: void Cmylist::PreSubclassWindow()
{
 // TODO: Add your specialized code here and/or call the base cla......

阅读全文(3826) | 评论:0

CListCtrl学习笔记(3)---中级篇(2)(2007-01-03 17:44:00)

摘要: 专题2:CListCtrl中如何实现排序功能? 1.排序功能的实现需要用到下面这个函数: BOOL SortItems( PFNLVCOMPARE pfnCompare, DWORD dwData ); 其中 第一个参数是回调函数的指针,后面是所要传递的参数 而回调函数一般定义如下: int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2,
   LPARAM lParamSort); 其中lParam1是其中list的一项数据,而lparam2是另外一项,第三个参数是刚才传递过来的参数. 2.举例如下: (1)回调函数的编写 注意回调函数必须是全局或者静态的,并且不能调用成员变量,所以要凭借最后一个参数传递某些数据. int CALLBACK CompareFunc(LPARAM lParam1,LPARAM lParam2,LPARAM lParamSort)
{ //传递list指针
 Cmylist *list=(Cmylist*)lParamSort; //获得指定行的索引号
 LVFINDINFO findInfo;
 findInfo.flags = LVFI_PARAM;
 findInfo.lParam = lParam1;
 int iItem1 = list->FindItem(&findInfo, -1);
 findInfo.lParam = lParam2;
 int iItem2 = list->FindItem(&findInfo, -1); //根据指定列的索引号,得到所在项的数据
 CString strItem1 =list->GetItemText(iItem1,list->selectedField);
 CString strItem2 =list->GetItemText(iItem2,list->selectedField); //判断是升序还是降序
  if(!li......

阅读全文(3404) | 评论:0

对话框条的制作CDialogBar(2007-01-03 16:58:00)

摘要:简单来说,就是对话框条的制作 1.创建对话框资源:在对话框资源编辑器内生成一个Dialog资源,并将其风格(Style)属性必须设置为Child,不能设置为Overlapped或Popup,否则运行肯定出错;至于边界属性则随用户自己喜欢,一般都是选择None。其余属性也随用户选择,一般没有特殊要求还是选择默认的好。 2.自己派生一个继承于CDialogBar的类,注意此时由于ClassWizard没有把CDialogBar列出来,所以只好自己手动编写.h和.cpp,然后加上必要的处理函数,如: class CmyDlgWnd : public CDialogBar 
{
public:
 CmyDlgWnd(CWnd *pParent=NULL);
 
 virtual ~CmyDlgWnd();
  //{{AFX_VIRTUAL(CmyDlgWnd)
 protected:
 virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
 //}}AFX_VIRTUAL
// Implementation
protected:
 
 // Generated message map functions
 //{{AFX_MSG(myDlgWnd)
  // NOTE: the ClassWizard will add member functions here
 //}}AFX_MSG

 DECLARE_MESSAGE_MAP() }; 3.假设在对话框添加了一个按钮,现在要响应,可以手动编写处理函数: .h: afx_msg void OnClose(); .cpp: BEGIN_MESSAGE_MAP(CmyDlgWnd, CDialogBar)
 //{{AFX_MSG_MAP(CmyDlgWnd)
  // NOTE: ......

阅读全文(9860) | 评论:3