bundy9764
asked on
how do i get OnClick event in CDhtmlDialog derived class
Hi,
i have created a class that inherits from CDHtmlDialog,
i added DECLARE_DHTML_EVENT_MAP to my header file
and the following event map to the cpp file
BEGIN_DHTML_EVENT_MAP(CDlg Email)
DHTML_EVENT_ONCLICK(L"btn1 ", OnBtn1)
DHTML_EVENT_ONCLICK(L"btn2 ", OnBtn2)
END_DHTML_EVENT_MAP()
my HTML file is loaded from a url and not from a resource.
both the btn1 and btn2 elements are included in the html file.
when clicking those elements, nothing happens,
i cant get the onclick event to get into my cpp code.
any idea what did I do wrong?
thanks
i
i have created a class that inherits from CDHtmlDialog,
i added DECLARE_DHTML_EVENT_MAP to my header file
and the following event map to the cpp file
BEGIN_DHTML_EVENT_MAP(CDlg
DHTML_EVENT_ONCLICK(L"btn1
DHTML_EVENT_ONCLICK(L"btn2
END_DHTML_EVENT_MAP()
my HTML file is loaded from a url and not from a resource.
both the btn1 and btn2 elements are included in the html file.
when clicking those elements, nothing happens,
i cant get the onclick event to get into my cpp code.
any idea what did I do wrong?
thanks
i
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The wide strings are fine if your application is compiled in Unicode mode.
Have you used the wizard to create the class or was it added to an existing project manually? Can you post the code for your class perhaps?
Have you used the wizard to create the class or was it added to an existing project manually? Can you post the code for your class perhaps?
ASKER
attached the two files ( i have removed some of my irrelevant code)
thanks again.
DlgEmailcpp.txt
DlgEmailh.txt
thanks again.
DlgEmailcpp.txt
DlgEmailh.txt
At the moment I still do not see the problem in the code however one question that arises is how do you know that OnBtn1 is not called? The code in the file for OnBtn1 would not indicate that it executed:
HRESULT CDlgEmail::OnBtn1(IHTMLEle ment* pElement)
{
CComBSTR szId;
pElement->get_id(&szId);
return S_OK;
}
Try adding AfxMessageBox(_T("OnBtn1 called.")); to the function body to see if it gets called.
I basically added a new MFC class derived from CDHtmlDialog to a sample project, then verified that it matches the code you have i.e. same DHTML Event Map, same approach of navigating to the web page on a server, and then created an instance of the class during a button click in the main app:
CDlgEmail dlgE;
dlgE.DoModal();
The dialog opened and displayed the web page and a message box was shown when the button was clicked.
HRESULT CDlgEmail::OnBtn1(IHTMLEle
{
CComBSTR szId;
pElement->get_id(&szId);
return S_OK;
}
Try adding AfxMessageBox(_T("OnBtn1 called.")); to the function body to see if it gets called.
I basically added a new MFC class derived from CDHtmlDialog to a sample project, then verified that it matches the code you have i.e. same DHTML Event Map, same approach of navigating to the web page on a server, and then created an instance of the class during a button click in the main app:
CDlgEmail dlgE;
dlgE.DoModal();
The dialog opened and displayed the web page and a message box was shown when the button was clicked.
ASKER
thanks for your help,
i knew that the code doesnt work because i have a breakpoint on this function :)
i have found the problem which was not related to the message map or anything, i was listenning to the OnNavigateComplete event, and didnt call CDhtmlDialog::OnNavigateCo mplete which initialize the document pointer.
thanks again for your help.
i knew that the code doesnt work because i have a breakpoint on this function :)
i have found the problem which was not related to the message map or anything, i was listenning to the OnNavigateComplete event, and didnt call CDhtmlDialog::OnNavigateCo
thanks again for your help.
ASKER
i had a mistake not accepting it earlier :)
ASKER
thats what i was trying to do...
the page was loaded using the navigate function.
the Ids are set on the html but still no call made to the c++ function.
the only diffrence from your code is the use of _T macro, i have made all calls as wide strings.