Written in dial-up program of VC 6.0: Daniel Published: 2001/05/22 Abstract: In this paper, visual c 6.0 to achieve a given dialer can be used as an example of VC learner programming practice.
-------------------------------------------------- ------------------------------ Text:
Writing a Dial-up program with VC 6.0 is a commonly used operation, and the program needs to be dial and network connections before running some remote online operations. After completing the operation, it must be closed. In Windows 95/98 "Dial Network", although the dial function is provided, it is impossible to directly develop the application developed. There is no provision between the commonly used controls registered in the system. This method is to make a dial-up control using VC , providing dial and tapping function. MFC ActiveX ControlWizard can quickly generate the program framework of the ActiveX control. The dialing function is supported by the Rasapi32.lib provided by VC , the function and variables are defined in the RAS.H file header. Function rasdial () implements dialing, rashangup () is used to terminate dial-up connections. Function calling method: dword dwret = rasdial (null, null, & rdparams, 0l, null, & hrasconn); dword dwret = rashangup (Hrasconn); where rdparams is the RasdialParams structure, the main parameters are defined as follows: DWORD DWSIZE Structural variable size; tchar SzenTryName [] The connection name created in the dial network; TCHAR SZPHONENUMBER [] phone number, if the number defined in szentryName is used, set to a null value; Char SzcallbackNumber [] Repair number, no need to be set to null; tchar szusername [] users Name; TCHAR SZPASSWORD [] User Password Hrasconn is a HRASCONN structure for remote dialing connections.
First, establish an engineering project
Start the CV integrated development environment, open the "New" dialog, select "MFC ActiveX Control Wizard" in Projects, enter "Dialer" in the Project Name entry, and generate the corresponding path in the Location item. Click the OK button to enter the second step and keep the default value. Click Next to enter the last step, select the Invisible At Run Time (invisible when the runtime window) is kept by default. Press the Finish button to pop up a message dialog box, press the OK button to complete the creation of the project item.
Second, modify the control icon
The engineering item automatically generates a bitmap of 15 x 15 bitmap, which will appear as an icon in the VB resource toolbox. In fact, the icon can be displayed to a 5 x 25-size bitmap. You need to change this bitmap to your own bitmap. The VC integrated development environment provides drawing tools to make you modified.
Third, the control interface
When the application is designed, the embedded control will display an interface. An ellipse is automatically generated when the engineering item is created. Here we are going to drop the code of the ellipse, and increase the following code to limit the size of the control window and display the display icon when the control is designed: Void CDIALERCTRL :: Ondraw (CDC * PDC, Const CRECT & RCBOUNDS, Const CRect & Rcinvalid) {/ / TODO: Replace the following codewith your own drawing code.//pdc-> FillRect (rcBounds, CBrush :: FromHandle ((HBRUSH) GetStockObject (WHITE_BRUSH))); // pdc-> Ellipse (rcBounds); // limit control Window size if (rcbounds.height! = 25 || rcbounds.width! = 25) setControlsize (25, 25); // Display bitmap cbitmap bitmap; cbitmap * Poldbitmap; cdc memdc; memdc.createcompatibleDC (PDC); Bitmap. Loadbitmap; PoldbitMap = MEMDC.SELECTOBJECT (& Bitmap); PDC-> Bitblt (0, 0, 48, 48, & MEMDC, 0, 0, Srcopy); MEMDC.SelectObject (PoldbitMap);} 4, add dialing libraries and Header file ---- adding Rasapi32.Lib and Ras.H to the project.
5. Add control properties
We have to set some properties in the control to implement the delivery parameters and control action of the application and the control. In the Automation tab of the Class Wizard, the class name item selects CDIALERCTRL, click the Add Property button to add control properties.
Six, add dialing and collection line functions
bool CDialerCtrl :: DialUp () {// dialing function RASDIALPARAMS rdParams; rdParams.dwSize = sizeof (RASDIALPARAMS); lstrcpy (rdParams szEntryName, m_netWorking.); lstrcpy (rdParams.szPhoneNumber, m_phone); rdParams.szCallbackNumber [0] = ' / 0 '; lstrcpy (rdParams.szUserName, m_userName); lstrcpy (rdParams.szPassword, m_passWord); rdParams.szDomain [0] =' * '; hRasConn = NULL; // hRasConn HRASCONN type of variable; DWORD dwRet = RasDial (NULL, NULL, & RDPARAMS, 0L, NULL, & HRASCONN); if (dwret == 0) {m_Message = "OK!"; M_returncode = deret; return true;} // Here you save the error handling code Return False;} bool CDIALERCTRL :: Handup () {// Take Wiring function DWORD DWRET = rashangup (hrasconn); // Here I save the error processing code Return True;}
Seven, increase the action function
The value of the Action of the control will automatically run the function, and the action has two actions: 1. Dialing 2. Take a line. Void cxiaxindialctrl :: onactionChanged () {// Todo: add notification handler code == 1) Dialup (); // Call Dial Function IF (M_Action == 2) Handup (); // Call Tuffer Function SETMODIFIEDFLAG ); Eight, compile, link, automatic registration
Starting VC build actions, you will be compiled, and the link generates Dialer.ocx and automatically registers the unit. At this point you can start the VB development platform to open Components, you can see the just registered Dialer ActiveX Control Module.
Nine, VB call method
In VB's development, you can use Dialer.ocx with a common control. Call as follows: Private Sub Command1_Click () Dialer1.NetWorking = Text1.TextDialer1.UserName = Text2.TextDialer1.PassWord = Text3.TextDialer1.Phone = Text4.TextLabel5.Caption = "Dialing ..." Dialer1.Action = 1Labe15. CAPTION = DIALER1.MESSAGE 'If the window minimizes if xiaxindial1.returncode = 0 Then Form1.WindowState = 1END SUB