473,513 Members | 6,210 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IViewObject + SetAdvise Not Working

1 New Member
Hallo,

i am trying to get updates, when the view of a .net webbrowser control is updated. So i implemented the IViewObject of this one and tried to use setadvise, so that a function is called, when an update happened.

The interesting code is this:

Expand|Select|Wrap|Line Numbers
  1. IHTMLDocument2 htmlDocument = (IHTMLDocument2)this.webBrowser1.Document.DomDocument;
  2.  
  3. IViewObject ViewObject = htmlDocument as IViewObject;
  4.  
  5. if (ViewObject == null)
  6. {
  7. MessagheBox.Show("An error has occurred in initialization of the IViewObject of te WebBrowser.");
  8. }
  9. try
  10. {
  11. ViewObject.SetAdvise((int)DVASPECT.DVASPECT_CONTENT, 0, (IAdviseSink)this);
  12. }
  13. catch (Exception e_tmp)
  14. {
  15. MessageBox.Show(e_tmp.Message);
  16. }
  17.  

But this doesnt work. I dont get any error, it just doesnt delivers any calls, when the view of the webbrowser changed. Any

MessageBox.Show("ss"); part gets never called (look at bottom, implemention of the IAdviseSink)



Complete Example:


Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Runtime.InteropServices.ComTypes;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Security.Permissions;
  8. using System.Runtime.InteropServices;
  9. using System.Text;
  10. using System.Windows.Forms;
  11. using mshtml;
  12. namespace WindowsApplication3
  13. {
  14. [ComVisible(true), ComImport()]
  15. [GuidAttribute("0000010d-0000-0000-C000-000000000046")]
  16. [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
  17. public interface IViewObject
  18. {
  19. [return: MarshalAs(UnmanagedType.I4)]
  20. [PreserveSig]
  21. int Draw(
  22. //tagDVASPECT
  23. [MarshalAs(UnmanagedType.U4)] UInt32 dwDrawAspect,
  24. int lindex,
  25. IntPtr pvAspect,
  26. [In] IntPtr ptd,
  27. //[MarshalAs(UnmanagedType.Struct)] ref DVTARGETDEVICE ptd,
  28. IntPtr hdcTargetDev,
  29. IntPtr hdcDraw,
  30. [MarshalAs(UnmanagedType.Struct)] ref tagRECT lprcBounds,
  31. [MarshalAs(UnmanagedType.Struct)] ref tagRECT lprcWBounds,
  32. IntPtr pfnContinue,
  33. [MarshalAs(UnmanagedType.U4)] UInt32 dwContinue);
  34. void Freeze(
  35. [MarshalAs(UnmanagedType.U4)] UInt32 dwDrawAspect,
  36. int lindex,
  37. IntPtr pvAspect,
  38. out IntPtr pdwFreeze);
  39. void Unfreeze(
  40. [MarshalAs(UnmanagedType.U4)] int dwFreeze);
  41. void SetAdvise
  42. ([MarshalAs(UnmanagedType.U4)] int aspects,
  43. [MarshalAs(UnmanagedType.U4)] int advf,
  44. [MarshalAs(UnmanagedType.Interface)] IAdviseSink pAdvSink);
  45. void GetAdvise(
  46. IntPtr paspects,
  47. IntPtr advf,
  48. [Out, MarshalAs(UnmanagedType.Interface)] out IAdviseSink pAdvSink);
  49. }
  50.  
  51.  
  52. public class Form1 : Form, IAdviseSink
  53. {
  54. public Form1()
  55. {
  56. this.webBrowser1 = new System.Windows.Forms.WebBrowser();
  57. this.button1 = new System.Windows.Forms.Button();
  58. this.SuspendLayout();
  59. // 
  60. // webBrowser1
  61. // 
  62. this.webBrowser1.Location = new System.Drawing.Point(52, 96);
  63. this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
  64. this.webBrowser1.Name = "webBrowser1";
  65. this.webBrowser1.Size = new System.Drawing.Size(339, 166);
  66. this.webBrowser1.TabIndex = 0;
  67. this.webBrowser1.Url = new System.Uri("http://www.heise.de",system.UriKind.Absolute);
  68. // 
  69. // button1
  70. // 
  71.  
  72. this.button1.Location = new System.Drawing.Point(95, 45);
  73. this.button1.Name = "button1";
  74. this.button1.Size = new System.Drawing.Size(75, 23);
  75. this.button1.TabIndex = 1;
  76. this.button1.Text = "button1";
  77. this.button1.UseVisualStyleBackColor = true;
  78. this.button1.Click += new System.EventHandler(this.button1_Click);
  79. // 
  80. // Form1
  81. // 
  82.  
  83. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  84. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  85. this.ClientSize = new System.Drawing.Size(403, 266);
  86. this.Controls.Add(this.button1);
  87. this.Controls.Add(this.webBrowser1);
  88. this.Name = "Form1";
  89. this.Text = "Form1";
  90. this.ResumeLayout(false);
  91. }
  92.  
  93. private System.Windows.Forms.WebBrowser webBrowser1;
  94. private System.Windows.Forms.Button button1;
  95. private void button1_Click(object sender, EventArgs e)
  96. {
  97. IHTMLDocument2 htmlDocument = (IHTMLDocument2)this.webBrowser1.Document.DomDocument;
  98. IViewObject ViewObject = htmlDocument as IViewObject;
  99. if (ViewObject == null)
  100. {
  101. MessageBox.Show("An error has occurred in initialization of the IViewObject of the WebBrowser.");
  102. }
  103. try
  104. {
  105. ViewObject.SetAdvise((int)DVASPECT.DVASPECT_CONTENT, 0, (IAdviseSink)this);
  106. }
  107.  
  108. catch (Exception e_tmp)
  109. {
  110. MessageBox.Show(e_tmp.Message);
  111. }
  112. }
  113.  
  114. // Implementation of the IAdviseSink
  115. public void OnDataChange(ref FORMATETC pFormat, ref STGMEDIUM pStg)
  116. {
  117. MessageBox.Show("ss");
  118. }
  119.  
  120. public void OnViewChange(int dwAspect, int index)
  121. {
  122. MessageBox.Show("ss");
  123. }
  124.  
  125. public void OnRename(IMoniker im)
  126. {
  127. MessageBox.Show("ss");
  128. }
  129.  
  130. public void OnSave()
  131. {
  132. MessageBox.Show("ss");
  133. }
  134.  
  135. public void OnClose()
  136. {
  137. MessageBox.Show("ss");
  138. }
  139.  
  140. }
  141.  
  142.  
  143.  
  144. static class Program
  145. {
  146. /// <summary>
  147. /// The main entry point for the application.
  148. /// </summary>
  149. [STAThread]
  150. static void Main()
  151. {
  152. Application.EnableVisualStyles();
  153. Application.SetCompatibleTextRenderingDefault(false);
  154. Application.Run(new Form1());
  155. }
  156. }
  157. }
  158.  
  159.  
  160.  
  161.  
Sep 25 '07 #1
0 1518

Sign in to post your reply or Sign up for a free account.

Similar topics

6
3052
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub...
5
4313
by: Eric | last post by:
Hi, How I get the interface IViewObject of a RichTextBox Control? I would like to call the Draw Method with C#. Thanks Eric
5
2792
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
5
3043
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
8
2495
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
14811
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
0
1173
by: ddd | last post by:
Can iviewobject be used in VB.net? If so how? I am basically trying to build a little application which would convert an html page into an image (bmp). I saw examples of it for C++ all over the...
9
3184
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
0
1263
by: Jasleen | last post by:
I am using Flash ocx to play the .swf file in a windowless container. Now I use IViewObject::Draw to render the contents on the HDC provided by me. I create a compatible DC passing NULL parameter....
0
7254
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.