|
You mean deprecated? DirectDraw is not deprecated and is even encapsulated in the Managed DirectX 9.0[^] SDK, which you can download and use from within C# or any other managed language.
The documented APIs in the SDK discuss how to use screen objects and to direct video. I urge you to read the SDK first.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Dave is wrong. To display things on the second monitor, there is a static class called Monitors or something that allows you to enumerate all screens. From this, you can get the co-ordinates to draw to in order to get onto the second screen.
just a sec.
The class is called Screen. This code shows a window called secondMonitor on the second screen, or hides it if there isn't one.
Screen [] screens = Screen.AllScreens;
if (screens.GetUpperBound(0) > 0)
{
Screen secondary = screens[1];
secondMonitor.Bounds = secondary.Bounds;
secondMonitor.MinimumSize = secondary.Bounds.Size;
}
else
{
secondMonitor.Visible = false;
}
There's no reason to use DirectDraw, unless you really have to. You can just as easily create a window and draw onto it.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
|
You've got a Click event, just call it wit the current mouse position.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
That won't actually click the object, however, even if it were within your application. The Click event fires in response to a click.
To simulate a click, you need to P/Invoke SendInput (this is the easiest) and send the screen coordinates for the click:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
class Click
{
static void Main(string[] args)
{
if (args.Length != 2)
Environment.Exit(1);
Point p = new Point();
p.X = int.Parse(args[0]);
p.Y = int.Parse(args[1]);
ClickAt(p);
}
[DllImport("user32.dll", SetLastError=true)]
[return: MarshalAs(UnmanagedType.U4)]
static extern int SendInput(
[MarshalAs(UnmanagedType.U4)] int nInputs,
INPUT[] pInputs,
int cbSize);
[StructLayout(LayoutKind.Explicit)]
struct INPUT
{
[FieldOffset(0), MarshalAs(UnmanagedType.U4)] public int type;
[FieldOffset(4)] public MOUSEINPUT mi;
}
const int INPUT_MOUSE = 0;
const int INPUT_KEYBOARD = 1;
const int INPUT_HARDWARE = 2;
[StructLayout(LayoutKind.Sequential)]
struct MOUSEINPUT
{
public int dx;
public int dy;
[MarshalAs(UnmanagedType.U4)] public int mouseData;
[MarshalAs(UnmanagedType.U4)] public int dwFlags;
[MarshalAs(UnmanagedType.U4)] public int time;
[MarshalAs(UnmanagedType.SysUInt)] public IntPtr dwExtraInfo;
}
const int MOUSEEVENTF_ABSOLUTE = 0x8000;
public static void ClickAt(Point p)
{
MOUSEINPUT mi = new MOUSEINPUT();
mi.dx = p.X;
mi.dy = p.Y;
mi.dwFlags = MOUSEEVENTF_ABSOLUTE;
INPUT[] inputs = new INPUT[1];
inputs[0].type = INPUT_MOUSE;
inputs[0].mi = mi;
int ret = SendInput(1, inputs, Marshal.SizeOf(typeof(INPUT)));
if (ret != 0)
throw new Win32Exception();
}
} This is just a sample I threw together quick, but be sure to read about the APIs and structs used in the example.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi. Thanks for your great reply. As this is the first time that I am using windows API in C# it would have taken me a long time to get this far without help.
When I run the code though the the sendInput method returns 1, according to msdn "the function returns the number of events that it successfully inserted into the keyboard or mouse input stream". I don't know for sure though if the click is performed. When I enter the coordinates (0,0) (which I think is the upper left corner) nothing out of the ordinary happens. Is there any way to know for sure?
again thx for your great reply
|
|
|
|
|
If the function returns 1, then 1 mouse click was queued.
As I said in my post, the coordinates are screen coordinates, and I highly doubt you have anything clickable in the absolute upper-left corner of your desktop. If you want click coordinates, call PointToScreen on the control for which you want screen coordinates, which will transform the client coordinates (like 0,0 for the upper-left corner of that control) to screen coordinates, then pass them to the sample method.
For information on P/Invoke, read Consuming Unmanaged DLL Functions[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
|
Hi, I am using Janus GridEX or Datagrid control
And am trying to bind a Hierarchical dataset to it at runtime
I am unsuccessful in both cases I have been able to see the parent table but am not able to open up to the child. With GridEX it gives me n unhandled exception that says that there is an invalid Child datasource. I have cchecked and the child table and all columns seem to be ok, would help if I could see the proper exception. And with Datagrid I cannot do anything except display the Parent. I added a relation and then tried but still only goit the parent. Here's the code I'm using. Would appreciate any help. Thanks.
PS it's a one to many relationship
dsSearchResults = Facade.SearchQuery(txtSearch.Text, cbSearchInQueryName.Checked, cbSearchInQueryText.Checked, cbSearchInQuerySummary.Checked, cbSearchInQueryDescription.Checked );
DataRelation rel = new DataRelation("QueryDatabases",dsSearchResults.Tables[0].Columns[QUERY_ID],dsSearchResults.Tables[1].Columns[QUERY_ID]);
rel.Nested = true;
dsSearchResults.Relations.Add(rel);
G3.DataSource = dsSearchResults;
G3.DataMember = "Query";
G3.DataBind();
//DataView a = new DataView(dsSearchResults.Tables[0]);
//dgSearchResults.DataSource = dsSearchResults;
//dgSearchResults.DataMember = "Query";
//dgSearchResults.DataBind();
DataGrid dgtemp1 = new DataGrid();
dgtemp.DataSource = dsSearchResults;
dgtemp.DataMember = dsSearchResults.Tables[0].TableName;
dgtemp.DataBind();
DataGrid dgtemp2 = new DataGrid();
dgtemp.DataSource = dsSearchResults;
dgtemp.DataMember = dsSearchResults.Tables[1].TableName;
dgtemp.DataBind();
|
|
|
|
|
If you're having problems with a commercial library you need to contact their support. It's very unlikely that anyone here has any expert experience with a commercial library since there are so many of them, and it's the job of the programming house to provide support.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Could any one tell me that How to get the value of hyperlink in web browser by C#.
|
|
|
|
|
You need to walk the DOM (document object model) by casting the AxWebBrowser2.Document property (or whatever the class is called, depending on how you imported it) to an IHTMLDocument3 , which is defined in the Microsoft.mshtml.dll interop assembly, or you can always import your own using VS.NET or tlbimp.exE.
Once you do that you simply walk the DOM like you would in HTML, or get the A link using it's ID (if set) like so:
IHTMLDocument3 doc = (IHTMLDocument3)axWebBrowser2.Document;
if (doc != null)
{
IHTMLAnchorElement a = doc.getElementById("myLink") as IHTMLAnchorElement;
if (a != null)
{
Console.WriteLine(a.href);
}
} Search for "IHTMLDocument" in this forum by clicking "Search comments" for additional examples of how to walk the DOM using the Internet Explorer WebBrowser control.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks Heath on your reply .
Basically I need to get the value of hyperlink on cursor like in web browser when we Hover the hyperlink, it showing hyperlink value in status bar.so the value which shows in status bar i need to get these values. please give me the solution in dotnet (C#)
|
|
|
|
|
I did give you a solution using C#, but it requires you to interop with COM. The solution gets the actual value of the A.href attribute. If you want an absolute URL, combine the IHTMLDocument2.location.href (casting AxWebBrowser2.Document to IHTMLDocument2 this time - this is just how COM interop and COM itself works) and the link value from the first solution:
IHTMLDocument2 doc2 = (IHTMLDocument2)axWebBrowser2.Document;
if (doc != null)
{
Uri url = new Uri(doc2.location.href);
url = new Uri(url, a.href);
} Now you've got an absolute URL. To be 100% correct, however, you should retrieve the IHTMLBaseElement from the <HEAD> and gets it's href attribute value - if any. This is an optional element so it may not exist; if it does exist it re-scopes URLs contained within the document to be relative to the <BASE href> value.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
...and for more information about COM interoperability to help you walk the DOM using the WebBrowser control, read Exposing COM Components to the .NET Framework[^] in the .NET Framework SDK.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thank you Heath for your prompt replies and usefull guidance...can you tell me what i should to make my browser to take the value of links when ever my mouse hovers it...because i have tried the way you have told but it is not picking the url of that link.
|
|
|
|
|
You need to handle the IHTMLDocument2.body 's onmouseover event in order to get the current element under the mouse. Copy the code snippet and see how it works in the browser. Everything JScript can do your application can do because they use the same automation server - the WebBrowser control or MSHTML (which is hosted by the WebBrowser control):
<html>
<head>
<title>Test</title>
</head>
<body onmouseover="showCurrentElement(event)">
<p>This is a paragraph of text with a <a href="http://www.microsoft.com">hyperlink</a> embedded.</p>
<p><b>Look at me - I'm bold!</b></p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<p id="currentElement"></p>
</body>
<script type="text/jscript">
function showCurrentElement(e)
{
var lbl = document.getElementById("currentElement");
if (lbl)
{
lbl.innerText = e.srcElement.tagName;
}
}
</script>
</html> You really need to read the links I gave you regarding COM interop. There's also several articles on this site about programming with the WebBrowser control, as well as on MSDN[^]. There's a lot to understand, but it's not difficult especially if you understand COM.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
you mean that i should add this code snippet in my C# program?
|
|
|
|
|
No, you should do something like the HTML - which is what I said in my previous post - and handle the IHTMLDocument2.body.onmouseover event like you would any other event. You get the srcElement (the element that fired the event) from the IHTMLEventObj .
The HTML was - again - an example of what you need to do. I've given you plenty of samples and you can find more by clicking "Search comments" to search this message board (and others, if you like) or use the search box at the top of every page to search for articles.
If you read the documentation I've linked for you all this will make a lot more sense.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thank You so much Heath....you have solved my problem.
|
|
|
|
|
Ok here goes, if i can get a program to compile and work in the windows version of mono...then is it possible for the program to run in linux and windows...if not will the code compile ok in linux then.
|
|
|
|
|
If you can get it compile under Mono using the Mono C# compiler, in theory and mostly in practice, your application will then run on both Windows and Linux. I say in theory only because, as is the case with Java, there are some caveats; certain features may work slightly differently on some different platforms.
Tech, life, family, faith: Give me a visit.
Judah Himango
|
|
|
|
|
|
Mono is another implementation of the Common Language Infrastructure (CLI), of which .NET is Microsoft's implementation. The CLI states that certain things must be implemented and Windows Forms, for example, is not one of them. So long as you classes defined in ECMA-certified base class libraries (like those assemblies of the .NET BCL having the publicKeyToken value b77a5c561934e089) it should work.
Mono and .NET have different ways of implementing Windows Forms, however. The .NET BCLs P/Invoke native Windows APIs and handle messages since they encapsulate the Windows Common Controls. Certain implementations of Mono use the QT or GTK toolkits. This is where things really different.
Also keep in mind that .NET compilers (that is, language compilers for the .NET Framework) wrap IL modules in a PE/COFF executable but Mono can handle this.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thx for info...Looks like porting my program is gonna be a learning experience.
|
|
|
|