|
veronika89 wrote: need programm on C# "Maltus' model"!!!
Well, good luck then. Obviously you'll be wanting to read up on this via Google. We aren't going to write your software for you. BTW - choose a better title; we know it's C#.
|
|
|
|
|
1. Please use a descriptive subject line. Given this is the C# forum, every post could carry the subject of C#.
2. We don't do homework here. On the other hand, if you are stuck at a particular place, we'd be happy to help.
3. Please read the guidelines above.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
Please don't tell me that even the model name is wrong... [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
It's not that nobody wants to help you, but you made a wrong post.
- Correct forum --> this was good
- Correct language --> Wrong, please create full sentences and mind spelling errors. You're american, people would think you can write in your own language.
- Give a good, (short), clear description in the subject.
- Tell us what you did yourself to find a solution to the problem
- it proves your not lazy and awaiting an answer while you're watching the television.
- it prevents people from going down a line you already searched.
- It doesn't matter if it's homework, real work or just for fun, just show you did some research yourself
- people will guide you and give a direction, they will not do the task for you.
- some people take the time to actually do research for you, take time to thank them for their effort.
hope this helps.
|
|
|
|
|
Guys,
Check out the following
private void btn_disable_Click(object sender, EventArgs e) {
IntPtr handle = FindWindow(null, "windowtitle");
Form.FromHandle(handle);
IntPtr chandle = GetDlgItem(handle, Convert.ToInt32(txtbox_controlid.Text));
Control.FromHandle(chandle);
string text = "";
GetWindowText(handle, text, 10);
MessageBox.Show(text);
}
[DllImport(@"user32.dll", EntryPoint="GetDlgItem")]
public static extern IntPtr GetDlgItem(IntPtr DialogHandle, int ControlId);
[DllImport(@"user32.dll", EntryPoint="FindWindow")]
public static extern IntPtr FindWindow(string ClassName, string DialogTitle);
[DllImport(@"user32.dll", EntryPoint="GetWindowText")]
public static extern int GetWindowText(IntPtr Hwnd, string text, int length);
both handle as chandle give back an IntPtr different from zero. Yet my MessageBox will stay empty.
If I try to create a Control (Control.FromHandle(chandle); ) I get back a null value.
I did find an article that uses SendMessage to manipulate controls, but I was wondering if I couldn't plug in into the control via a reference or something. (like TextBox.FromHandle(found_handle)). [EDIT]Goal is to get hold of the properties and methods of the control like backColor, ForeColor, GetWindowtext, SetWindowText, Enable, Visible, ...[/EDIT]
Am I on the wrong path here or did I just miss a detail?
thanks !!
|
|
|
|
|
Control.FromHandle(HWND) should return a reference to a Control. For the string to function properly, pass in a StringBuilder.
private void Test() {
IntPtr handle = FindWindow(null, "Form1");
Control c = Control.FromHandle(handle);
StringBuilder text = new StringBuilder();
int x = GetWindowText(handle, text, 10);
MessageBox.Show(x.ToString() + text.ToString() + c.Text);
}
[DllImport(@"user32.dll", EntryPoint = "GetDlgItem")]
public static extern IntPtr GetDlgItem(IntPtr DialogHandle, int ControlId);
[DllImport(@"user32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(string ClassName, string DialogTitle);
[DllImport(@"user32.dll", EntryPoint = "GetWindowText")]
public static extern int GetWindowText(IntPtr Hwnd, StringBuilder text, int length);
Scott
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Hey,
Thanks for the reply. The StringBuilder option is indeed working, but getting an instance of a Control doesn't seem to work. (it stays null) It could be because the other application is a VC++ application and not .Net ??
thanks.
|
|
|
|
|
You have to make sure that you are looking for the correct window title. The search is done by that parameter, case sensitive. In my example, I left the title to default "Form1", change that to the title of the VC++ window.
Scott P
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
lol, thanks, that is working, but if I take that handle and try to create a Form or Control with the FromHandle method, it will still result in null, although GetWindowText is working.
IntPtr handle = FindWindow(null, "windowtitle");
Form f = Form.FromHandle(handle);
Control c = Control.FromHandle(handle);
string text = "";
GetWindowText(handle, text, 10);
MessageBox.Show(text);
So in this case both f and c are null, but the MessageBox will show my dialogtitle.
My theory is that the code can't convert a Dialog or a Control from a VC++ form/control to a .Net form/control, but I'm not sure about that.
thanks !
(and sorry to be so difficult )
|
|
|
|
|
Hello everybody,
in a DBF Database the strings are written in a given way.
If i read out the strings in C++ i get for the €-Char the Integer-Value -128
In C# i read out the string of the DBase-Table via the ODBC-Connection.
There the Integer-Value is 199 (and does not belong to the €-Char)...
if i convert the character set with Encoding.GetEncoding(858)
i get the right €-Char but has also a integer-value of 8364
How can i convert the values to obtain the -128?
Big thanks in advance !!
|
|
|
|
|
The Euro symbol wasn't part of the original ASCII set, but this[^] page says after installing a patch ASCII 128 becomes the Euro sign.
8364, on the other hand, is the Unicode value for the Euro sign and is safer to use.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
Hi master,
I got this error message when initialize matrix with so large number MxN
An unhandled exception of type 'System.StackOverflowException' occurred in [project name].exe
I dont know how to pass this error, anyone can help me please? This is my code:
<br />
class image<br />
{<br />
<br />
<br />
public void zoning()<br />
{<br />
int Max = 0;<br />
for (int i = 1; i < M - 1; i++)<br />
for (int j = 1; j < N - 1; j++)<br />
if (Img_In_Process[i, j] == -1)<br />
{<br />
Max++;<br />
Point_Zone(i, j);<br />
}<br />
}<br />
<br />
private void Point_Zone(int i, int j)<br />
{<br />
Img_In_Process[i, j] = Max;<br />
if ((i - 1 >= 0) && (Img_In_Process[i - 1, j] == -1)) Point_Zone(i - 1, j);<br />
if ((j - 1 >= 0) && (Img_In_Process[i, j - 1] == -1)) Point_Zone(i, j - 1);<br />
if ((i + 1 < M) && (Img_In_Process[i + 1, j] == -1)) Point_Zone(i + 1, j);<br />
if ((j + 1 < N) && (Img_In_Process[i, j + 1] == -1)) Point_Zone(i, j + 1);<br />
}<br />
}
|
|
|
|
|
You are recursively calling Point_Zone too many times and running out of stack space.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
As the other poster said, you are going too deep recursively.
Now you have 2 options:
a. Rewrite the algorithm so it does not need recursion, in other words iteratively.
b. Use editbin to increase the stack space if this is indeed a borderline case and an attempt at (a) failed.
|
|
|
|
|
Thanks for your reply, leppie.
I can not change my algorithm so I must increase stack space,
But I dont know how to increase the stack space, please help me!!
|
|
|
|
|
cuongmits wrote: I can not change my algorithm so I must increase stack space,
But I dont know how to increase the stack space, please help me!!
He already did, see his reply.
b. Use editbin to increase the stack space if this is indeed a borderline case and an attempt at (a) failed.
I would look into ways of changing the algorithm first though.
/* I can C */
// or !C
Yusuf
|
|
|
|
|
Hi Yusuf,
Yes, I read his reply already, but I dont know exactly how to use EDITBIN? Where is it??? Can you explain where to find that? Is it command or function of MS VS C#?
Best regards.
|
|
|
|
|
check MSDN ^
/* I can C */
// or !C
Yusuf
|
|
|
|
|
Hello.. im alittle new when it comes to handling threads and all the crap.. and i would really appreciate if someone would be able to give me some guidance tips..
i have tried to build a small search program who runs up of my entire hard drives (for now it was limited to windows directory)and to give me the strings that matches to the search box..
well it works perfectly.. though it takes a while to search because i dont know how to use multi threading..
i have tried reading articles but i always get stuck at some point... for now ive managed to create one single thread and when im trying to send another one .. they dont synchronize it just multiply the result by 2...can please someone direct me to the answer and help me abit.. wide explanations will be awesome
here's the code
the main procedure:
<br />
namespace SearchFile<br />
{<br />
public struct directors<br />
{<br />
public DirectoryInfo Dir;<br />
public bool processed;<br />
}<br />
public partial class Form1 : Form<br />
{<br />
<br />
directors direct;<br />
public string location = "";<br />
public delegate void invokegetdirecotrs(directors dr);<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
public void getDirectors(directors dr)<br />
{<br />
<br />
if (this.InvokeRequired)<br />
{<br />
invokegetdirecotrs inv = new invokegetdirecotrs(this.getDirectors);<br />
this.Invoke(inv, new object[] { dr });<br />
}<br />
<br />
else if( dr.processed == false)<br />
{<br />
dr.processed = true;<br />
int i = 0;<br />
Array Sub_Dir;<br />
FileInfo[] fi = dr.Dir.GetFiles();<br />
string comparest;<br />
Sub_Dir = dr.Dir.GetDirectories();<br />
if (Sub_Dir.Length > 0)<br />
{<br />
for (i = 0; i < fi.Length; i++)<br />
{<br />
comparest = fi[i].Name.ToString();<br />
for (int j = 0; j < comparest.Length - location.Length + 1; j++)<br />
{<br />
if (location == comparest.Substring(j, location.Length))<br />
{<br />
j = comparest.Length;<br />
listView1.Items.Add(fi[i].FullName.ToString());<br />
}<br />
}<br />
<br />
}<br />
foreach (DirectoryInfo d in Sub_Dir)<br />
{<br />
DirectoryInfo di = new DirectoryInfo(d.FullName.ToString());<br />
direct.Dir = di;<br />
getDirectors(direct);<br />
}<br />
<br />
}<br />
else<br />
{<br />
fi = dr.Dir.GetFiles();<br />
for (i = 0; i < fi.Length; i++)<br />
{<br />
comparest = fi[i].Name.ToString();<br />
for (int j = 0; j < comparest.Length - location.Length + 1; j++)<br />
{<br />
if (location == comparest.Substring(j, location.Length))<br />
{<br />
listView1.Items.Add(fi[i].FullName.ToString());<br />
j = comparest.Length;<br />
}<br />
}<br />
<br />
}<br />
<br />
}<br />
}<br />
}<br />
and the button click
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
<br />
listView1.Items.Clear();<br />
location = textBox1.Text;<br />
if (location != "")<br />
{<br />
DirectoryInfo dir = new DirectoryInfo(@"c:\divx");<br />
directors dr;<br />
dr.Dir = dir;<br />
dr.processed = false;<br />
ThreadStart starter = delegate<br />
{<br />
getDirectors(dr);<br />
};<br />
new Thread(starter).Start();<br />
<br />
ThreadStart starter1 = delegate<br />
{<br />
getDirectors(dr);<br />
};<br />
new Thread(starter1).Start();<br />
<br />
<br />
}<br />
}<br />
i appreciate your help!
the lost guy ;[
|
|
|
|
|
Gosh this code is a mess! I'm not sure I know where to start in helping you to work through this but here goes:
if (this.InvokeRequired)<br />
{<br />
invokegetdirecotrs inv = new invokegetdirecotrs(this.getDirectors);<br />
this.Invoke(inv, new object[] { dr });<br />
}
Whatever you are doing here it is very wrong. I think you've misunderstood the point of the Invoke method. It would serve you well to go and look up the documentation to this particular method and read through the description and pay extra attention to the examples given. In a nutshell, you use Invoke to marshall a call back to the UI thread - this is the only thread where you will be able to update the UI (In your case fill a matching file into the ListView).
On the subject of filling the listview you should have a method which encapsulates just this functionality. This method will itself take care of the cross-threadedness of your app.
private delegate void AddItemToListViewDelegate(string item);<br />
<br />
<pre>private void AddItemToListView(string item)<br />
{<br />
if(this.InvokeRequired)<br />
{<br />
this.Invoke(new AddItemToListViewDelegate(this.AddItemToListView),item);<br />
return;<br />
}<br />
this.listView.Items.Add(item);<br />
}</pre><br />
<br />
Now you can call this method from any thread and it will take care of marshalling back to the UI. Attantion to the return keyword, this stops execution continuing on the separate thread - this is one of the specific places you've gone wrong in your code.<br />
<br />
As for the rest of the code, you've massively over-complicated it. You dont need the structs and the wierd "processed" property, and you definately dont have to check the filename one char at a time like this (hint: string has a <code>Contains method):
comparest = fi[i].Name.ToString();<br />
for (int j = 0; j < comparest.Length - location.Length + 1; j++)<br />
{<br />
if (location == comparest.Substring(j, location.Length))<br />
{<br />
listView1.Items.Add(fi[i].FullName.ToString());<br />
j = comparest.Length;<br />
}<br />
}
All you really need is a recursive function that does the looking for the search phrase:
private void SearchRecursive(DirectoryInfo dir, string search)
{
foreach(FileInfo fi in dir.GetFiles())
{
if(fi.FileName.Contains(search))
AddItemToListView(fi.FileName);
}
foreach(DirectoryInfo di in dir.GetDirectories())
{
SearchRecursive(di,search);
}
}
Finally, why you fire off 2 threads in the button click I can only imagine, but suffice it to say you only need one and it should call SearchRecursive with the starting directory (new DirectoryInfo("c:\divx") ) and the contents of your search textbox (textBox1.Text ).
Hope that helps.
|
|
|
|
|
First Of all thanks for correcting me.. I made this program without knowing the contain function i donno y i havent looked that out ..
in addition.. the invoke key i have used was taken out from the mdsn site and i didnt really knew what the hell to do with it.. thanks for clearing that out
the program now works perfectly thank you !!
BUT
i wanted the process to work faster.. by adding more threads to the search program (where each thread looks at some other directory)thats what i meant by synchronizing threads and working with multi threads.. how can i do that?? consider your code as my base program code
and i can ask another question..
Multi threads and threadpool..
whats the difference between them??
is threadpool just a number of multi threads function?
thank you so much!
|
|
|
|
|
Multi threading isn't a simple solution to all your performance problems. You're accessing a disk here, and looping through every file and directory. Disk access is slow compared to CPU speeds. if you spawn multiple threads, all that's going to happen is they'll each be fighting over the disk because the disk won't be able to keep up with all the requests from the CPU.
It's like copying files. Try copying 2 large files separately, but start them at the same time. See how long it takes. Now try copying them one at a time and wait for the first to finish before you start the second, it'll take roughly the same amount of time in total, because by doing them both at the same all that happens is the CPU has to wait for the disk to be ready.
There is no easy way to speed up a full disk search, you've just got to sit it out. I suppose what you can do is have 1 thread for getting all the data from the disk, and a second to process it all, so thread 1 can carry on reading the disk while thread 2 is processing the data. But other than that, multi threading is not going to help you unless you have multiple disks, then you can target 1 thread at each disk.
(The other way to do things is to index the disk, and hold the index in memory. You would have to have a service or something to monitor the disk for changes. I assume this is how things like google desktop search works.)
Simon
|
|
|
|
|
Ok Got it thanks!
Can you please though give me an example of how to work with a multi threads situation??
this is not necessarily have to do with my program, i just want to go to know that feature cause i really cant seem to understand how to synchronize between threads..
And threadpool<>multi threads <-- what's the difference??
|
|
|
|
|
shinboxe wrote: threadpool<>multi threads <-- what's the difference??
Think of the thread pool as a pot of ready made threads available for you to use. Threads are relatively costly to create and manage, so if you just want to do some quick and simple actions on separate threads, you can request some threads from the pool, use them, then give them back when your finished. The thread pool will give you threads to meet your needs but when you've finished and you hand them back to the pool, it might keep them around and reuse them for other applications who use the pool rather than destroying and creating new threads every time someone needs them.
The disadvantage is that you lose some control over exactly how many threads you create and various other details like thread priority and stuff. You just tell the pool what jobs you want done with ThreadPool.QueueUserWorkItem(), and the pool will manage the threads for you.
There are lots of different ways to work with Threads, and it's not a simple topic, so I would suggest you get a good .Net book. "CLR via C#" and "Pro C# 2008 & the .Net 3.5 platform" both have good chapters on async operations and thread synchronisation with .Net
Simon
|
|
|
|
|
|