Как создать пользовательские элементы управления в диалоговом проекте MFC (visual studio 2012)

(Извините за мой плохой английский)
Я пытаюсь создать пользовательский элемент управления в диалоговом проекте MFC (visual studio 2012).
Это настройка при создании проекта на основе MFC Dialog:

Настройки мастера приложений MFC:
введите описание изображения здесь

таможенный контроль бедности:
введите описание изображения здесь

когда я помещаю пользовательский элемент управления в диалог, всегда возникает ошибка компиляции.

журнал :
Предупреждение: не удалось создать диалоговое окно, поэтому приложение неожиданно завершает работу.
Предупреждение: если вы используете элементы управления MFC в диалоговом окне, вы не можете #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.
Программа ‘[0x2524] CustomControl.exe’ вышла с кодом 0 (0x0).

——————————————-MyCustomControl.h ———————————-

#pragma once// MyCustomControl
#define MYWNDCLASS "MyDrawPad"class MyCustomControl : public CWnd
{
DECLARE_DYNAMIC(MyCustomControl)

public:
MyCustomControl();
virtual ~MyCustomControl();

protected:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);

DECLARE_MESSAGE_MAP()
private:
CDC cDC;
BOOL RegisterWndClass();
CPoint oldpt;
BOOL flag;

};

———————————MyCustomControl.cpp —————————————

// MyCustomControl.cpp : implementation file
//

#include "stdafx.h"#include "CustomControl.h"#include "MyCustomControl.h"

// MyCustomControl

IMPLEMENT_DYNAMIC(MyCustomControl, CWnd)

MyCustomControl::MyCustomControl()
{

}

MyCustomControl::~MyCustomControl()
{
}BEGIN_MESSAGE_MAP(MyCustomControl, CWnd)
END_MESSAGE_MAP()// MyCustomControl message handlers

/////////////////////////////////////////////////////////////////////////////
// MyCustomControl message handlers

BOOL MyCustomControl::RegisterWndClass()
{
WNDCLASS windowclass;
HINSTANCE hInst = AfxGetInstanceHandle();

//Check weather the class is registerd already
if (!(::GetClassInfo(hInst, MYWNDCLASS, &windowclass)))
{
//If not then we have to register the new class
windowclass.style = CS_DBLCLKS;// | CS_HREDRAW | CS_VREDRAW;
windowclass.lpfnWndProc = ::DefWindowProc;
windowclass.cbClsExtra = windowclass.cbWndExtra = 0;
windowclass.hInstance = hInst;
windowclass.hIcon = NULL;
windowclass.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
windowclass.hbrBackground = ::GetSysColorBrush(COLOR_WINDOW);
windowclass.lpszMenuName = NULL;
windowclass.lpszClassName = MYWNDCLASS;if (!AfxRegisterClass(&windowclass))
{
AfxThrowResourceException();
return FALSE;
}
}

return TRUE;

}int MyCustomControl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;

// TODO: Add your specialized creation code herereturn 0;
}void MyCustomControl::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

if(flag==FALSE)
{
oldpt=point;
flag=TRUE;
}

//CWnd::OnLButtonDown(nFlags, point);
}

void MyCustomControl::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

if(flag==TRUE)
{

CDC *d=GetDC();

d->MoveTo(oldpt);
d->LineTo(point);oldpt=point;

ReleaseDC(d);
}

//CWnd::OnMouseMove(nFlags, point);
}

void MyCustomControl::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

flag=FALSE;

//CWnd::OnLButtonUp(nFlags, point);
}

——————————————stdafx.h —————————————

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently

#pragma once

#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers
#endif

#include "targetver.h"
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // some CString constructors will be explicit

// turns off MFC's hiding of some common and often safely ignored warning messages
#define _AFX_ALL_WARNINGS

#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#include <afxdisp.h>        // MFC Automation classes#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h>           // MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>             // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

#include <afxcontrolbars.h>     // MFC support for ribbons and control bars#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif

Может кто-нибудь может сказать мне, в чем проблемы?
большое спасибо вам.

2

Решение

Я видел тот же пример, но мой конструктор выглядит иначе. Смотрите код ниже

MyCustomControl::MyCustomControl()
{
//Register My window class
RegisterWndClass();

flag=FALSE; //Sets the drawing flag off
}

Вам также не хватает реализации MESSAGE_MAP

0

Другие решения