Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Sorry if I am posting this in the wrong place but I didn't really think it clearly fit in any of the other sections.

 

I am trying to make an application that has a section that would be control via an HTML page. As an example of what I am talking about look at the Start page that opens by default in .NET IDE.

 

I need to be able to place controls on the HTML page and have them control the program but really not sure how to go about this. Any pointers to tutorials or examples would be welcome.

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

  • Leaders
Posted
I have no clue but... until someone comes along that does, you might take a look at vsHome.js (or something similar) to see if you can glean any insight from it. It appears (from a View Source) to be the brains behind the Start Page in VS.NET. I'm sure someone will come in soon with something more helpful.
--tim
  • *Experts*
Posted

The Start Page of VS.NET does not actually interact with the IDE

itself; it simply accesses the registry to get the list of recent projects,

and lists them as standard <a> links. When you click on one, it

opens the project in VS.NET as if you double clicked in in Explorer.

There isn't really any "interaction" between the IDE and the Start

Page going on, but it does access the registry, etc.

 

AFAIK, what you want is not possible directly, without coding your

own handlers, etc, into the program; any code you wanted to execute

would most likely be done totally in your program using click handlers

and such, instead of in the code of the webpage.

Posted

Ok... I had to reread your post a couple of times to get the sense of what you were saying and I think I finally got it. Still not sure how to implement this in my own program though. I am trying to make an IDE for making skins for another program and I wanted to use a similar design to the VS.NET IDE.

 

Any suggestions on what I would need to do to get this part working the same (or equivalent) way?

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

  • *Experts*
Posted

Why would you want to use HTML controls in a windows app? Don't the Windows controls do what you need? Or, why not go pure web app if you're more familiar with that? I'm not sure I understand what you're doing and why would want the two to interface so closely, aside from "can it be done"...

 

There was another post about hooking the events from a WebBrowser control. I think divil posted the way to cast the control's document property to a "real" .NET type. Using a similar technique, you might be able to trap an HTML button's click or a hyperlink that's navigating away and intercept to run some code on your form. Not sure why you'd want it to work that way - seems like a lot of work :)

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Gurus*
Posted

This topic interests me. I posted an example in this thread of how to catch HTML document events from within a .NET app hosting a webbrowser control. You could make use of this to do exactly what you need.

 

I would be interested to see the results if and when you implement this.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

Thanks for the post everyone.

 

 

 

Why would you want to use HTML controls in a windows app? Don't the Windows controls do what you need?

 

The why isn't all that important. For a short answer... it allows the layout and design of these windows to be tweaked outside the development enviroment. It also allows you to do other things in the same window like visit related websites and and view the HTML help files. Ease of use for the user... not the programmer.

 

divil: Thanks for posting. I will check out your link and will be happy to show you the results when I have them. :-)

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Posted

divil (or anyone else that can answer):

 

I looked over the source that you provided in your project at the above link. I ran it and it worked fine for grabbing the text of whatever fired the onmouseover event on the webpage. I tried to change this to indicate an onclick even being fired but really don't know enough about C# to pull this off.

 

I then began the process of trying to at least translate what that application does over to VB.Net. Most of it is pretty straightforward I think but one section stumps me:

 

private void wb_DownloadBegin(object sender, System.EventArgs e)
{
doc = (mshtml.HTMLDocument)wb.Document;

((mshtml.HTMLDocumentEvents_Event)doc).onmouseover += new mshtml.HTMLDocumentEvents_onmouseoverEventHandler(onmouseover);
}

 

I was able to get part of this since you had done an example of something similar a few post before you posted your project. The first line is almost a direct copy of the Directcast that you did in that post. The second line eludes translation by me though. I fear this is just a lack of understanding on exactly what it is doing and how C# works in this instance. Any help and explaination of the principles in that example would be helpful.

 

Thanks.

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

  • *Gurus*
Posted

That last like should translate to:

 

AddHandler DirectCast(doc, mshtml.HTMLDocumentEvents_Event).onmouseover, AddressOf onmouseover)

 

Assuming you have declared the onmouseover sub in your code properly. If you haven't, it will tell you so and how to fix it. I'm sorry if I haven't got it exactly right, I don't have time to look at the example I posted at this instant.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

Thanks for all the help divil... still working on a VB solution to your C# example. Don't think I am quite getting it right though. First of all I have had to add the webbrowser control to the form programmatically. For some reason I wind up with errors if I try to add it at design time. It will let me add it but it will give me errors. If I do it at run time then it works fine.

 

This is what I have so far. For posting the code I have removed the Form Designer Generated Code. The app is just a form (Form1) and a label docked to the bottom (Label1). The webbrowser control (webbrowser) is added at runtime:

 

