Control

zhaozj2021-02-16  49

Control

He Zhidan 1, File => New => Project => MFC ActiveX ControlWizard Creates a project called Owner, all settings are default, direct finish. 4, CTRL F5 runs. Executable for debug session, select cancellation. 5, TOOL => ActiveX Control Test Container is tested. 6. Register, copy the control's OCX file to the Windows system directory, such as: Win95 / System. Start menu, runregsvr32 Owner.ocx. Regsvr32 [/ u] [/ s] [/ c] [/ i [: cmdline ]]]] Dllname where: / U Logan / S does not display the prompt information / c output console / i call dllinstall and pass CMDLINE, call the logout / n when using / u Do not call DLLREGISTERSEVER, must be used with / i . 7. Create a dialog-based executable OwneRexe, Note AppWizard-Step 2 of 6 Select the ActiveX Controls check box. Application Guide to us Add Bool Cownerexeapp :: InitInstance () {AFXENSTANCE () {AFXENABLECONTROLCONTAINER (); ...... 8, Project => add to project- Components. Find the control you just registered and inserted into the control toolbar. Get it on the dialog as using standard controls. 9, CTRL F5, we can see anything that is not dry. Let's take a check of a number of power (such as 1, 2, 4, 8) that checks a number of 2, let us supplement the second step and third steps. 2, add a Booler variable IS2N in COWNERCTRL, the initial value is false; change the onDrawne: Void CownerCtrl :: Ondraw (CDC * PDC, Const CRECT & RCBOUNDS, Const CRECT & RCINVALID) {CBRUSH * PBRUSH; if (IS2N) PBRUSH = New CBRUSH (RGB (255, 0)); Else Pbrush = New CBRUSH (RGB (255, 255, 255)); PDC-> FillRect (RCBounds, PBRUSH); delete pbrush;} Ctrl W Open Class Wizard, Automation => Add Method Name Fill in the ISPOW2N, returns VOID, a long shaped parameter x. Note that there are multiple parameters, mobilized with the downwise key or PageDown. Modify this function: void cownerctrl :: ISPOW2N (long x) {is2n = ((x & -x) == x); invalidateControl ();} Ctrl F5 generates new OCX, covering the original OCX. Note when Windows System Directory After the OCX is modified, OXC in our program will automatically update the control. Not all functions of the control can be called by the control user, only the method can be.

Go back to OWNEREXE, add an edit control (associated with a long shape variable m_input) and a button, let the control associated with m_ctrl, this button's response function is: void cownerexedlg :: Onis2n () {updatedata (); m_ctrl. IsPow2N (M_INPUT);} Ctrl F5, view the effect, take a closer look, when the input is zero, the result is wrong. Obviously 0 cannot be 2 N times. 3, we define an event for the control, the event is very similar to a custom message, you must decide when it is called, and it is necessary to set the initial value when it is called. Go back to our control, Ctrl W => ActiveX Events => add events. Name ZERO, parameter is x, long shaping. Insert IF (0 == x) Firezero (X); in Void CownerCtrl :: ISPOW2N (LONG X), indicating that the parameter of ISPOW2N is found in the ISPOW2N execution process, this method is called. And its parameters are the same as ISPOW2N. Void cownerCtrl :: ISPOW2N (long x) {is2n = ((x & -x) == x); if (0 == x) {Firezero (x); IS2N = false;} invalidateControl ();} Back to Ownerexe, Ctrl W => MessageMaps. ID Fill in our control, double-click our just added ZERO, edit the function: void cownerexedlg :: onzerookingnerctrl1 (long x) {cstring str; fact ("Please enter a non-% LD Integer ", X); AFXMessageBox (STR);} Ctrl F5.3.5 You may think that color setting is too bad, we can increase the properties of the control. Go back to our control, Ctrl W => Automation => add proty; select Inventory Properties in External Name. We come from defined two attributes that are 2 N times color and the color, iScolor, NotColor; type is OLE_COLOR; edit code. Void cownerCtrl :: oniscolorchanged () {invalidateControl (); setmodifiedflag ();

转载请注明原文地址:https://www.9cbs.com/read-25728.html

New Post(0)