尝试使用 DDX_CONTROL 连接控件时出错

Error when trying to hook up a control with DDX_CONTROL

这是我现在尝试使用的代码:

#pragma once
#include "stdafx.h"
#include "resource.h"

class MusicPlayerDialog : public CDialogImpl<MusicPlayerDialog>, public CWinDataExchange<MusicPlayerDialog>
{
public:

    MusicPlayerDialog();
    ~MusicPlayerDialog();

    enum { IDD = IDD_MAINDIALOG };

    BEGIN_MSG_MAP_EX(MusicPlayerDialog)
        MESSAGE_HANDLER(WM_CLOSE, OnClose)
        MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
        MESSAGE_HANDLER(WM_INITDIALOG, OnInit)

        COMMAND_ID_HANDLER_EX(IDC_CLOSE, OnExitButtonClick)
    END_MSG_MAP()

    BEGIN_DDX_MAP(MusicPlayerDialog)
        DDX_CONTROL(IDC_TRACKSLIDER, m_trackSlider)
    END_DDX_MAP()

    LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
    LRESULT OnInit(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);


private:

    CTrackBarCtrl m_trackSlider;

    void OnExitButtonClick(UINT uCode, int nCtrlID, HWND hwndCtrl);
};

如您所见,它主要是基本的初始化,带有消息映射等。但是,我现在想用 DDX_MAP.

连接我的 CTrackBarCtrl

重要的部分是:

    BEGIN_DDX_MAP(MusicPlayerDialog)
        DDX_CONTROL(IDC_TRACKSLIDER, m_trackSlider)
    END_DDX_MAP()

这里应该是m_trackSlider挂上了Id为IDC_TRACKSLIDER的控件,所以我可以通过操作变量来控制它。

但是,现在我遇到了这个错误:

error C2039: 'SubclassWindow': Is No Element Of 'WTL::CTrackBarCtrlT<ATL::CWindow>' 

由于 WTL 缺少文档,我无法真正找出问题所在。我阅读了有关子类化的内容,但最后我并没有看到比我尝试的方式更好的另一种方式。我也不认为 CTrackBarCtrl 是错误的,因为它似乎是滑块的 WTL 包装器。

有什么建议吗?

请尝试使用 "DDX_CONTROL_HANDLE"。似乎这个宏不需要 "SubclassWindow" 方法。

BEGIN_DDX_MAP(MusicPlayerDialog)
    DDX_CONTROL_HANDLE(IDC_TRACKSLIDER, m_trackSlider)
END_DDX_MAP()

查看此线程的 last answer 和代码项目文章中的解释:

A new feature that was added in WTL 7.1 is the DDX_CONTROL_HANDLE macro. In WTL 7.0, if you wanted to hook up a plain window interface class (such as CWindow, CListViewCtrl, etc.) with DDX, you couldn't use DDX_CONTROL because DDX_CONTROL only works with CWindowImpl-derived classes. With the exception of the different base class requirement, DDX_CONTROL_HANDLE works the same as DDX_CONTROL.

WTL for MFC Programmers, Part IV - Dialogs and Controls