Public Class Form1
   Inherits System.Windows.Forms.Form
   
   'took this out for the sake of a short example
   #Region " Windows Form Designer generated code " 

   Private doc As mshtml.HTMLDocument
   Private webbrowser As AxSHDocVw.AxWebBrowser

   Protected Overrides Sub OnLoad(ByVal e As EventArgs)
       webbrowser = New AxSHDocVw.AxWebBrowser()
       Me.Controls.Add(webbrowser)
       webbrowser.Dock = DockStyle.Fill
       webbrowser.Navigate2("http://www.xtremedotnettalk.com")
   End Sub

   Private Sub onmouseover()
       Dim HTML As String
       HTML = doc.parentWindow.event.srcElement.innerText
       Label1.Text = HTML
   End Sub

   Private Sub webbrowser_DownloadBegin(ByVal sender As Object, ByVal e As System.EventArgs)
       doc = DirectCast(webbrowser.Document, mshtml.HTMLDocument)
       AddHandler DirectCast(doc, mshtml.HTMLDocumentEvents_Event).onmouseover, AddressOf onmouseover
   End Sub
End Class

 

The it doesn't seem to reach the last two subs at all. It just loads the webpage. Can you spot what I am doing wrong? Sorry if it is something simple. I am still just starting out with .NET. Anyone else that can help is welcome to speak up too. LOL

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

  • *Gurus*
Posted

It's odd that you can't add the webbrowser control at design time. Assuming, though, that you have it declared withevents as wb, as I did, you can just modify that last sub as follows:

 

Private Sub webbrowser_DownloadBegin(ByVal sender As Object, ByVal e As System.EventArgs) Handles wb.DownloadBegin
       doc = DirectCast(webbrowser.Document, mshtml.HTMLDocument)
       AddHandler DirectCast(doc, mshtml.HTMLDocumentEvents_Event).onmouseover, AddressOf onmouseover
   End Sub

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

Well had to take a week off from this problem due to RL stuff... came back and redid it and got a working VB example of divil's C# code first time through. Thanks for the help. Don't know exactly why it wouldn't let me add a webbrowser control at design time before... but it does now flawlessly.

 

Well the next step is figuring out how to adapt this to capturing a click event. I just need to know if something has been clicked and if so then what has been clicked. It would be as simple as setting up a case select then for the items I want it to handle.

 

Any ideas how this can be done?

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Posted

Found the answer on how to do this. For anyone else that wants to know how to make their own event handler for a click event on a webbrowser control check out this tutorial:

 

http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=561

 

Just add your code to the onclickproc method.

 

divil: as promised I will post my code shortly showing how I did this to make a VS.Net style startpage. wooHOO!!! ;-)

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Posted (edited)

Ok... I have attached a copy of my basic project so far. No fuctionality has been attached to anything other than if you click on button in the browser the program will display a messagebox telling you what button you clicked. This should be enough to show you how to intercept a onclick event from a webpage and handle it within the program.

 

I have a major question on it though. As it works now, the process of intercepting the onclick event seems to stop the browser from handling ANY events hence the added onmouseover and onmouseout event handlers I added. Is there a way that this can be fixed so that it simply recognizes an onclick event but if the control id doesn't match one in the Select Case statement then it passes control back to the browser. Also would still like the browser to handle all other events... only want it to intercept the onclick event.

 

This on the surface seems similar to subclassing in VB6 but it doesn't work quite the same. In VB6 you could return control back to the default message handler. How would you do this in this case for VB.Net?

Edited by divil

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

  • *Gurus*
Posted (edited)

From your own comments:

 

   ' Notice that the signature of this event is different from usual, as it
   ' is expected to return a Boolean - if false the default effect associated
   ' with the event (for example, jumping to another page if the click is on
   ' an hyperlink) is canceled.

 

Surely that means if you Return True at the end of that function the browser will do the default action for these things?

 

I had to remove your attachment because it contained executables, can you post it again without?

Edited by divil

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted (edited)

D'OH!!!!!

 

That is what I get for not sleeping in 24 hours. LOL

Thanks divil... once again you have been a big help. I have noticed though that after commenting out all code adding an event handler for the onmouseover and onmouseout the buttons still don't have the normal button effects for those event... and it doesn't show the button going down on a click. For comparison try opening the StartPage.htm in IE and notice the effects I am talking about.

 

Setting the Return to True doesn't change this. Any idea if this can be fixed? Or is it something that I am doing wrong with the browser settings?

Edited by mooman_fl

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Posted

