高手指点一下,急用,搞不定啊
解决方案 »
- 求正则表达式
- 求助:用CreateProcess函数启动另外一个程序后,如何知道它什么时候运行完毕?
- 我已经失去信心了
- 数据库和存储过程相关的问题?(答者有分)
- 向高手请教:如何在一DLL中调用另一DLL中的位图?
- UDP的sendto和bind的port为什么不一致?
- P4 2G的CPU(升技主板),开机温度就到了45-50度,夏天使用中温度可以达到70-80度以至于死机,这算正常吗?(都有分)
- 简单问题:我有一个中文字符串(全是中文),怎样将其转化成16进制
- 请问这段代码在vc中如何解释?
- intel与HP合作的64位CPU已推出,是否Win32API将来也要变成Win64API,大家讨论一下前景
- 请问如何实现类似资源管理器的预览功能?
- 如何读取二进制流文件。
不过直接用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.
在类中定义一个
CListViewCtrl m_lstBox;在合适的地方调用,(一般考虑在初始化对话框窗口的时候,OnInitDialog)
m_lstBox.Attach( GetDlgItem(IDC_LIST_YOURCONTROL) );其中,IDC_LIST_YOURCONTROL,是你资源中定义的listbox的id
然后,你就可以使用CListViewCtrl的方法,操纵listbox了其他控件类型也可照此办理