|
BobJanova wrote: I think Dispatcher.RequiresInvoke or something like that will be better.
They changed the name for WPF:
Dispatcher.CheckAccess() (Returns true on the GUI thread, false otherwise)
Dispatcher.VerifyAccess() (Throws an exception if not on the GUI thread)
Just FYI.
|
|
|
|
|
Got it....
public void getData()
{
GameData g = null;
do
{
try
{
FileStream fs = new FileStream(@"C:\Users\IsH\Desktop\Podi wadak\WpfApplication1\GameData\GameData.xml", FileMode.Open);
XmlSerializer xs = new XmlSerializer(typeof(GameData));
g = (GameData)xs.Deserialize(fs);
fs.Close();
Thread.Sleep(2000);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
} while (g.Turn != false);
if (this.Dispatcher.CheckAccess())
{
callMethod m = new callMethod(getData);
this.Dispatcher.Invoke(m);
}
else
{
Action job = delegate
{
textBox2.Text = "" + g.PlayerValue;
button1.IsEnabled = true;
};
textBox2.Dispatcher.Invoke(job);
}
}
*********************** thanks everybody for your help........
|
|
|
|
|
Thanks ... I'll try to remember (though I'll probably fail, as I'm not using WPF in actual code).
|
|
|
|
|
hi i am using window 7, and vs2008.net c#
i want to capture my screen image and identify words from a certain section.
is this possible? anyidea how its implemented? i am trying to make a school project. thanks
|
|
|
|
|
One way to achieve this would be to use OCR to read the text in from that position in the image. It's not going to be easy - OCR is not a trivial task. Andrew Kirillov is probably the best place to start to get an idea of how complex this is. Try his article here[^] for more information.
|
|
|
|
|
Not a real "solution", just a theoretical long-shot. How are you gonna clip the area that you need to capture under the cursor?
No, don't asnwer - once you're there, you need to realize that you'll have to run this CPU-intensive task on each mouse-move.
It would have been more realistic to answer that it's not possible, even though one could think of a dozen workarounds. It would have even been more rewarding if you explained the difference between a control and a picture, and would have explained that one (with a bit of work) can fetch it's text[^] if it ain't a drawing - asking whether his project would be limited by this.
Bastard Programmer from Hell
|
|
|
|
|
Eddy Vluggen wrote: No, don't asnwer - once you're there, you need to realize that you'll have to
run this CPU-intensive task on each mouse-move.
Actually, sod that, I will answer - seeing you thought it necessary to one vote. Read what he actually asked, not what you took it to mean. At no stage did he mention basing the read on mouse position. You have overcomplicated the problem, and haven't actually answered what he asked.
This is what he really asked:
"hi i am using window 7, and vs2008.net c#
i want to capture my screen image and identify words from a certain section.
is this possible? anyidea how its implemented? i am trying to make a school project. thanks"
Now, where does that say anything about mouse position? So, my answer still stands.
|
|
|
|
|
Pete O'Hanlon wrote: Actually, sod that, I will answer - seeing you thought it necessary to one vote. Read what he actually asked, not what you took it to mean. At no stage did he mention basing the read on mouse position. You have overcomplicated the problem, and haven't actually answered what he asked.
You're right, I interpreted his question and jumped to a conclusion. He doesn't say anything about capturing the text under the mouse-cursor.
And yes, I strongly disagreed with someone whose answers are usually valuable - hence the one. I can see my mistake and will rectify it after posting this reasoning. Next time, I'll make it a two if I simply disagree. 1's imply a lot of crap, which it certainly is not.
Pete O'Hanlon wrote: Now, where does that say anything about mouse position? So, my answer still stands.
It indeed does not say that.
Bastard Programmer from Hell
|
|
|
|
|
Don't worry about the one vote. You had me doubting my memory though, which at my age, I can't afford.
|
|
|
|
|
Pete O'Hanlon wrote: Don't worry about the one vote.
Cool
Just noticed that one can only flag it as a good/bad answer. A bad answer translates to a one-vote. I'm off to the suggestions-forum; it'd be nice to have a "hold on" or "say what?" indicator.
Pete O'Hanlon wrote: You had me doubting my memory though, which at my age, I can't afford.
You already forgotten that kids forget things too? You were more alert than I was when answering the TS.
Bastard Programmer from Hell
|
|
|
|
|
neodeaths wrote: is this possible?
Only in theory, as we have yet to find a CPU that can do OCR for different fonts at high speed.
In pratice, there are controls that can hold text, and controls that don't hold the text but who are simply displaying drawn pixels.
neodeaths wrote: i am trying to make a school project.
Too complicated for a school-project. First, it's not always possible to read the "word" under the cursor, as it might not be saved in memory as a text; as said, it might have been drawn. Although it's possible to have the computer guess what words there are in the picture, it's slow and error-prone.
Bastard Programmer from Hell
|
|
|
|
|
its my suggestion to my teacher for my school project as we are supposs to think of an application to do, i have not talk to him about it yet, just want to see how complex and what i should know before i decide what to do.
from what i have read about ocr its pretty deep, and will probably have a very long time complexity to run.
still considering though
|
|
|
|
|
neodeaths wrote: its my suggestion to my teacher for my school project as we are supposs to think of an application to do
What kind of application where you planning? Perhaps there's another way to get the required input, like the ClipBoard ?
neodeaths wrote: just want to see how complex and what i should know before i decide what to do.
A good project would be any project that has been done already. Ask the students of the previous year; at least you'll now it's viable within the given time.
neodeaths wrote: from what i have read about ocr its pretty deep, and will probably have a very long time complexity to run.
With some people (like me) doing a lot of travelling by mouse, with the cursor hitting a lot of words when I'm working.
Bastard Programmer from Hell
|
|
|
|
|
While you are deliberating, you should consider whether Eddie has actually answered the question you asked. In my opinion, he's interpreted your question - you need to decide whether his interpretation is actually what you were asking.
|
|
|
|
|
hi i am using window 7, and vs2008.net c#
to create a simple
to use my mouse to click a certain area of my desktop when like
every 12pm click on the 50,50 of my screen
is this possible? if so please give advice on the website and class file i should check out. thanks
|
|
|
|
|
This StackOverflow question[^] has the answer to your question.
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
public class Form1 : Form
{
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
public Form1()
{
}
public void DoMouseClick()
{
int X = Cursor.Position.X;
int Y = Cursor.Position.Y;
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
}
}
0100000101101110011001000111001011101001
|
|
|
|
|
In order to control a PLC with a "complex data structure" the PLC class expects a structure that is unmanaged.
This structure runs fine:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class PinStructureQuality
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
public int[] iPinValues = new int[24];
public PinStructureQuality()
{
iPinValues = new int[24];
}
}
The problem I have is that I don't know at the time this Class is constructed whether I have 10, 24 or any other number of pins. I would like to read this from a settings file or an XML file containing a parameter telling what the size the array is.
The line
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
causes the problem, since the value 24 must be known in front.
Does anybody have an idea on how to solve this?
|
|
|
|
|
What's the C declaration? I suspect you want to marshal as a pointer not as a fixed size array within the structure.
|
|
|
|
|
the structure is directly used in the API provided with the PLC. This is the declaration of the wrapper:
public void WriteAny(int variableHandle, object value);
and my call to it is:
public void SetAllLow()
{
for (int i = 0; i < iNrIO; i++)
_PinStructureQuality.iPinValues[i] = (int)(65535);
try
{
if (e._ErrorCode == 0)
adsClient.WriteAny(hcomplexStruct, _PinStructureQuality);
}
catch
{
e._ErrorCode = 1;
e._ErrorMessage = "Could not write pinning data to PLC";
ErrorEvent(this, e);
e._ErrorCode = 0;
e._ErrorMessage = "";
}
}
The reason I want to use this WriteAny call is that it allows me to sent also strings and other types in the same structure.
|
|
|
|
|
Member 7889751 wrote: I don't know at the time this Class is constructed whether I have 10, 24 or any
other number of pins. I would like to read this from a settings file or an XML
file containing a parameter telling what the size the array is.
Why does the second preclude the first?
|
|
|
|
|
The easiest way to deal with variable length arrays with P/Invoke is to create your array as a normal .NET array where variable length is no issue.
When you need to pass it you can use GCHandle[^] to pin the data and pass the GCHandle's pointer. Make sure you free the GHHandle after you are done with it! This assumes the native code can somehow work out the length of the data being passed - if it attempts to read outside of the allocated memory, strange things will happen
|
|
|
|
|
Hi Experts
can u please guide me how to download a file which is in Network location( \\10.101.....)where we pass credentials OF particular server and downloading a file from that server to local Machine in asp.net
Regards
venu
|
|
|
|
|
On the local network? You can just use File.Open etc (any of the normal ways to read a file from System.IO), if you have permissions to read it. Remember that ASP.net runs as its own user, though, so setting up the network permissions might be tricky.
|
|
|
|
|
ya i dont have permissions to read it but i have a user name and password who has the permission to read so i have to pass this parameters in the code and to read the file
|
|
|
|
|
Getting network resources under a different user name is (on Windows anyway) pretty tricky. You'd probably do better asking your network admin for read permissions on that file.
|
|
|
|