Anyone? Still having trouble with the button-down effect not showing if using a event handler for the onclick event. Even with a return set for true. Another side-effect: right-clicking on the page no longer gets the context menu. On a side note... and it may be related... if I load the page in IE the look like XP style buttons. If I load them in the browser control they don't. Even with a manifest in the program directory. Any idea why?

 

This is the code I am using for the event handler for the onclick event:

 

Private Function onclickproc(ByVal obj As mshtml.IHTMLEventObj) As Boolean
   ' an object on the page has been clicked - you can learn more about
   ' type and position of this object by querying the obj's properties
   ' ...
   
    Select Case obj.srcElement.id
       Case "btn_StartNewProject"
           obj.srcElement.style.color = "#ff0000"
       Case "btn_StartOpenProject"
           obj.srcElement.style.color = "#ff0000"
       Case Else
           Return True
   End Select
   
    MessageBox.Show(obj.srcElement.id)
    
    Return True
    
End Function

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

  • 1 month later...
Posted

Mooman_fl,

 

Did you find out why the browser is not reflecting your events. I think it is a bug in mshtml (I am using ver 4.0)

 

I am doing similar code to yours and when I click into a textbox the cursor does not show up and neither do my keystrokes.

 

The document click event is however triggered as expected.

 

Thanks for any and al help...Vsdotnetguy

Posted
I sure didn't. Of course I am still looking for an answer myself and would appreciate any help that could be given on this issue.

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Posted (edited)

Actually I am using version 6. What version of windows do you have?

 

My mistake... I just looked it up to double check that... Microsoft.mshtml version 7.0.3300.0

Edited by mooman_fl

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

  • 2 weeks later...
Posted

capture onmouseover browser event

 

Hello, I have read this thread and i'm very interesed. But I have done several test and I can't get found my example program.

The main problem: i can't capture the text of html element when onmouseover. Let me see show the code, follow:

 

Public Class Eventos
   Private WithEvents IExplorer As SHDocVw.InternetExplorer
   Protected doc As mshtml.HTMLDocument

   Public Sub New()
       System.Console.WriteLine("Y yo estoy aqui??")
       If IExplorer Is Nothing Then
           IExplorer = New SHDocVw.InternetExplorer()
       End If
       'doc = DirectCast(IExplorer.Document, mshtml.HTMLDocument)
       'AddHandler DirectCast(doc, mshtml.HTMLDocumentEvents_Event).onmouseover, New mshtml.HTMLDocumentEvents_onmouseoverEventHandler(AddressOf onmouseover)
   End Sub

   Private Sub IExplorer_DownloadBegin() Handles IExplorer.DownloadBegin
       System.Console.WriteLine("Download Begin.")
       doc = DirectCast(IExplorer.Document, mshtml.HTMLDocument)
       'AddHandler DirectCast(doc, mshtml.HTMLDocumentEvents_Event).onmouseover, New mshtml.HTMLDocumentEvents_onmouseoverEventHandler(AddressOf coñazo)
       AddHandler DirectCast(doc, mshtml.HTMLDocumentEvents2_Event).onmouseover, AddressOf onmouseover
   End Sub

   Public Sub IExplorer_DocumentComplete(ByVal pDisp As Object, ByRef URL As Object) Handles IExplorer.DocumentComplete
       System.Console.WriteLine("Document Complete.")
   End Sub

   Public Sub dosomething()

       IExplorer.AddressBar = True
       IExplorer.StatusBar = True
       IExplorer.Visible = True
       IExplorer.Navigate("http://www.microsoft.com")
       System.Console.WriteLine("Beginnig...")
   End Sub


   Public Sub onmouseover(ByVal pEvtObj As mshtml.IHTMLEventObj)
       Dim HTML As String
       'The follow line fail!!!!!!!!!!
       HTML = doc.parentWindow.event.srcElement.innerText
       System.Console.WriteLine(HTML)
   End Sub
End Class

 

Can you say me, what im doing wrong please. THANKS SO MUCH!

Posted

SOLUTION

 

kaka, i found the solution. I'm beginner in .net and I don't feel well with it. Ea replacing the follow function in the eventos class:


...
Public Sub onmouseover(ByVal pEvtObj As mshtml.IHTMLEventObj)
       Dim HTML As String
       HTML = pEvtObj.srcElement.innerText
       System.Console.WriteLine (HTML)
       'The follow line fail!!!!!!!!!!
       'HTML = doc.parentWindow.event.srcElement.innerText

End Sub
...

 

Sorry by the intrusion. I'm sure that I'll return.

Ooooh excuse my english is verry bad. I hope you understand me.

 

See you.

Agur.

Posted
No intrusion at all. Sorry I didn't answer before but for some reason I wasn't notified that there had been a new post to this thread. I am glad you found your answer. :-)

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...