Récupérer une variable globale Javascript dans un CHtmlView
Bonjour,
Je dispose d'une classe héritant de CDialog et affichant une CHtmlView.
J'arrive effectivement à visualiser une URL grâce à ce procédé. J'aimerai cependant récupérer une variable globale javascript, pour pouvoir ensuite appeler des méthodes de cette variable pour changer dynamiquement le contenue de la page HTML. J'ai trouvé quelques liens sur internet pour récupérer des variables javascript, mais ça n'a pas l'air de fonctionner, seulement je n'arrives pas bien à voir ce que je fais mal (ou que je ne fais pas). Voilà en gros ce que j'ai écris jusqu'à maintenant :
Test.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Test : public CDialog
{
public :
Test(CWnd* pParent = NULL);
afx_msg BOOL OnInitDialog();
bool GetJScript();
virtual ~Test_Oleg();
private :
CHtmlView* m_html;
CComPtr<IHTMLDocument2> m_spDoc;
CComPtr<IDispatch> scripts;
CSplitterWnd m_split;
}; |
.cpp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| BOOL Test::OnInitDialog()
{
CDialog::OnInitDialog();
CRect rect;
GetClientRect( &rect );
m_split.CreateStatic(this, 1, 1);
m_split.CreateView(0,0,RUNTIME_CLASS(CHtmlView), CSize(rect.right, rect.bottom), NULL);
m_html = (CHtmlView*)m_split.GetPane(0, 0);
m_html->Navigate2("lien_html");
m_split.MoveWindow(0,0, rect.right, rect.bottom -40);
m_split.ShowWindow(SW_SHOW);
LPDISPATCH pDisp = m_html->GetHtmlDocument();
if(pDisp)
{
HRESULT hresult = pDisp->QueryInterface( IID_IHTMLDocument2, (void**)&m_spDoc );
if(hresult != S_OK)
{
return FALSE;
}
if(!GetJScript())
{
return FALSE;
}
//Find dispid for given function in the object
CComBSTR bstrMember("DS");
DISPID dispid = NULL;
HRESULT hr = scripts->GetIDsOfNames(IID_NULL,&bstrMember,1,
LOCALE_SYSTEM_DEFAULT,&dispid);
if(FAILED(hr))
{
MessageBox("Can't find DS variable", "", MB_ICONWARNING);
return false;
}
}
} |
la variable DS est représentée comme ceci dans le html :
Code:
1 2 3
| <script name="DS" id="DS">
var DS = new DataSet();
</script> |
Si quelqu'un a une idée, ou sait où est-ce que je m'y prends mal!
Merci d'avance,
Guillaume