tags:

views:

39

answers:

2

I want to make a custom made component (a line chart), that would be used in other applications.

I don't know 2 things:

  1. Where should I use (within component class!) the methods for drawing, like FillRect

    or PolyLine? In OnPaint handler that I should define and map it in MESSAGE MAP? Will

    it (OnPaint handler) be called from OnPaint handler of the dialog of the application

    or where from?

  2. How to connect the component, once it is made, to the test application, which will

    for example be dialog based? Where should I instantiate that component? From an

    OnCreate method of the MyAppDialog.cpp?

I started coding in MFC few days ago and I'm so confused about it.

Thanks in advance,

Cheers.

A: 

Painting the control is handled exactly like it would be if it wasn't a control. Given that you're using MFC, that (at least normally) means you do the drawing in the View class' OnDraw (MFC normally handles OnPaint internally, so you rarely touch it).

Inserting the resulting ActiveX control in the host application will be done like inserting any other ActiveX control. Assuming you're doing your development in Visual Studio, you'll normally do that by opening the dialog, right clicking inside the dialog box, and clicking "Insert ActiveX Control..." in the menu that pops up. Pick your control from the list, and it'll generate a wrapper class for the control and code to create an object of that class as needed. From the viewpoint of the dialog code, it's just there, and you can use it about like any other control.

Jerry Coffin
The thing is I'm using a dialog based application and there's no `OnDraw` method in it, cause there's no myAppView and `myAppDocument classes`. I don't even know which class should I inherit in my component class. Btw I'm not trying to make ActiveX control, but rather just a Cpp file, that would be used later. Maybe there's something here I'm getting completely wrong, and if I am, I'm sorry in advance.Thanks for the effort you're putting in trying to help me!
kobac
If you want to do your own drawing in a dialog, you *really* want to do it in a control.
Jerry Coffin
A: 

For create new component in MFC, you must create a class from the window class (CWND),

after that you can have your MessageMap for the component and your methods and also can override CWND::OnDraw method to draw the thing you want. Before that I suggest you to take a look to device context

http://msdn.microsoft.com/en-us/library/azz5wt61(VS.80).aspx

Good Luck friend.

Shahrooz Kia