Development of ActiveX Controls
During this time, because of the needs of the work, an ActiveX control has been developed. The development tool used is VC, I hope to provide a reference to everyone to do a similar development.
First, the function of the ActiveX control:
1. Mainly used to download and save the specified web page.
2. To be able to be embedded in the web page, the script call for the server page.
3. Provide a window that is saved to which folder to give the user yourself to save the location.
4. Provide program interfaces such that users can save a single file.
5. Provide a program interface that allows the user to save multiple files, and the file name is passed in an array.
Second, the development process of ActiveX control:
1. Develop this control through the MFC ActiveX ControlWizard Wizard Wizard, name the project to ActiveX3
2, hook the Invisible At Runtime in the wizard and remove the hook in front of the HAS AN "About" Box, which is not displayed when calling.
3, open ClassWizard, add the method under Automation:
(1) External name: DownloadSingle
INTERNAL NAME: DownloadSingle
Return Type: BOOL
Parameter List: STRDOWNLOAD LPCTSTR
The method of this method: accepts and handles parameters to download requests for string types, while providing operators with the chance to specify download directory and accept it.
(2) External name: DownloadArray
Internal Name: Downloadarray, INTERNLOADARRAY
Return Type: BOOL
Parameter List: ArrdownLoad Variant
The method of this method: accepts and handles the download request for the parameter string array type, and provides the operator with the chance to specify the download directory and accept it.
4, add the method by manual:
Void Tryurl (CString straddress)
Calling by Downloadarray and DownloadSingle to implement specific download functions.
Third, key code
1, BOOL CACTIVEX3CTRL :: DownloadSingle (LPCTSTR STRDOWNLOAD)
{
// Todo: Add Your Dispatch Handler Code Here
Char buf [max_path];
_Getcwd (buf, max_path);
Location = "d: //";
Tryurl (strDownload);
MessageBox ("Download Details!");
Return True;
}
2, Bool Cactivex3ctrl :: DownloadArray (Const Variant Far & Arrdownload)
{
// Todo: Add Your Dispatch Handler Code Here
Char buf [max_path];
_Getcwd (buf, max_path);
Location = "d: //";
Const Variant * Vararray;
IF (arrdownload.vt == (vt_variant | vt_byref))
{
Vararray = arrdownload.pvarval;
}
Else
{
Vararray = & arrdownload;
}
IF ((Vararray-> VT) == (vt_array | vt_byref | vt_variant))))
{
VARIANT * STRARRAY;
SafeArray * psa = * (Vararray-> PPARRAY);
SafearrayAccessData (PSA, (void **) & stratay;
UINT UDIM = SafeArraygetdim (PSA);
IF (udim == 1)
{
Long llbound, lrbound;
SafeArraygetlbound (PSA, 1, & LLBOUND);
SafeArraygetubound (PSA, 1, & LRBOUND);
For (long i = llbound; i <= lrbound; i )
{
IF (Strarray [i] .vt == vt_bstr)
{
Tryurl (strrray [i] .bstrval);
}
}
}
SafeArrayunaccessData (PSA);
}
MessageBox ("Download Details!");
Return True;
}
3, Void Cactivex3ctrl :: Tryurl (CString straddress)
{
CFILE NEWFILE;
CString filename = straddress.mid (straddress.reversefind ('/') 1);
Newfile.open (Location "//" filename, cfile :: modecreate | cfile :: modewrite;
CinternetSession session;
CinternetFile * file = NULL;
Try
{
File = (CinternetFile *) session.openurl (straddress);
Catch (CinternetException * PEX)
{
File = NULL;
PEX-> delete ();
}
IF (file)
{
INT number = 0;
BYTE * BUF;
BUF = New byte [1024];
DO
{
Number = file-> read (buf, 1024);
Newfile.write (buf, number);
}
While (NUMBER> 0);
DELETE [] BUF;
}
File-> close ();
Newfile.close ();
Return;
}
Fourth, test page
Function Download1 ()
{
Var file;
File = Document.form1.text1.value;
Favoritedown.DownloadSingle (file);
Return;
}
script>
Sub Down_ONCLICK
DIM S (2)
s (0) = Document.form1.text1.Value
s (1) = Document.form1.text2.Value
s (2) = document.form1.text3.Value
ActivexDown.downloadArray (s)
End Sub
->
script>
hEAD>