Error when trying to hook up a control with DDX_CONTROL

左心房为你撑大大i 提交于 2019-12-12 04:17:58

问题


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.

The important part is this:

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

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>' 

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.

Any advice?


回答1:


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:

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



来源:https://stackoverflow.com/questions/34528471/error-when-trying-to-hook-up-a-control-with-ddx-control

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!