|
It's because the document object must be initialized first. This issue has been under scrutiny the last few days in this forum, and the answer is to call a method from an interface queried from the doc. It's IPersistStreamInit. And the method is InitNew(). Look up this forum with either of these keywords.
|
|
|
|
|
Rod,
Okay, I followed the discussion threads and got the document write working -- or at least that is how it appeared. I got the page displayed that I had passed via innerHTML.
However -- the previous discussion is related to acquiring / altering info on a browser page that had been navigated to. I am trying to have the browser show a functional page that was written to it as a string. A REALLY LONG string, but a string none the less.
I am speculating that since I am populating InnerHTML, it really is not being set up as a proper page within the document object. The string contains a full HTML document and it has script problems when I try to execute the script inside this 'page' since the browser indicates that all it contains is "about:blank"...even after I have updated the browser document object.
So this approach helped me create a visual, but it was only a painting of a "car" instead of a running, moving "car". I need to do a write to the document object to create a full HTML page that is executable in the browser as if it had navigated to a site. So using IPersistStreamInit does not really help me since it does not expose a doc.write method that supports a string as input, and updating doc.body.innerhtml does not create a functional webpage with scripts.
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
quick facts :
- if you want the web browser to run in full extent, you need two main dlls : shdocvw.dll (IWebBrowser) and mshtml.dll (IHTMLDocument). By full extent, I mean that some of the Internet Explorer features are not available if only one of the two dlls are loaded. For instance, if you only load IHTMLDocument, then you can't navigate a url. At least you can't without a few tricks which, in the end, indirectly load shdocvw.dll behind the wheel.
- if you only load shdocvw.dll, then you have all Navigate(url) features, but you don't have access to the underlying dom.
- conversedly, if you only load mshtml.dll, you'll be able to build and traverse a dom, but won't be able to navigate a url, or even the web page represented by the dom.
- attaching one dll to the other is done by implicit or explicit query interfaces, and often involve IPersist**** interfaces.
Hope this clarifies things a bit.
|
|
|
|
|
To quote my dear mum -- it is clear as mud.
This is in an application where I am hooking IDocHostUIHandler and as such I have both DLL's loaded.
Now what is frustrating to me is that this article that WORKED before (the one I cannot recreate the search that found it earlier) did not use the IPersist*** interface to accomplish the task. But the nominclature required to create a working object within the browser is lost. In the example I had found earlier and cannot find now the example was explicitely to have a document be written to the browser as a string. And....in that article, after getting the document object created, he just did document.write(stringValue); The resulting page that was displayed in the browser control contained the display portions as expected AND the browser View Source contained ALL of the HTML that made up my string-based web page.
Deploying the IPersist*** approach displayed the page but when I View Source the browser knows nothing of my document -- only the about:blank document. And I DO have both DLL's in my program.
I hate working with the browser. It shouldn't have to be THIS hard.
Michael
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
theRealCondor wrote:
Deploying the IPersist*** approach displayed the page but when I View Source the browser knows nothing of my document -- only the about:blank document. And I DO have both DLL's in my program.
I have been explaining the cause of this effect in my previous post.
theRealCondor wrote:
document.write(stringValue);
That's javascript syntax. And that's a javascript context, where dlls mentioned earlier are loaded and appropriately attached for us.
None of this context is ready by default when you are custmizing the usage of the browser, especially with .NET languages which, as a matter of fact, only add another layer of code on top of it.
You need specific marshaling to do this using C# since the tlbimp importer generated a f***ed up signature for the write method.
|
|
|
|
|
.S.Rod. wrote:
document.write(stringValue);
That's javascript syntax. And that's a javascript context, where dlls mentioned earlier are loaded and appropriately attached for us.
You misunderstood my post. The example I found that actually worked was SOMETHING like this:
(somedoctype) document = (someInterfaceType) mybrowsercontrol.Document;
document.write(myString);
I vaguely recall that the document type was something like HTMLDocument2. And the working example was only 2 or three lines of code AND I did not remember using IPersist... in getting it implemented.
So anyway. I read your post and I don't understand any of it. Your suggestion just does not work the way I need it to work. Thanks anyway.
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
theRealCondor wrote:
(somedoctype) document = (someInterfaceType) mybrowsercontrol.Document;
document.write(myString);
This method call cannot compile with the C# compiler. The C# signature awaits a String[].
|
|
|
|
|
.S.Rod. --
I got this solved, finally. To write a string to the browser control all I have to do is this:
StringBuilder msg = new StringBuilder();
msg.Append("<HTML>\n\r<BODY>\n\r");
...
msg.Append("</BODY>\n\r<\HTML>");
IHTMLDocument2 document = this.WebBrowser.Document as IHTMLDocument2;
document.write(msg.ToString());
Now the browser control thinks it is still working with the about:blank document, so when I had scripting errors they were reported as occuring inside of about:blank. However when I view source I see my constructed string HTML source. When I click an object, the script is seen and executed.
That is it. No IPersist... was necessary. I just needed to find the syntax for deploying the IHTMLDocument2 interface.
Condor
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
Hello
We have a smal game that we whant to put some music in.
We have manage to add wave files but the size become to big, so now we whant to use mp3 or somthing like that.
Could i use Windows media player ore do i have to decrompress the mp3 my self(own code)?
We have tryed to add media player to ower form but it says that its not singel threaded.
Hope you have a way to make this happen
Best regards
Jimmy
|
|
|
|
|
Try following,
[DllImport("winmm.dll", CharSet=CharSet.Ansi)]
private static extern bool PlaySound(IntPtr szFileName, IntPtr hmod, int fdwSound);
use this method where you want to play mp3 files.
-Paresh
|
|
|
|
|
How?!?
May you show me how to use this function, what arguments to pass?
What's the IntPtr? which numbers do what (fdwSound)?
|
|
|
|
|
if you are trying to run the audio file.
herez the sample for you.
(the sample for playing the audio files
without any GUI)
u might consider running it in threads if u need
check the sample.
using
winmm.dll
[DllImport("winmm.dll")]
public static extern long PlaySound(String lpszName, long hModule, long dwFlags);
-----------------check the following code------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.IO;
namespace WinMediaPlayer
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
[DllImport("winmm.dll")]
public static extern long PlaySound(String lpszName, long hModule, long dwFlags);
private System.Windows.Forms.Button buttonPlay;
private System.Windows.Forms.Label labelFile;
private System.Windows.Forms.TextBox textBoxAudioFile;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.buttonPlay = new System.Windows.Forms.Button();
this.labelFile = new System.Windows.Forms.Label();
this.textBoxAudioFile = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// buttonPlay
//
this.buttonPlay.Location = new System.Drawing.Point(128, 80);
this.buttonPlay.Name = "buttonPlay";
this.buttonPlay.Size = new System.Drawing.Size(96, 32);
this.buttonPlay.TabIndex = 0;
this.buttonPlay.Text = "Play";
this.buttonPlay.Click += new System.EventHandler(this.buttonPlay_Click);
//
// labelFile
//
this.labelFile.Location = new System.Drawing.Point(8, 24);
this.labelFile.Name = "labelFile";
this.labelFile.Size = new System.Drawing.Size(80, 24);
this.labelFile.TabIndex = 1;
this.labelFile.Text = "File To Play";
//
// textBoxAudioFile
//
this.textBoxAudioFile.Location = new System.Drawing.Point(112, 24);
this.textBoxAudioFile.Name = "textBoxAudioFile";
this.textBoxAudioFile.Size = new System.Drawing.Size(328, 20);
this.textBoxAudioFile.TabIndex = 2;
this.textBoxAudioFile.Text = "Path to Audio File";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(424, 141);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBoxAudioFile,
this.labelFile,
this.buttonPlay});
this.Name = "Form1";
this.Text = "Windows Media Player ";
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void buttonPlay_Click(object sender, System.EventArgs e)
{
// Codes used
// where Asynchronously = 0x0001,
// where NoWait = 0x00002000,
// where Filename = 0x00020000,
if(File.Exists(textBoxAudioFile.Text))
{
PlaySound(textBoxAudioFile.Text, 0,0x0001|0x00020000|0x00002000);
}
}
}
}
----------------------------------------------------
hope this helps you
-Paresh;);););P;P;P
|
|
|
|
|
|
|
leppie wrote:
Try nBASS (written by me)
Hey Leppie, one more project from you!!
Yesterday only I ran across your other project MyRC. *thumbs up*
Don't and drive.
|
|
|
|
|
Kant wrote:
Yesterday only I ran across your other project MyRC. *thumbs up*
That was my first program I started when doing C#. Was nice to play around with, but I lost all my database so I stopped. If I had to look back at the code, it would probably look horrible to me now
My Plugin automation article is based on that Sharkbite .NET IRC library. To make a plugin assembly that can be unloaded without killing the main program (you know the bad thing of .NET) and hence the connection.
BTW how are you liking C#? I see you more and more in this forum
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
hey leppie...i just got a chance now to take a look at nbass.....amazing...i really really like it. Im going to recommend..using it in school...if we ever need the use of sound for our project....Good Work...More amazing code from south africa lol..
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
I'm finding problems while transferring large files between the Client and Server. I'm using TCPListener and TCPClient Sockets for communications.
Need help urgently!
BETTER TO BURN OUT THAN TO FADE AWAY - Anonymous
|
|
|
|
|
What kind of problems?
If it's performance, you might experiment with different buffer options:
* Increasing the size of the TcpClient buffers -- SendBufferSize and ReceiveBufferSize properties.
* Wrapping the NetworkStream with a BufferedStream.
|
|
|
|
|
Hello,
I made simple applicatino in VC#.
On my computer work good (Win2000), but in the
other computers the program show message (cannot find mscoree.dll...).
I read somewhere that you must install Microsoft .NET framework, but for me is this
not right solution for small application with two forms.
for exaple: if I want to make Installation program (INNO SETUP), which files
I must add to my Exe file that program work properly on computer with Win98, ME, 2000, 95... withowt Microsoft .NET framework.
Thank you again for answers
Anze
|
|
|
|
|
flyingv wrote:
I must add to my Exe file that program work properly on computer with Win98, ME, 2000, 95... withowt Microsoft .NET framework
Any .NET program requires the .NET run-time to work. The best you can do if you don't want to embed the 20MB+ dotnetfx.exe redistribuable in your setup is to put a link in your readme.txt or documentation.
|
|
|
|
|
How do I get the handle for a child window from a MDI in C#.Net?
Getting the handle to the Mainframe window is quite easy, but I'm having some problems retrieving the handle from one of many child windows? So, if I have several child windows open in a parent window, how do I get the handle of only one child window?
Any help will be appreciated. Thanks!
|
|
|
|
|
the Controls collection brings access to children. Controls.item[i].Handle is the window handle of the ith children.
|
|
|
|
|
I had code where I needed to iterate through my children looking for replicated data being displayed between the child displays.
public void mdiParent_childLoadComplete(object sender, LoadCompleteEventArgs senderArgs)
{
System.Windows.Forms.Form[] formArray = this.MdiChildren;
int color = formArray.Length - 1;
if (color < 1)
return;
editView newForm = new editView();
foreach (editView children in formArray)
{
if (children.Text == senderArgs.delegateIdentifier)
{
newForm = children;
break;
}
}
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
in C++ i would have something like this:
#define DIALUP 0
#define FTP 1
..
if (m_nAccessMode == FTP)
.. this was really useful for keeping track of options and such, like if im storing a combo box of Monthly ,Quarterly ,Annually i dont wanna just compare strings when im doing an if statement, but rather use some sort of defined key so that i never get my stuff mixed up..
i have looked at the #define statement in C# and it only lets me define like
#define FTP it doesnt let me assign a value to it in the define statement, so i really dont even see its purpose .. can someone set me straight plz?
still a newb.. cut me some slack :P
-dz
|
|
|
|