About Programming Implementation of Mode dialog in HTML

zhaozj2021-02-11  241

A dialog box with images, sounds, and animations is often used in web application development, but to implement such a dialog in VC , you need to do a lot of work. Fortunately, with the appearance of Internet Explorer 4.0 and the new technologies it use, all of these works can be implemented. One way is to use a web browser control, but it is not the best way, especially when the processing mode dialog; another method is to use the HTML Mode dialog introduced by IE4, which resides in the system's MSHTML .dll in the engine explained to HTML. Although some functions such as: Click a link, it is not possible to implement a link to the history of history and in the same window in this mode dialog, but only one mode dialog is used in almost everything, it is enough. .

How to use the mode dialog box in HTML MSHTML.DLL SHOWHTMLDIALOGFN is used to display an HTML dialog, but it needs to use COM elements for strings and other transaction conversions. In order to simplify all of these work, the author uses a class to a COM elements of the package as follows: class CMshtmlDialog {public: void SetDlgOptions (LPCTSTR lpszOptions); void SetSize (int x, int y); LPCVARIANT GetReturnVariant (); CString GetReturnString (); void SetParam (LPCTSTR lpszArgs); void SetParam ( VARIANT * pvarArgs); virtual int DoModal (); CMshtmlDialog (LPCTSTR lpszURL, BOOL bRes = FALSE, CWnd * pParent = NULL); CMshtmlDialog (UINT nResID, CWnd * pParent = NULL); CMshtmlDialog (); virtual ~ CMshtmlDialog (); private: inline void ResourceToURL (LPCTSTR lpszURL); void CommonConstruct (); protected: HWND m_hWndParent; CString m_strOptions; COleVariant m_varArgs, m_varReturn; CString m_strURL; HINSTANCE m_hInstMSHTML;}; // CMshtmlDialog class implementation file CMshtmlDialog :: CMshtmlDialog (). {TRACE0 ( "Warning: Initialization may not be done: Non Functionalcontructor");} CMshtmlDialog :: ~ CMshtmlDialog () {file: // release Mshtml.dll :: FreeLibrary (m_hInstMSHTML);} CMshtmlDialog :: CMshtmlDialog (UINT nResID, CWnd * pParent / * = NULL * /) {m_hWndParent = pParent pParent-> GetSafeHwnd ():? NULL; CString strTemp; strTemp.Format ( "% d", nResID); ResourceToURL (strTemp); CommonConstruct ();} CMshtmlDialog :: CMshtmlDialog (LPCTSTR lpszURL , BOOL bRes, CWnd * pParent / * = NULL * /) {m_hWndParent = pParent pParent-> GetSafeHwnd ():? NULL; if (bRes) {ResourceToURL (lpszURL);} elsem_strURL = lpszURL; CommonConstruct ();} int CMshtmlDialog :: DoModal () {file: // First get the proc ShowHTMLDialogSHOWHTMLDIALOGFN * pfnShowHTMLDialog; pfnShowHTMLDialog = (SHOWHTMLDIALOGFN *) GetProcAddress (m_hInstMSHTML, TEXT ( "ShowHTMLDialog")); if (pfnShowHTMLDialog!) return -1; file: // Now Create a URL Monikerimoniker * PMK = NULL;

BSTR bstrURL = m_strURL.AllocSysString (); CreateURLMoniker (NULL, bstrURL, & pmk); if (pmk!) Return -1; TCHAR * pchOptions = m_strOptions.IsEmpty () NULL: m_strOptions.GetBuffer (0); file:? // now show the HTML DialogHRESULT hr = (* pfnShowHTMLDialog) (m_hWndParent, pmk, m_varArgs, pchOptions, m_varReturn); if (FAILED (hr)) 0return -1; return 0;} void CMshtmlDialog :: CommonConstruct () {m_hInstMSHTML = :: LoadLibrary (TEXT ( "MSHTML.DLL"));} inline void CMshtmlDialog :: ResourceToURL (LPCTSTR lpszURL) {hINSTANCE hInstance = AfxGetResourceHandle (); ASSERT (hInstance = NULL!); LPTSTR lpszModule = new TCHAR [_MAX_PATH]; if ( GetModuleFileName (hInstance, lpszModule, _MAX_PATH)) {m_strURL.Format (_T ( "res: //% s /% s"), lpszModule, lpszURL);} delete [] lpszModule;} void CMshtmlDialog :: SetParam (VARIANT * pvarArgs ) {m_varArgs = pvarArgs;} void CMshtmlDialog :: SetParam (LPCTSTR lpszArgs) {m_varArgs = lpszArgs;} CString CMshtmlDialog :: GetReturnString () {ASSERT (m_varReturn.vt == VT_BSTR); CString str = m_varReturn.bstrVal; return str; LPCVARIANT CMSHT Mldialog :: getreturnvariant () {return (lpcvariant) m_varreturn;} void cmshtmldialog :: setsize (int x, int y) {m_stroptions.format ("Dialogwidth:% D; Dialogheight:% D", x, y);} void CMSHTMLDIALOG :: SetdlGOptions (LPCTSTR LPSZOPTION) {m_stroptions = lpszOptions;} A simple example of using CMSHTMLDialog is like we have to use this class in a dialog box, we have to do a html file and put it with idR_about_htm into resources. File. The functions of ONAppabout are listed here as follows: void chDDemoApp :: ONAppabout () {cmshtmldialog DLG (idR_about_htm, afxgetmainwnd ()); DLG.Domodal ();} You can also use constructor to deliver string resources or displayed URLs to display Graphics and sound resources in HTML can display a complex effect on the dialog.

Passing parameters to the dialog In some, we must not only display an HTML resource, but also pass some parameters from the application (such as: product serial number, license number, etc.), parameter type can be String type It can also be a Variant type. For example, we must display the product serial number, user name, company name, and product version number. You can add the following code: void chDDemoApp :: Ondemoparam1 () {CMSHTMLDIALOG DLG (idR_about1_htm, afxgetmainwnd ()); Cstring str = m_strproductid file: // Product serial number ";" m_strusername file: // user licensed number "; m_strcompanyname file: // company name "; m_strappversion; // version DLG.SETPARAM (STR); DLG.Domodal ();} We must also include some JavaScript or VBScript functions in the actual display HTML home page. Any parameters passing to CMSHTMLDialog in HTML can be used as the Dialogarguments property of the Window object. Take JavaScript as an example: function getParameters () {var args = new array (); args = window.dialogarguments.split (";"); file : // Now Display in the document = args [0]; username.innertext = args [1]; companyName.innertext = args [2]; appver "INNNERTEXT = args [3];} Get return from the dialog box Value We have found that more information can be obtained by combining JavaScript and C , then how do you pass parameters from the dialog as the result of the return value we get and pass back the C program? As an example, we also combined with JavaScript and C , we will give the following code in the HTML window program in the HTML window program: function window_onclose () {window.ReturnValue = Username.Value "; CompanyName.Value; This value can be transferred back to the C program by setting the attribute of the return value.

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

New Post(0)