Click here to Skip to main content
Email Password   helpLost your password?

Introduction

This article shows how to use CSS, JavaScript and images in resource with CDHtmlDialog in VC++ .NET. I build this project with VC++ 7.1(VS .NET 2003), and it should also work with VC++ 7.0(VS .NET 2002).

Background

CDHtmlDialog is a new class, in MFC 7.x, that enables dialog to use HTML files as resource.

Steps

For example, if there are lines below in the raw HTML file,

<SCRIPT src="layout.js" type=text/javascript></SCRIPT>
<link type="text/css" rel="stylesheet" href="classic.css" />
<img src="showit.gif">

To use CSS files, JavaScript files and images in resource, you must convert all links in HTML file to be the resource numbers.

Then your HTML dialog can make use of those three files in the resource of the executable file.

:-) Good luck.

And this is my first article on CodeProject.com.

Welcome to my page iTreeSoft.

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralCalling javascript function
Nico Cuppen
2:03 7 Mar '09  
I want to call from my application a javascript function that is in the HTML. How should I do that?
GeneralRe: Calling javascript function
TURK
9:37 7 Jun '09  
BOOL CDHtmlDialog::CallJScript(IDispatch* pDisp, const CString strFunc, const CStringArray& paramArray, CComVariant *vaReturn)
{

ATLASSERT(pDisp != NULL);
CComPtr<IDispatch> spScript = pDisp;

CComBSTR bstrMember(strFunc);
DISPID dispid = NULL;
HRESULT hr = spScript->GetIDsOfNames(IID_NULL,&bstrMember,1,
LOCALE_SYSTEM_DEFAULT,&dispid);
if(FAILED(hr))
{
//ShowError(GetSystemErrorMessage(hr));
return false;
}

const int arraySize = paramArray.GetSize();

DISPPARAMS dispparams;
memset(&dispparams, 0, sizeof dispparams);
dispparams.cArgs = arraySize;
dispparams.rgvarg = new VARIANT[dispparams.cArgs];

for( int i = 0; i < arraySize; i++)
{
CComBSTR bstr = paramArray.GetAt(arraySize - 1 - i); // back reading
bstr.CopyTo(&dispparams.rgvarg[i].bstrVal);
dispparams.rgvarg[i].vt = VT_BSTR;
}
dispparams.cNamedArgs = 0;

EXCEPINFO excepInfo;
memset(&excepInfo, 0, sizeof excepInfo);
CComVariant vaResult;
UINT nArgErr = (UINT)-1; // initialize to invalid arg
hr = spScript->Invoke(dispid,IID_NULL,0,
DISPATCH_METHOD,&dispparams,&vaResult,&excepInfo,&nArgErr);

delete [] dispparams.rgvarg;
if(FAILED(hr))
{
//ShowError(GetSystemErrorMessage(hr));
return false;
}

if(vaReturn)
{
*vaReturn = vaResult;


if (vaResult.vt == VT_BSTR )
sResult->SetSysString(&vaResult.bstrVal);
*sResult = vaResult.bstrVal;
else sResult->Empty();

}
return true;
}

How to use CallJScript
HRESULT CAppSettingDlg::OnButtonOK(IHTMLElement* /*pElement*/)
{
CComPtr<IHTMLDocument> pDocument;
IDispatch *dispScript;
IDispatch *dispDocument;
CComVariant vaResult;
CStringArray strarrParam;

m_pBrowserApp->get_Document(&dispDocument);

dispDocument->QueryInterface(IID_IHTMLDocument, (void**)&pDocument);

pDocument->get_Script(&dispScript);

CallJScript(dispScript, _T("submitform"), strarrParam, &vaResult);

if ((&vaResult) && (vaResult.vt == VT_BOOL) && (vaResult.boolVal == -1))
{

UpdateData(TRUE);

m_Settings.setWSServer (m_strServer);
m_Settings.setWSUsername(m_strUsername);
m_Settings.setWSPassword(m_strPassword);
m_Settings.setWSDomain (m_strDomain);
m_Settings.setWSPort (m_strPort);

m_Settings.Save();

OnOK();
return S_OK;
}

return S_OK;
}

Generalvery good!
samsong
17:24 8 Oct '06  
非常好的例子,比微软的哪个DHtmlExplore要好,呵呵Smile

我的MSN: NoblePaul # vip.sina.com。

小牛Smile
Generalrefreshing...很高兴看到中文……呵呵……
iTreeSoft
4:50 26 Mar '08  
Wink
GeneralRe: refreshing...很高兴看到中文……呵呵……
JoeJiao
23:45 5 Oct '08  
我也是的,难得看见中文啊~

Dream my dream,JoeJiao!

GeneralAdding Flash File to Resources
Nauman Khan
0:15 2 Mar '05  
Hi,

Thanks for writing a nice article for using images from Resources. It really helped.

I imported a Flash file into resources and then tried to use it the similar way. RES:/CUS/#139, where #139 referes to Flash file imported[obviously], But the flash file does not get loaded. When i load it from File, it works fine but from Resources, it is having some problem. Does anyone know what can be the problem and if there is way of doing it ?

Regards
Nauman
Laugh
GeneralI am preparing a new sample to use HTML page as skin.
iTreeSoft
5:02 21 Oct '04  
Still use the HTML page in this sample.
Maybe I can post it here in some days.

Smile

good luck
Suspicious
GeneralIt's here
iTreeSoft
16:02 21 Oct '04  
Dialog with HTML skin using CDHtmlDialog and SetWindowRgn[^]

Smile

GeneralImage is not Adding to HTML
pubba
20:14 26 Jul '04  
hi,
I have used Visual C++7 to add a Image to HTML Page.I have used cutom resoure & added acording to the Article.But Image is not Displaying.Why like this?.

Coding Part just like this:-



Generaltest it in plain html file first
pengok
22:45 29 Sep '04  
you can test it in plain html file first.
Then test it as "res:/CUS/#138" in the VC code.

If the image still does not show up,
try to place it in some other place and test it again.

good luck.
Smile

GeneralCDHTMLDialog + Frameset
Kene
3:37 14 Jan '04  
I tried using frameset but the HTML controls in the pages were not calling my dialog code.
It seems the code:
DHTML_EVENT_ONCLICK(_T("ButtonCancel"), OnButtonCancel)

doesn't work for frames.

Pls help me out

What would life be without programmers and salesmen?
Generaltry to use DIV instead of frames.
Anonymous
1:47 15 Jan '04  
Yes, frames are not supported.

Try to use DIV + JavaScript, instead of frames.

That is the way I deal with it in my program.

Smile

Any better one ?

Big Grin


Last Updated 29 Dec 2003 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010