Develop OCX button controls using vc6.0 0 Preface
1. ocx is a typical ActiveX control. There are many common OCX controls. Internet Explorer, word, and Excel all provide a variety of OCX controls.
2. The advantage of OCX control is that it can be used in other applicationsProgram. OCX controls are flexible and convenient as plug-ins and external hanging applications.
3. Generally, it is used as a display area control for videos, images, charts, etc. Recently, several buttons are encapsulated into OCX controls for use by other programs. I searched the internet, but there were not many materials, so I wrote it for searching.
1. Create an OCX Project
1. Open vc6.0 and create an MFC ActiveX project named ocxdemo.
2. Follow the wizard steps and click "finish" to create the project.
3. Define the "add" button in the ocxdemoctrl. h file.
//Button IDC# DefineIdc_button_add 0x2001//"Add" button
Private://"Add" buttonCbutton m_btnadd;
4. Add the "add" button Method for self-painting.
5. Add the create button in the createbtnadd method generated by ocxdemoctrl. cpp.Code.
M_btnadd.create (_ T ("Add"), Ws_child | ws_visible | bs_pushbutton, crect (10,10,60,30),This, Idc_button_add );
6. Add a response event to the "add" button.
//Ocxdemoctrl. hPrivate://"Add" buttonCbutton m_btnadd;//"Add" button click responseVoidOnbuttonadd ();
// Ocxdemoctrl. cpp Begin_message_map (cactivexdemoctrl, colecontrol) // {Afx_msg_map (cactivexdemoctrl) // Note-classwizard will add and remove message map entries // Do not edit what you see in these blocks of generated code! On_bn_clicked (idc_button_add, onbuttonadd) // } Afx_msg_map On_oleverb (afx_ids_verb_properties, onproperties) end_message_map () Void Cocxdemoctrl: Onbuttonadd () {MessageBox ( " Add " );}
7. Delete the code in ondraw.
//PDC-> fillrect (rcbounds, cbrush: fromhandle (hbrush) getstockobject (white_brush )));//PDC-> ellipse (rcbounds );
8. compile and generate ocxdemo. ocx.
9. Source Code: ocxdemo.rar
2. Test ocxdemo. ocx
1. Open ActiveX control test container and insert ocxdemo. ocx.
2. Invoke: createbtnadd method.
3. Test the createbtnadd method.
3 Vc6 calls the OCX control
1. Open vc6.0 and create a project in the MFC Appwizard [EXE] dialog box. Project name: ocxtestdemo.
2. Insert ocxtestdemo. ocx to the control panel.
3. Add the associated member variable m_ocxdemoctrl to the control.
4. bool cocxtestdemodlg: oninitdialog () to add the "add" button.
M_ocxdemoctrl.createbtnadd ();
Compile and generate ocxtestdemo.exe in 5th to view the effect of calling ocxdemo. OXC.
6. Source Code: ocxtestdemo.rar