EVC 下控件

来源:互联网 发布:每天工作记录软件 编辑:程序博客网 时间:2024/06/06 16:58

http://www.cppblog.com/hkingSP/archive/2007/04/04/21212.html

 

ClistCtrl(MFC)

创建虚拟列表ClistCtrl(MFC)&&ListView(API)

BOOL CTest::OnInitDialog() 
{
 CDialog::OnInitDialog();
 
 
// TODO: Add extra initialization here

 
//SP-A1.用工具栏画一个CListCtrl控件
 
//SP-A2.插入栏(列)到控件
 ((CListCtrl *)GetDlgItem(IDC_LIST1))->InsertColumn(0, _T("Name"), LVCFMT_LEFT);
 ((CListCtrl 
*)GetDlgItem(IDC_LIST1))->InsertColumn(1, _T("Scores"), LVCFMT_LEFT);
 

 
//SP-A3.设置各个栏的宽度
 ((CListCtrl *)GetDlgItem(IDC_LIST1))->SetColumnWidth(0,50);
 ((CListCtrl 
*)GetDlgItem(IDC_LIST1))->SetColumnWidth(1,50);

 
//SP-23插入栏,并制定高度
 
//或((CListCtrl *)GetDlgItem(IDC_LIST1))->InsertColumn(1, _T("Scores"), LVCFMT_LEFT,50);

// int nColumnCount = ((CListCtrl *)GetDlgItem(IDC_LIST1))->GetHeaderCtrl()->GetItemCount();

 
//SP-A4.1.插入行1
 LV_ITEM lvitem;   //LVITEM结构体

 lvitem.mask
=LVIF_TEXT; //指出对成员中的哪些数据进行设置
 lvitem.pszText=L"vv"//将文本设为vv
 lvitem.iItem=0;   //索引值为0
 lvitem.iSubItem=0;  //没有子项
 
 ((CListCtrl 
*)GetDlgItem(IDC_LIST1))->InsertItem(&lvitem);
 
//SP-A4.2.插入行2
 
//((CListCtrl *)GetDlgItem(IDC_LIST1))->SetItemText(0,0,L"aa");
 
//((CListCtrl *)GetDlgItem(IDC_LIST1))->SetItemText(0,1,L"bb");



 
return TRUE;  // return TRUE unless you set the focus to a control
               
// EXCEPTION: OCX Property Pages should return FALSE
}



ListView(API)   这是工程文件 下载
//----------------------------------------------------------------------
// DoCreateMain - Process WM_CREATE message for window.
//
LRESULT DoCreateMain (HWND hWnd, UINT wMsg, WPARAM wParam, 
                      LPARAM lParam) 
{
    HWND hwndCB;

    
int nHeight;
    HWND hwndLV;
    LPCREATESTRUCT lpcs;

    
// Create a command bar.
    hwndCB = CommandBar_Create (hInst, hWnd, IDC_CMDBAR);

    
// Add exit button to command bar.
    CommandBar_AddAdornments (hwndCB, 00);

    
//SP-A1转换LPARAM
    
// Convert lParam into pointer to create structure.
    lpcs = (LPCREATESTRUCT) lParam;

    
//SP-A2创建列表查看控件
    
//
    
// Create the list view control.
    
//
    hwndLV = CreateWindowEx (0, WC_LISTVIEW, TEXT (""),
                             LVS_REPORT 
| LVS_SINGLESEL |
                             LVS_OWNERDATA 
| WS_VISIBLE | WS_CHILD |
                             WS_VSCROLL, 
0, nHeight, lpcs->cx,
                             lpcs
->cy - nHeight, hWnd,
                             (HMENU)IDC_LISTVIEW,
                             lpcs
->hInstance, NULL);
    
//SP-A3增加列
    
// Add columns.
    {
        LVCOLUMN lvc;

        lvc.mask 
= LVCF_TEXT | LVCF_WIDTH | LVCF_FMT | LVCF_SUBITEM;
        lvc.fmt 
= LVCFMT_LEFT;
        lvc.cx 
= 150;
        lvc.pszText 
= TEXT ("Name");
        lvc.iSubItem 
= 0;
        SendMessage (hwndLV, LVM_INSERTCOLUMN, 
0, (LPARAM)&lvc);

        lvc.mask 
|= LVCF_SUBITEM;
        lvc.pszText 
= TEXT ("Type");
        lvc.cx 
= 100;
        lvc.iSubItem 
= 1;
        SendMessage (hwndLV, LVM_INSERTCOLUMN, 
1, (LPARAM)&lvc);

        lvc.mask 
|= LVCF_SUBITEM;
        lvc.pszText 
= TEXT ("Size");
        lvc.cx 
= 100;
        lvc.iSubItem 
= 2;
        SendMessage (hwndLV, LVM_INSERTCOLUMN, 
2, (LPARAM)&lvc);
    }


    
return 0;
}


