|
You could also provide "outside" access to this ItemCollection class via a public interface (implemented by ItemCollection) which you pass back to a caller from your function
Phil Harding. myBlog [^] | mySite [^]
|
|
|
|
|
Hello,
I need to access a frame (filling inputs, reading data, etc.) in an activeX webbrowser.
ie: an html page embeds 2 frames, one on the same domain (no probs using this frame), and the other that refers a page on another domain.
The problem is that IE component doesnt allow access to a frame (read and more) that is not in the same domain as the parent window.
A friend success to access this kind of frame using Delphi, but I wonder if there is a way to do the same using C#.
Regards.
|
|
|
|
|
Are you using JavaScript/JScript or VBScript to do this in a web page? Cross-site scripting is there for a reason, and this question wouldn't have anything to do with C# or .NET, so please refer your question to the Web Development[^] forum.
C# won't simply solve your problem if you're talking about a client scenario only. An ActiveX control or embedded Windows Forms control could possibly access the other frame through a few methods, but if you try to use the MSHTML DOM (document object model) to do this then no language will help since those calls - the very same calls that scripts automate - will be blocked by the implementation, which is implemented by mshtml.dll (the MSHTML DOM).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am not using any scripts in the web page. I am just trying to fill some form inputs using MSHTML ActiveX, but the MSHTML component doesnt let me access a frame outside the domain of the parent web page.
So I'm looking for another way to access the frames objects. Any ideas ?
|
|
|
|
|
Could you please provide more information about what you're doing? Are you interoperating with the WebBrowser control in a Windows Forms application? Please be specific.
As I mentioned in my previous post, if you use the methods of the MSHTML DOM objects - no matter if done through JScript, VBScript, C#, C++, etc. - they will block against cross-site scripting. This is intentional and is implemented in the MSHTML DOM itself, so there's no way around it using the MSHTML DOM methods.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
At this moment using MSHTML works perfectly (in the same domain), I know that cross-frame scripting is restricted using MSHTML.
I am using the ActiveX axWebBrowser object to embed a webbrowser in my app. But in some case, web pages embeds frame out of the parent domain. So I am stuck if I want (for exemple) to login on external website, due to cross-frame scripting restrictions.
So I wonder if there is a way to do this in C#... My friend that did the thing in Delphi seems to get the main webbrowser document id in an OleContainer then enumerate objects in this container, after he cast back the OleObject to a IHTMLWindow and access the frame without any restrictions.
Here is the link where he find the solution in Delphi (unfortunaly he doesnt know what he does, but use the code as it):
http://www.swissdelphicenter.ch/torry/showcode.php?id=2054
|
|
|
|
|
Okay, not that I know what you're trying to do and how you're using the WebBrowser control it makes more sense.
You can do the same thing, but those interfaces your friends is using aren't defined in the .NET Framework class libraries. You have to either create an interop assembly, or write your own interfaces with the right method signatures and GUIDs (using the GuidAttribute ) and the ComImportAttribute that match up to the native interfaces like IOleObject .
This can be a daunting task, however. First, please read Exposing COM Components to the .NET Framework[^]. It's imperative that you understand COM interoperability in .NET. You'll also need to these interfaces in managed code so that the CLR will marshal calls from your managed code to native code (the COM implementation).
Fortunately, there's a relatively easy way since defining these interfaces by hand would take a long time and require quite a bit of experience with marshaling the various data structures and interfaces required.
Make an IDL file that forward-declares the interfaces you need, run the IDL file through midl.exe, then run the resulting typelib (.tlb file) through tlbimp.exe. midl.exe is the Microsoft IDL compiler that ships with the Platform SDK and Visual Studio .NET, and tlbimp.exe is the Type Library Importer that ships with the .NET Framework SDK, which is installed by default with Visual Studio .NET as well.
For an example of how this is done, read Using MSHTML Advanced Hosting Interfaces[^] where Nikhil uses the technique above to creating an interop assembly (that contains interop interfaces and enumerations and structure required to call them) for the MSHTML and WebBrowser hosting interfaces.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Okay
Thx for pointing me to some nice things to read.
Regards.
|
|
|
|
|
Can you help me about project in the image processing
(how can you discovery disease in cell boold employmend computer )
image reading next recognize on disease.
plz help me......
|
|
|
|
|
|
I need to center a text in the promt how can I do that??
|
|
|
|
|
What prompt? The console prompt? Please be specific.
For now I'll assume you're referring to the console window, since your last question was about the console text colors. You can P/Invoke GetConsoleScreenBufferInfo as I did in my previous example[^], but change the 1st, 2nd, and 5th fields to COORD and define a COORD structure like so:
[StructLayout(LayoutKind.Sequential)]
struct COORD
{
public short x;
public short y;
} After calling GetConsoleScreenBufferInfo in the same manner I did previously, you can get csbi.dwSize.x for the width and pad your string with spaces accordingly to center it.
Note that the Compact Framework (.NET CF) doesn't marshal nested structures, so if you have to support .NET CF you can you can leave the CONSOLE_SCREEN_BUFFER_INFO struct as a defined it and add a method like so to get a Size with the necessary coordinates (don't forget to add System.Drawing to your using clauses to use Size without fully-qualifying it):
[CLSCompliant(false)]
static Size GetSize(uint coord)
{
return new Size(
(int)(coord & 0xffff0000 >> 16),
(int)(coord & 0x0000ffff));
} After resetting the console text attributes in my previous example, I extended my source to add the following at the end of Main :
Size s = GetSize(csbi.dwSize);
string text = "This is a centered text message.";
int lpad = (s.Width - text.Length) / 2;
text = text.PadLeft(lpad + text.Length);
Console.WriteLine(text);
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Well its a C++ MFC program
|
|
|
|
|
Why are you asking in the C# forum, then? Please use the appropriately forums.
Since GetConsoleScreenBufferInfo is a native function, you can call it without P/Invoking, making it even easier. Read the documentation[^] for GetConsoleScreenBufferInfo in the MSDN Library.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Can I access a cookie set by a browser through a winform?
|
|
|
|
|
You can P/Invoke InternetGetCookie like in the following example:
using System;
using System.Runtime.InteropServices;
class CookieSample
{
[DllImport("wininet.dll", CharSet=CharSet.Auto, SetLastError=true)]
static extern bool InternetGetCookie(string lpszUrlName,
string lpszCookieName, [Out] string lpszCookieData,
out uint lpdwSize);
const int ERROR_SUCCESS = 0;
const int ERROR_INSUFFICIENT_BUFFER = 122;
const int ERROR_NO_MORE_ITEMS = 259;
static void Main(string[] args)
{
if (args.Length != 1)
{
Console.Error.WriteLine("Error: please specify a URL.");
Environment.Exit(1);
}
try
{
string data = GetCookie(args[0]);
if (data != null)
Console.WriteLine("Cookie data: " + data);
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
Environment.Exit(1);
}
}
static string GetCookie(string url)
{
int error;
uint dwSize = 0;
if (InternetGetCookie(url, null, null, out dwSize))
{
error = Marshal.GetLastWin32Error();
if (error == ERROR_SUCCESS)
{
string data = new string('\0', (int)dwSize);
if (InternetGetCookie(url, null, data, out dwSize))
{
return data;
}
}
}
error = Marshal.GetLastWin32Error();
if (error == ERROR_NO_MORE_ITEMS)
{
Console.Error.WriteLine("Error: no cookie for URL or parents.");
return null;
}
throw new Exception("Error: unexpected failure.");
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Brilliant! Thanks alot.
Do you know how to get the cookies from other browsers (firefox, opera) as this only seems to work with IE.
|
|
|
|
|
You should read the documentation for those applications and explore how they store and allow access to cookies. InternetGetCookie is a WinInet function, an API on which parts of Internet Explorer are built.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello,
How can I use diffrent color on the text or background in a consol program?. And is it possible to show a *.bmp picture?
|
|
|
|
|
In .NET 2.0 the Console class will define new methods for setting text color, but for now you'd have to P/Invoke SetConsoleTextAttribute , as well as GetConsoleScreenBufferInfo .
using System;
using System.Runtime.InteropServices;
class ConsoleSample
{
[DllImport("kernel32.dll")]
static extern bool SetConsoleTextAttribute(IntPtr hConsoleOutput,
TextAttributes wAttributes);
[Flags]
enum TextAttributes : short
{
None = 0,
FOREGROUND_BLUE = 1,
FOREGROUND_GREEN = 2,
FOREGROUND_RED = 4,
FOREGROUND_INTENSITY = 8,
BACKGROUND_BLUE = 16,
BACKGROUND_GREEN = 32,
BACKGROUND_RED = 64,
BACKGROUND_INTENSITY = 128
}
[DllImport("kernel32.dll")]
static extern bool GetConsoleScreenBufferInfo(IntPtr hConsoleOutput,
out CONSOLE_SCREEN_BUFFER_INFO csbi);
struct CONSOLE_SCREEN_BUFFER_INFO
{
public uint dwSize;
public uint dwCursorPosition;
public TextAttributes wAttributes;
public ulong srWindow;
public uint dwMaximumWindowSize;
}
[DllImport("kernel32.dll")]
static extern IntPtr GetStdHandle(StdHandle nStdHandle);
enum StdHandle : uint
{
STD_INPUT_HANDLE = unchecked((uint)-10),
STD_OUTPUT_HANDLE = unchecked((uint)-11),
STD_ERROR_HANDLE = unchecked((uint)-12)
}
static void Main()
{
IntPtr hStdErr = GetStdHandle(StdHandle.STD_ERROR_HANDLE);
TextAttributes attrs = TextAttributes.None;
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (!GetConsoleScreenBufferInfo(hStdErr, out csbi))
{
Console.Error.WriteLine("Error: could not get current colors.");
Environment.Exit(1);
}
else
attrs = csbi.wAttributes;
if (!SetConsoleTextAttribute(hStdErr,
TextAttributes.FOREGROUND_RED | TextAttributes.FOREGROUND_INTENSITY))
{
Console.Error.WriteLine("Error: could not set current colors.");
Environment.Exit(1);
}
Console.Error.WriteLine("Sample error: this is a test error in red.");
SetConsoleTextAttribute(hStdErr, attrs);
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Well its a C++, MFC program so this dont work.
|
|
|
|
|
Why are you asking in the C# forum, then? Please use the appropriately forums.
Since SetConsoleTextAttribute is a native function, you can call it without P/Invoking, making it even easier. Read the documentation[^] for SetConsoleTextAttribute in the MSDN Library.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi, I just started playing around with SDL.Net some hours ago and everything works perfectly when I use the SDL.Net window functions instead of a WinForm.
The problem is that I want to use the input functions of SDL.Net with my application, but my application will use D3D/OGL(not implented yet) for rendering, so I'll need a WinForm.
So is it possible to use SDL.Net on a WinForm?
|
|
|
|
|
Yes it should. Windows Forms are classes that encapsulate the native Window APIs. The TextBox , for example, encapsulates the Edit common control; the ListView the List-view common control; etc.
Every class that extends Control is, in fact, tied to an HWND . That's what the Control.Handle property is - an IntPtr (processor-specific bit length integer). The Control.WndProc method is the callback function to handle window messages. Many Window API functions are encapsulated by Windows Forms (even setting the Control.Text property in the Windows Forms BCL ends up sending the WM_SETTEXT windows message most often), but some times you need to P/Invoke other functions like FindWindow or something.
Since your question is rather open-ended, I recommend you read about[^] the Control class members and about P/Invoke[^].
Please search this forum using "Search comments" above to search for function names to find examples, or visit http://pinvoke.net[^] for many, many function signatures.
If you have further questions, please be specific in your request.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Customer Product-lifecycle Experience
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I'm not sure you understood my question correctly, but thanks for answering anyway.
SDL.Net is a cross-platform API which provides functionality as window creation, 2D rendering and input handling. The problem is that to become cross-platform it needs to hide the WinForm away from the user of SDL.Net, otherwise it wouldn't run on Mono and such projects(if there are other).
So without taking a WinForm (or control) SDL creates it's own window, if you do this AND also call the standard "InitializeComponents" two windows will be created. You could tell SDL not to create a window, but then it wouldn't be possible to keep track of mouse position and check if mouse/keyboard keys was pressed.
So what I want to do is to create ONE window and have a "System.Windows.Forms.Form" variable after that, with this window I want to check if any keys have been pressed and if the mouse have moved.
Hope I made it clear this time.
|
|
|
|
|