但愿这两段代码能够帮助你对话框中的工具条:step1: 在资源编辑器中插入工具条资源,并为每个按钮创建ID。将它命名为IDC_TOOLBAR1 step2: 在对话框变量中添加一个工具条变量。 CToolBar m_wndToolBar;step3: 在CDialog::OnInitDialog中添加如下代码: // 创建工具条并调入资源 if(!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1)) { TRACE0("Failed to Create Dialog Toolbar\n"); EndDialog(IDCANCEL); }CRect rcClientOld; // 久客户区RECT CRect rcClientNew; // 加入TOOLBAR后的CLIENT RECT GetClientRect(rcClientOld); // // Called to reposition and resize control bars in the client area of a window // The reposQuery FLAG does not really traw the Toolbar. It only does the calculations. // And puts the new ClientRect values in rcClientNew so we can do the rest of the Math. //重新计算RECT大小 RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0,reposQuery,rcClientNew);// All of the Child Windows (Controls) now need to be moved so the Tollbar does not cover them up. //所有的子窗口将被移动,以免被TOOLBAR覆盖 // Offest to move all child controls after adding Tollbar //计算移动的距离 CPoint ptOffset(rcClientNew.left-rcClientOld.left, rcClientNew.top-rcClientOld.top);CRect rcChild; CWnd* pwndChild = GetWindow(GW_CHILD); //得到子窗口 while(pwndChild) // 处理所有子窗口 {//移动所有子窗口 pwndChild->GetWindowRect(rcChild); ScreenToClient(rcChild); rcChild.OffsetRect(ptOffset); pwndChild->MoveWindow(rcChild,FALSE); pwndChild = pwndChild->GetNextWindow(); }CRect rcWindow; GetWindowRect(rcWindow); // 得到对话框RECT rcWindow.right += rcClientOld.Width() - rcClientNew.Width(); // 修改对话框尺寸 rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height(); MoveWindow(rcWindow,FALSE); // Redraw WindowRepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0); 接下来是ListView中的一些例子(sdk),但愿有参考价值case WM_CREATE: hInstance=((LPCREATESTRUCT)lparam)->hInstance; InitComCtl.dwSize=sizeof(INITCOMMONCONTROLSEX); InitComCtl.dwICC=ICC_LISTVIEW_CLASSES|ICC_TREEVIEW_CLASSES; InitCommonControlsEx(&InitComCtl); hListView=CreateWindowEx(WS_EX_STATICEDGE,WC_LISTVIEW,NULL,WS_VISIBLE|WS_CHILD|LVS_REPORT,0,0,0,0, hwnd,(HMENU)ID_LISTVIEW,hInstance,0); //hTreeView=CreateWindowEx(WS_EX_CLIENTEDGE,WC_TREEVIEW,NULL,WS_CHILD|WS_VISIBLE|WS_BORDER|WS_CLIPSIBLINGS|WS_SIZEBOX ,0,0,0,0, // hwnd,(HMENU)ID_TREEVIEW,hInstance,0);
我给你个网站,你自己去找找吧
www.codeproject.com
这个上面都有
2、Imagelist
第二个问题你可以创建一个imagelist,把它选到listctrl中,在插入item的时候就可以选择image的索引了。
在资源编辑器中插入工具条资源,并为每个按钮创建ID。将它命名为IDC_TOOLBAR1 step2:
在对话框变量中添加一个工具条变量。
CToolBar m_wndToolBar;step3:
在CDialog::OnInitDialog中添加如下代码:
// 创建工具条并调入资源
if(!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
{
TRACE0("Failed to Create Dialog Toolbar\n");
EndDialog(IDCANCEL);
}CRect rcClientOld; // 久客户区RECT
CRect rcClientNew; // 加入TOOLBAR后的CLIENT RECT
GetClientRect(rcClientOld); //
// Called to reposition and resize control bars in the client area of a window
// The reposQuery FLAG does not really traw the Toolbar. It only does the calculations.
// And puts the new ClientRect values in rcClientNew so we can do the rest of the Math.
//重新计算RECT大小
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0,reposQuery,rcClientNew);// All of the Child Windows (Controls) now need to be moved so the Tollbar does not cover them up.
//所有的子窗口将被移动,以免被TOOLBAR覆盖
// Offest to move all child controls after adding Tollbar
//计算移动的距离
CPoint ptOffset(rcClientNew.left-rcClientOld.left,
rcClientNew.top-rcClientOld.top);CRect rcChild;
CWnd* pwndChild = GetWindow(GW_CHILD); //得到子窗口
while(pwndChild) // 处理所有子窗口
{//移动所有子窗口
pwndChild->GetWindowRect(rcChild);
ScreenToClient(rcChild);
rcChild.OffsetRect(ptOffset);
pwndChild->MoveWindow(rcChild,FALSE);
pwndChild = pwndChild->GetNextWindow();
}CRect rcWindow;
GetWindowRect(rcWindow); // 得到对话框RECT
rcWindow.right += rcClientOld.Width() - rcClientNew.Width(); // 修改对话框尺寸
rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height();
MoveWindow(rcWindow,FALSE); // Redraw WindowRepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
接下来是ListView中的一些例子(sdk),但愿有参考价值case WM_CREATE:
hInstance=((LPCREATESTRUCT)lparam)->hInstance;
InitComCtl.dwSize=sizeof(INITCOMMONCONTROLSEX);
InitComCtl.dwICC=ICC_LISTVIEW_CLASSES|ICC_TREEVIEW_CLASSES;
InitCommonControlsEx(&InitComCtl); hListView=CreateWindowEx(WS_EX_STATICEDGE,WC_LISTVIEW,NULL,WS_VISIBLE|WS_CHILD|LVS_REPORT,0,0,0,0,
hwnd,(HMENU)ID_LISTVIEW,hInstance,0); //hTreeView=CreateWindowEx(WS_EX_CLIENTEDGE,WC_TREEVIEW,NULL,WS_CHILD|WS_VISIBLE|WS_BORDER|WS_CLIPSIBLINGS|WS_SIZEBOX ,0,0,0,0,
// hwnd,(HMENU)ID_TREEVIEW,hInstance,0);
himl=ImageList_Create(16,16,ILC_COLOR24,6,7);
ImageList_AddIcon(himl,LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1)));
ImageList_Add(himl,LoadBitmap(NULL,MAKEINTRESOURCE(OBM_RESTORED)),0);
ImageList_Add(himl,LoadBitmap(NULL,MAKEINTRESOURCE(OBM_SIZE)),0);
ImageList_Add(himl,LoadBitmap(NULL,MAKEINTRESOURCE(OBM_RGARROWD)),0); SendMessage(hListView,LVM_SETIMAGELIST,(WPARAM)LVSIL_SMALL ,(LPARAM)himl);
SendMessage(hListView,LVM_SETEXTENDEDLISTVIEWSTYLE,(WPARAM)0,
(LPARAM)(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_CHECKBOXES)); for(i=0;i<4;i++)
{
Column.mask=LVCF_FMT|LVCF_IMAGE|LVCF_TEXT|LVCF_WIDTH;
Column.fmt=LVCFMT_COL_HAS_IMAGES;
Column.iImage=i;
Column.pszText=ColumnText[i];
Column.cx=100;
SendMessage(hListView,LVM_INSERTCOLUMN,(WPARAM)0,(LPARAM)&Column);
} i=0; for(i=0;i<4;i++)
{
Item.mask=LVIF_IMAGE|LVIF_TEXT;
Item.iItem=i;
Item.iSubItem=0;
Item.iImage=i;
Item.pszText=ColumnText[i]; SendMessage(hListView,LVM_INSERTITEM,(WPARAM)0,(LPARAM)&Item);
} for(i=0;i<4;i++)
{
Item.mask=LVIF_TEXT;
Item.iItem=i;
Item.iSubItem=1;
Item.pszText=SubText[i]; SendMessage(hListView,LVM_SETITEM,(WPARAM)0,(LPARAM)&Item);
} return 0;
break;
虽然不是ClistCtrl,应该还是有点参考意义的。