//SP-A4改变窗口大小,显示列表查看控件
//----------------------------------------------------------------------
// DoSizeMain - Process WM_SIZE message for window.
//
LRESULT DoSizeMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam){
    HWND hwndLV;
    RECT rect;

    hwndLV 
= GetDlgItem (hWnd, IDC_LISTVIEW);

    
// Adjust the size of the client rect to take into account
    
// the command bar height.
    GetClientRect (hWnd, &rect);
    rect.top 
+= CommandBar_Height (GetDlgItem (hWnd, IDC_CMDBAR));

    SetWindowPos (hwndLV, NULL, rect.left, rect.top,
                  rect.right 
- rect.left, rect.bottom - rect.top,
                  SWP_NOZORDER);
    
return 0;
}


(EVC)静态CListCtrl

BOOL CTest::OnInitDialog()
{
 CDialog::OnInitDialog();
 
 // TODO: Add extra initialization here

 //SP-A1.用工具栏画一个CListCtrl控件
 //SP-A2.插入栏(列)到控件
 ((CListCtrl *)GetDlgItem(IDC_LIST1))->InsertColumn(0, _T("Name"), LVCFMT_LEFT);
 ((CListCtrl *)GetDlgItem(IDC_LIST1))->InsertColumn(1, _T("Scores"), LVCFMT_LEFT);

 //SP-A3.设置各个栏的宽度
 ((CListCtrl *)GetDlgItem(IDC_LIST1))->SetColumnWidth(0,50);
 ((CListCtrl *)GetDlgItem(IDC_LIST1))->SetColumnWidth(1,50);

 //SP-23插入栏,并制定高度
 //或((CListCtrl *)GetDlgItem(IDC_LIST1))->InsertColumn(1, _T("Scores"), LVCFMT_LEFT,50);

// int nColumnCount = ((CListCtrl *)GetDlgItem(IDC_LIST1))->GetHeaderCtrl()->GetItemCount();

 //SP-A4.1.插入行1
 LV_ITEM lvitem;   //LVITEM结构体

 lvitem.mask=LVIF_TEXT; //指出对成员中的哪些数据进行设置
 lvitem.pszText=L"vv"; //将文本设为vv
 lvitem.iItem=0;   //索引值为0
 lvitem.iSubItem=0;  //没有子项
 
 ((CListCtrl *)GetDlgItem(IDC_LIST1))->InsertItem(&lvitem);
 //SP-A4.2.插入行2
 //((CListCtrl *)GetDlgItem(IDC_LIST1))->SetItemText(0,0,L"aa");
 //((CListCtrl *)GetDlgItem(IDC_LIST1))->SetItemText(0,1,L"bb");



 return TRUE;  // return TRUE unless you set the focus to a control
               // EXCEPTION: OCX Property Pages should return FALSE
}

 

 

 

(evc)动态创建列表框

 

BOOL CTest::OnInitDialog()
{
 CDialog::OnInitDialog();
 
//动态创建列表框
//----------------------------------------------------
 #define IDC_LISTBOX 112    //列表框标识,放在头文件中
 CListBox *pList = new CListBox;  //给列表框对象分配内存,在成员变量中定义
 pList->Create(WS_CHILD
     |WS_VISIBLE
     |WS_VSCROLL
     |WS_HSCROLL
     |WS_TABSTOP,  
     CRect(10,10,100,150),  
     this,  
     IDC_LISTBOX);   

delete CListBox;   //用完之后删除
//-----------------------------------------------------
 
 return TRUE;  // return TRUE unless you set the focus to a control
               // EXCEPTION: OCX Property Pages should return FALSE
}

 

 

http://www.cppblog.com/hkingSP/archive/2007/04/02/21090.html

(EVC)CListBox的使用

Posted on 2007-04-02 13:28 宋鹏 阅读(1721) 评论(0)  编辑 收藏 引用 所属分类: Evc Debug Code

ListBox的工程文件
1、在资源浏览器中MENU的菜单上生成一个弹出按钮Test
2、在资源浏览器里insert dialog
3、将该对话框连接到CDialog派生类CTest(自己创建的新类)
//这样在单击Test时就会弹出CTest关联的对话框Test
4、在插入的对话框上可视化添加一个ListBox控件
5、在CTest中添加CTest对话框的初始化消息响应函数,如下

BOOL CTest::OnInitDialog()
{
 CDialog::OnInitDialog();
 

 // TODO: 自己添加的代码
//增加列表框的项
  ((CListBox *)GetDlgItem(IDC_LIST1))->AddString(L"BeiJIng");
 

 return TRUE;                
}

6、在Test按钮的消息相应函数中定义对象,弹出对话框
void CMainFrame::OnTest()
{
 // TODO: Add your command handler code here

 CTest test;
 test.DoModal();
 
}