高手指点一下,急用,搞不定啊

解决方案 »

  1.   

    这种内置的基本windows control就没必要用WTl搞得这么复杂了吧,看看MSDN/SDK, 用宏或者Message完全能简洁、快速的搞定的
      

  2.   

    可是我的dialog有很多控件,用sdk做很复杂的,程序是个addin,不支持mfc的,如何是好?
      

  3.   

    不会复杂的,比用WTL看起来应该更简洁才是
      

  4.   

    用ddx.很简单啊 应该看的懂下面的东西把  有神么不明白email我[email protected]
    不过直接用sdk也不难,甚至更简洁.用一下GetDlgItemDouble, SetDlgItemDouble
    SetDlgItemFloat SetDlgItemInt SetDlgItemText.....只需要控件id,用着很舒服
    WTL’s support for DDX 
    Another of MFC’s features that WTL copies is Dynamic Data Exchange (DDX). DDX is the act of moving data back and forth between a Window object’s data members and a window’s child controls. WTL provides support for DDX via the CWinDataExchange class and a set of macros that implement the DoDataExhange method of this class.// atlddx.h
    template <class T> class CWinDataExchange {
    public:
    // Data exchange method - override in your derived class
    BOOL DoDataExchange(BOOL /*bSaveAndValidate*/ = FALSE, UINT 
     
                  /*nCtlID*/ = (UINT)-1)
    {
    // this one should never be called, override it in
    // your derived class by implementing DDX map
    ATLASSERT(FALSE);
    return FALSE;
    }

    };Any class that wants to participate in the DDX ritual simply derives from CWinDataExchange and provides an implementation of the DoDataExchange method. This method is implemented most easily via the DDX_MAP with each entry corresponding to the child controls placed on its client area, for example,class CStringDialog :
        public CDialogImpl<CStringDialog>,
        public CWinDataExchange<CStringDialog>
    {
    public:
        CStringDialog() { *m_sz = 0; }    enum { IDD = IDD_STRING };
        BEGIN_MSG_MAP(CStringDialog)
            COMMAND_ID_HANDLER(IDOK, OnOK)
            COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
            MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
        END_MSG_MAP()    BEGIN_DDX_MAP(CMainDlg)
            DDX_TEXT(IDC_STRING, m_sz)
        END_DDX_MAP() LRESULT OnInitDialog(UINT, WPARAM, LPARAM, BOOL&) {
    DoDataExchange(FALSE);  // Populate the controls
    return 0;
    }    LRESULT OnOK(WORD, WORD wID, HWND, BOOL&) {
            DoDataExchange(TRUE);  // Populate the data members
            EndDialog(wID);
            return 0L;
        }    LRESULT OnCancel(WORD, WORD wID, HWND, BOOL&) {
            EndDialog(wID);
            return 0L;
        } 
    public:
        enum { MAX_STRING = 128 };
        char    m_sz[MAX_STRING+1];
    };CStringDialog is a dialog that derives from CWinDataExhange and contains a single edit control. The dialog first populates the edit control with whatever is in the m_sz data member during WM_INITDIALOG when the handler calls DoDataExchange(FALSE). The dialog synchronizes the data member to the state of the edit control when the user presses the OK button and the handler calls DoDataExchange(TRUE). This is very similar to MFC’s DDX implementation and the usage.LRESULT CMainFrame::OnFileTitle(WORD,WORD wID, HWND,BOOL&) {
        CStringDialog   dlg;
        GetWindowText(dlg.m_sz, dlg.MAX_STRING);
        if( dlg.DoModal() == IDOK ) SetWindowText(dlg.m_sz);
        return 0L;
    }In addition to text, WTL’s DDX supports signed and unsigned integers and floating-point numbers. It also supports controls like radio buttons and checkboxes. Table 3 shows the macros that atlddx.h defines. 
    Table 3: WTL’s DDX Macros
     
    Macro                               PurposeDDX_TEXT(nID, var)                      Associates the text content of a control with the CString, CComBSTR or LPTSTR member variable of your class.DDX_TEXT_LEN(nID, var, len)             Same as DDX_TEXT but also validates the length.DDX_INT(nID, var)                      Associates the numeric value that the user typed in a control with the integer class member.DDX_INT_RANGE(nID, var, min, max)    Same as DDX_INT but also validates the range.DDX_UINT(nID, var) Same as DDX_INT for unsigned Integers.DDX_UINT_RANGE(nID, var, min, max)    Same as DDX_INT_RANGE for unsigned integers.DDX_FLOAT(nID, var)             Same as DDX_INT for floats.DDX_FLOAT_RANGE(nID, var, min, max)    Same as DDX_INT_RANGE for floats.DDX_CONTROL(nID, obj)             DDX_CONTROL subclasses a control, represented by the obj parameter in the macro (just like in MFC). Because of that, your data member must derive from CWindowImpl (or at least have SubclassWindow method).DDX_CHECK(nID, var)             Sets the var to the checked state of  the button.DDX_RADIO(nID, var)     Manages the transfer of integer data between a radio control group and a int data member.Compared to MFC, WTL’s DDX doesn’t happen automatically; you have to call manually call DoDataExchange. This gives you flexibility to call it exactly when you want. Also, you can call it for only one control by passing in the control’s id to DoDataExchange.
      

  5.   

    最简单的办法:
    在类中定义一个
    CListViewCtrl m_lstBox;在合适的地方调用,(一般考虑在初始化对话框窗口的时候,OnInitDialog)
           m_lstBox.Attach( GetDlgItem(IDC_LIST_YOURCONTROL) );其中,IDC_LIST_YOURCONTROL,是你资源中定义的listbox的id
    然后,你就可以使用CListViewCtrl的方法,操纵listbox了其他控件类型也可照此办理