[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how do i get OnClick event in CDhtmlDialog derived class

Posted on 2008-11-17
7
Medium Priority
?
1,497 Views
Last Modified: 2013-11-20
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(CDlgEmail)
      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
0
Comment
Question by:bundy9764
  • 4
  • 3
7 Comments
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 2000 total points
ID: 22979523
The code above itself appears to be good, I ran a simple test with the following code and an HTML file located on a web server:

BEGIN_DHTML_EVENT_MAP(CDlgEmail)
      DHTML_EVENT_ONCLICK(_T("btn1"), OnBtn1)
END_DHTML_EVENT_MAP()

HRESULT CDlgEmail::OnBtn1(IHTMLElement * pElement)
{
      AfxMessageBox(_T("OnBtn1 called."));
      return S_OK;
}

Do the input elements of type button, in the remove HTML file, have an id attribute with values btn1 and btn2, i.e. id="btn1" and id="btn2" respectively?
<html>
</head>
<body>
<input type="button" id="btn1" value="Button 1" />
</body>
</html>

Open in new window

0
 

Author Comment

by:bundy9764
ID: 22979583
thanks,
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.
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22980700
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?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:bundy9764
ID: 22982358
attached the two files ( i have removed some of my irrelevant code)
thanks again.
DlgEmailcpp.txt
DlgEmailh.txt
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22986212
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(IHTMLElement* 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.
0
 

Author Comment

by:bundy9764
ID: 22987594
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::OnNavigateComplete which initialize the document pointer.

thanks again for your help.

0
 

Author Closing Comment

by:bundy9764
ID: 31517579
i had a mistake not accepting it earlier :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question