简体   繁体   中英

How to create and add a custom made component to a Dialog based app (MFC)?

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM