Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Custom Control toolbox in a regular MFC DLL

LuiginoLuigino Member Posts: 3
Hello everyone!!!

I'm trying to make a custom control with a regular MFC DLL which can be loaded on the toolbox. Is that possible? If yes, how?...Any suggest?

Because actually I coded a class inside a regular MFC DLL which should paint a rectangle in the area where I draw the component on the MFC Application (then I'll replace that code of rectangle with the rest of code) but I'm stuck... here is the code:

#include "stdafx.h"
#include "CDLLControls.h"
#include "CSingleDLL.h"

// CSingleDLL

IMPLEMENT_DYNAMIC(CCaChart, CWnd)

CSingleDLL::CSingleDLL()
: iGraphType(GRAPH_BARS)
{
RegisterWindowClass();

}

CSingleDLL::~CSingleDLL()
{

}

// Register the window class if it has not already been registered.
BOOL CSingleDLL::RegisterWindowClass()
{
WNDCLASS wndcls;
HINSTANCE hInst = AfxGetInstanceHandle();

if (!(::GetClassInfo(hInst, CSINGLEDLL_CLASSNAME, &wndcls)))
{
// otherwise we need to register a new class
wndcls.style = CS_DBLCLKS | CS_HREDRAW |
CS_VREDRAW;
wndcls.lpfnWndProc = ::DefWindowProc;
wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
wndcls.hInstance = hInst;
wndcls.hIcon = NULL;
wndcls.hCursor = AfxGetApp()->LoadStandardCursor
(IDC_ARROW);
wndcls.hbrBackground = (HBRUSH) (COLOR_3DFACE + 1);
wndcls.lpszMenuName = NULL;
wndcls.lpszClassName = CSINGLEDLL_CLASSNAME;

if (!AfxRegisterClass(&wndcls))
{
AfxThrowResourceException();
return FALSE;
}
}

return TRUE;

}

BEGIN_MESSAGE_MAP(CSingleDLL, CWnd)
//{{AFX_MSG_MAP(CSingleDLL)
ON_WM_PAINT()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// CSingleDLL message handlers
void CSingleDLL::OnPaint()
{
CPaintDC dc(this); // device context for painting

// Create memory DC
CDC MemDC;
if (!MemDC.CreateCompatibleDC(&dc))
return;

CRect rect;
GetClientRect(rect);

// Paints a rectangle
MemDC.Rectangle(rect);
}

BOOL CSingleDLL::OnEraseBkgnd(CDC* pDC)
{
return CWnd::OnEraseBkgnd(pDC);

}

void CSingleDLL::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base
class
// In our case this is not needed - yet - so just drop through
to
// the base class

// Get Size of Display area

CWnd::PreSubclassWindow();

}

BOOL CSingleDLL::Create(CWnd* pParentWnd, const RECT& rect, UINT nID,
DWORD dwStyle /*=WS_VISIBLE*/)
{
return CWnd::Create(CSINGLEDLL_CLASSNAME, _T(""), dwStyle,
rect,
pParentWnd, nID);

}
Sign In or Register to comment.