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

Проверка пользовательского элемента управления:
когда я добавляю пользовательский элемент управления в диалог, всегда возникает ошибка компиляции.
log :Внимание: создание диалогового окна не удалось, поэтому приложение завершается. неожиданно.
Предупреждение: если вы используете элементы управления MFC в диалоговом окне, вы не можете #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS.
Программа «[0x2524] CustomControl.exe» завершилась с кодом 0 (0x0).
-------------------------------------------MyCustomControl. ч----------------------------------
Код: Выделить всё
#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 : 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 here
return 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 : 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 // MFC core and standard components
#include // MFC extensions
#include // MFC Automation classes
#ifndef _AFX_NO_OLE_SUPPORT
#include // MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#include // 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
Большое спасибо.
Подробнее здесь: https://stackoverflow.com/questions/276 ... studio-201