Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MFC DLL

2 views
Skip to first unread message

Luigino

unread,
Oct 15, 2009, 3:59:13 AM10/15/09
to
Ciao a tutti,

sto cercando di realizzare un custom control implementando una DLL MFC
da visualizzare su Toolbox in modo tale da poterlo utilizzare in MFC
Application...è possibile? Se si, come posso fare?.....

Perché attualmente ho realizzato una classe in una regular MFC DLL che
per il momento mi deve disegnare a video un rettangolo colorato (poi
al suo posto ci faccio tutto il resto del codice) il cui codice di
esempio è il seguente:

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

}

Luigino

unread,
Oct 16, 2009, 4:06:51 AM10/16/09
to
Ciao di nuovo...

giocando ho provato a modificare il metodo Create() della classe con:

BOOL CaChart::Create(const CRect& rect, CWnd* wnd)
{
if (!CWnd::Create(CACHART_CLASSNAME, _T(""), WS_VISIBLE, rect, wnd,
wnd->GetDlgCtrlID()))
return FALSE;
SetWindowPos(wnd, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
return TRUE;
}

cosicché posso "sostituire" ad una CStatic che creo nella resource
dell'applicazione di test di modo da avere un rect fittizio.
E nel codice di inizializzazione dell'applicazione di test
(OnInitDialog) ci metto quanto segue:

CStatic* c_CStaticPlaced = (CStatic *)GetDlgItem(IDC_MYSTATIC);
CRect r;
c_CStaticPlaced->GetWindowRect(&r);
ScreenToClient(&r);
CCaChart* c_MyControl = new CCaChart();
CWnd* pWnd = c_CStaticPlaced->GetDlgItem(c_CStaticPlaced->GetDlgCtrlID
());
c_MyControl->Create(r, pWnd);
c_CStaticPlaced->DestroyWindow();

ma ottengo un errore di questo tipo:

1>test_chartDlg.obj : error LNK2019: unresolved external symbol
"public: __thiscall CCaChart::CCaChart(void)" (??0CCaChart@@QAE@XZ)
referenced in function "protected: virtual int __thiscall
Ctest_chartDlg::OnInitDialog(void)" (?
OnInitDialog@Ctest_chartDlg@@MAEHXZ)

Il bello è che il costruttore CCaChart è public e quindi dovrebbe
trovarlo...non mi spiego sta cosa.
Tra l'altro se dichiaro solo:

CCaChart* c_MyControl;

di modo che ho solo un puntatore e poi istanzio creando l'oggetto
chiamando la Create(...), a compilare compila, ma in esecuzione torna
un errore bloccante dicendomi che la variabile c_MyControl è usata
senza essere inizializzata.

Suggerimenti? Magari mi sono perso qualcosa in giro.... (premetto che
sono un newbie totale di MFC...)
Grazie a tutti,
Ciao
Luigi

0 new messages