尝试使用DDX_CONTROL挂接控件时出错 [英] Error when trying to hook up a control with DDX_CONTROL

查看:2785
本文介绍了尝试使用DDX_CONTROL挂接控件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我现在想要工作的代码:

This is the code I'm trying to get to work right now:

#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);
};

正如你所看到的,它主要是基本的初始化,消息映射等。

As you can see, it's mostly basic initializing, with a Message map etc. However, I now want to hook up my CTrackBarCtrl with a DDX_MAP.

重要的部分是:

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


$ b b

这里应该发生的是,m_trackSlider被挂接到ID为IDC_TRACKSLIDER的控件,所以我可以通过操纵变量来控制它。

What should happen here is that m_trackSlider is hooked up to the control with the Id of IDC_TRACKSLIDER, so I can control it by manipulating the variable.

但是,现在我面临这个错误:

However, right now I am facing this error:

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

由于WTLs缺少文档,我不能真正找到问题是什么。我读了子类,但最后,我不会看到另一种方式做到比我想要的方式。我也不认为CTrackBarCtrl是错误的,因为它似乎是滑块的WTL包装。

Due to WTLs missing documentation I can't really find out what the problem would be. I read up on subclassing, but in the end I don't quite see another way to do it than the way I am trying to. I also don't think CTrackBarCtrl is wrong, as it seems to be the WTL wrapper for sliders.

任何建议?

推荐答案

尝试改用DDX_CONTROL_HANDLE。看起来像这个宏不需要SubclassWindow方法。

Try using "DDX_CONTROL_HANDLE" instead. Seems like this macro does not need the "SubclassWindow" method.

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

查看此主题的最后回答以及来自代码项目文章的解释:

See this thread's last answer and the explanation from a codeproject article:

在WTL 7.1中添加的一个新功能是DDX_CONTROL_HANDLE宏。在WTL 7.0中,如果你想用DDX连接一个简单的窗口接口类(例如CWindow,CListViewCtrl等),你不能使用DDX_CONTROL,因为DDX_CONTROL只能使用CWindowImpl派生的类。除了不同的基类需求之外,DDX_CONTROL_HANDLE的工作方式与DDX_CONTROL相同。

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

这篇关于尝试使用DDX_CONTROL挂接控件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