Ah ok thanks... what about loading the class I pasted in the code from the main .CPP so it would be loaded in the Toolbox?....
Main Topics
Browse All TopicsHello everyone,
I'm going to make a custom control which can be loaded on Toolbox to add in a MFC Application as a component. Before I tried creating a MFC ActiveX Control but it's an OCX and plus it uses COM.
So I'm trying to create a regular DLL (which could have more than one control...) and I started with creating a new MFC DLL choosing Use MFC in a Shared DLL.
Then I added a MFC Class where at the start I want to show a rectangle that redraws every time I resize the control on a resource window in a MFC application.
Here I have the code of the class which is supposed to be the custom control inside a DLL, so I'd like to know:
1) how I can initialize this class in the main .CPP of the DLL so I can load the custom control on the Toolbox?
2) how I can associate my own icon to load the custom control class on the toolbox instead to see the one that VC++ picks up?
Thanks
Ciao
Luigi
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I've never tried creating an ActiveX control that integrates with the VS Toolbox.
Just loading code int one or another cpp file is not likely to fix anything. The object needs to get instantiated at some point. But I don't know when or how that needs to be done. And 125 points is small incentive for me to try a test project.
Hello Dan,
I've been playing with it in these two days and I figured out to have a custom control in the Toolbox it has to be an OCX ActiveX COM.
So I played with a Regular DLL thinking on substituting a CStatic in test application as like I have a virtual rect where to put my control.
So I changed the Create method in the class with:
BOOL CaChart::Create(const CRect& rect, CWnd* wnd)
{
if (!CWnd::Create(CACHART_CLA
return FALSE;
SetWindowPos(wnd, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
return TRUE;
}
and in the test MFC application I added a CStatic in the resource and I coded this:
CStatic* c_CStaticPlaced = (CStatic *)GetDlgItem(IDC_MYSTATIC)
CRect r;
c_CStaticPlaced->GetWindowR
ScreenToClient(&r);
CCaChart* c_MyControl = new CCaChart();
CWnd* pWnd = c_CStaticPlaced->GetDlgItem
());
c_MyControl->Create(r, pWnd);
c_CStaticPlaced->DestroyWin
but I get a linker error:
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::OnInitDial
OnInitDialog@Ctest_chartDl
So since constructor and destructor are declared as like the class wizard did as PUBLIC I wonder why it would return me this kind of error....
I added in the linker properties the path and the name of the .lib file as MSDN said but I'm stuck with this weird linker error... do you have maybe a suggest?...
Thanks
Ciao,
Luigi
That's because you have #include'd the right header file (probably CaChart.h) but the CPP file is not part of the project. The compiler cannot find any code that will constuct the CCaChart object.
If you have an OCX, then you need to have the ClassWizard create a wrapper for it so that there is some code to run when you construct the object, or when you use any of its mmber functions, etc.
HI Dan,
it was nothing about that,... .just I forgot to export methods and stuffs from the class so I could use them in the application so I added something like:
#ifdef MYDLL_BUILD
#define MYDLL_IO _declspect(dllexport)
#else
#define MYDLL_IO _declspec(dllimport)
#endif
class MYDLL_IO MyDLL : public CWnd...
and I already reached to draw something on the device context through the OnPaint and OnDraw events.
But if I create a creation own-function (because I have to pass some initialization parameters) to just initialize the dc because it's the background which has to be fixed. And in this case it doesn't draw anything even if I create an instance of CMemDC...maybe when I try to draw something on DC outside OnPaint structure I have to use a different method?...
Nevermind, I figured out everything.... I just had to code an OnPaint() event which calls an OnDraw() event so I had also to set a BOOL variable to stop drawing when resizing so I can manage my own OnEnterSizeMove/OnExitSize
Now I can implement the rest of the component (ah BTW, I had to switch from static library to shared library due for warnings I get, on the other hand from start question about #1 I figured I can't load a DLL in the toolbox because it has to be a COM ActiveX, so I call the DLL component directly from the code and for #2 I assign points to DanRollins). thanks to everyone! :-)))
Ciao,
Luigi
Business Accounts
Answer for Membership
by: DanRollinsPosted on 2009-10-13 at 15:14:13ID: 25565368
#2 should be easy.... just use the resource editor to change the (only) ICON resource in your project.