|
Here is an example to Simulating User Clicks. Just use the methods "GetWindowHandleWhoseTitleStartsWith" and "SimulateClick". The problem with this approach is that the external application must be active (I think) and visible (I think). Also, you develop a hard dependency between the location of buttons in your application and the third-party software, which is terrible practice. The alternative method I suggested is DEFINITELY the preferable way to do it, but I cannot give you an example because I have not used sockets or HTML communication in C#. Basically, the idea is that you would open a socket connection on the standard html port at the destination (probably some call like Socket s = new Socket("http:\\www.google.com", 54), send an html request to get the search page (probably like s.SendMessage(new HTMLRequest("http:\\www.google.com#searchstrings"))), then parse the return HTML to get the first link (see xmldocument or htmldocument), and finally load the data from that link into your own HTML browser. You will have to do some work to figure that out, but it will ALWAYS work and does not depend on third-party software (other than the search engine). Sorry I couldn't be more help in that arena.
private IntPtr m_Handle = IntPtr.Zero;
public delegate bool EnumWindowsProc(IntPtr handle, object data);
[DllImport("user32.dll")]
public extern bool EnumWindows(EnumWindowsProc proc, object data);
[DllImport("user32.dll")]
public extern int GetWindowText(IntPtr handle, StringBuilder title, int maxSize);
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr handle, uint op, uint keys, Point point);
public IntPtr GetWindowHandleWhoseTitleStartsWith(string title) {
m_Handle = IntPtr.Zero;
EnumWindows(myEnumWindowsProc, title);
return m_Handle;
}
private bool myEnumWindowsProc(IntPtr handle, object data) {
string searchTitle = data as string;
if (searchTitle == null)
return true;
StringBuilder title = new StringBuilder();
GetWindowText(handle, title, searchTitle.Length + 1);
if (title.ToString() != searchTitle)
return true;
m_Handle = handle;
return false;
}
public void SimulateClick(Point pos, IntPtr handle) {
SendMessage(handle, (uint)WM_MOUSEDOWN, 0, pos);
SendMessage(handle, (uint)WM_MOUSEUP, 0, pos);
}
Jeff
|
|
|
|
|
Ever have this problem with Oracle 9i+ when opening the connection
ps. It's working just fine with 8i!
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
Hi
I want to use a Windows Service to call certain stored procedures once a day.
It needs to pass the DateTime.Now as a variable to these stored procedures.
If someone could please help me out as to how i implement a timer and call stored procedures and pass the current datetime to the stored procedures.
Thanks
|
|
|
|
|
You can initialize a variable of System.Threading.Timer in the OnStart method as set up event handler for Elapsed event. In the event handler call the stored procedure using sqlcommand object and pass the parameter by adding it to Parameters collection
|
|
|
|
|
hi all.i use twain.net image scanner and i want set resolution within code wiyhout using twain.interface but i can't please send me sample with C#
|
|
|
|
|
chehreghany wrote: i want set resolution within code wiyhout using twain.interface
The only method you have to use is the TWAIN interface...
Or if you don't want to use TWAIN, you might be able to find an SDK for the scanner you're using. In which case, you'll have to use it's interface to set the resolution.
There is no "generic" .NET or Win32 API method to do this.
|
|
|
|
|
I want to copy one listview.item and change name on subitem[1] by +1 if that exists add+1 and futher
Dictionary<string, int32=""> list = new Dictionary<string, int="">();
if (listView2.SelectedItems.Count > 0)
{
foreach (ListViewItem lvi in listView2.Items)
{
int number = Convert.ToInt32(lvi.SubItems[1]);
bool alreadyExists = true;
while (alreadyExists)
{
alreadyExists = false;
foreach (int existingNumber in listView2.Items)
{
if (existingNumber == number)
{
alreadyExists = true;
break;
}
}
if (alreadyExists)
{
number = number + 1;
}
}
}
}
it says: Unable to cast object of type 'ListViewSubItem' to type 'System.IConvertible'?
what should i do? sigh
tnx mates
|
|
|
|
|
andredani wrote: int number = Convert.ToInt32(lvi.SubItems[1]);
You can't convert a ListViewSubItem control to an integer. If you want the contents of the item, use the Text property.
---
single minded; short sighted; long gone;
|
|
|
|
|
have search in internet the hole day after this.. can you help me....
|
|
|
|
|
Did you read my post? If there is something that you don't understand, say what it is instead of just pretending that I didn't write it.
---
single minded; short sighted; long gone;
|
|
|
|
|
no.. i meant that i haved googled on text property and listview property..
But i did´t find the awnser..
I have come as far as this:
if (listView2.SelectedItems.Count > 0)
{
int number = 0;
foreach (ListViewItem lvi in listView2.Items)
{
bool alreadyExists = true;
while (alreadyExists)
{
alreadyExists = false;
foreach (int existingNumber in lvi.SubItems[1].Text)
{
if (existingNumber == number)
{
alreadyExists = true;
break;
}
}
if (alreadyExists)
{
number = number + 1;
}
}
this.listView2.Items.Add(number.ToString());
}
}
changed a little bit but (i only get 0 in my listview, its beacause int number = 0;)
-- modified at 19:01 Saturday 8th September, 2007
|
|
|
|
|
I don't understand what nodes you want duplicated, you might need to post an example of the input and output. There is not much point in doing a foreach over a single item like you have done in the inner loop.
Here is an example that duplicates each node in the listview and increments the subitem. This only adjusts SubItems[1] other subitems are not changed. It also does no checking if SubItems[1].Text is an number or not.
e.g
Before:
A 1
B 1
C 1
After:
A 1
B 1
C 1
A 2
B 2
C 2
foreach (ListViewItem item in listView1.Items)
{
int value = int.Parse(item.SubItems[1].Text);
ListViewItem newItem = (ListViewItem)item.Clone();
newItem.SubItems[1].Text = (value + 1).ToString();
listView1.Items.Add(newItem);
}
|
|
|
|
|
it´s gonna work like this:
before:
a k111
b k111
a k112
after a click on a k111:
a k111
b k111
a k112
a k113 (this is the copy)
|
|
|
|
|
What are you trying to do really? The text of a SubItem is a string, and a string doesn't contain any integers, it only contains characters.
If you use foreach on a string, it will loop through the characters in the string, and casting each character to int means that you get the unicode character codes for the characters in the string. You won't find any characters in the string with the character code 0.
What does the SubItems contain? If it is the string representation of a number, you have to parse the string if you want to get the number. Use the int.Parse method.
---
single minded; short sighted; long gone;
|
|
|
|
|
Subitem[1] is gonna contain one letter and than all numbers, like this:
Before:
A k111
B k111
A k112
After a click on A k111:
A k111
B k111
A k112
A k113
|
|
|
|
|
andredani wrote: Subitem[1] is gonna contain one letter and than all numbers, like this:
Before:
A k111
B k111
A k112
After a click on A k111:
A k111
B k111
A k112
A k113
That doesn't make sense.
"A k111" is not one letter then all numbers. That's a letter, a space, another letter, and then some digits.
If you click "A k111", what is the process to get to "A k113"? That's not adding one, so the items have to be related somehow?
---
single minded; short sighted; long gone;
|
|
|
|
|
IList<string> m_SubItems = new List<string>();
if (m_ListView.SelectedItems.Count > 0) {
// Why do you need SelectedItems.Count > 0? ...
// You don't ever reference them again within the if statement
for (int i = m_ListView.Items.Count - 1; i >= 0; --i) {
ListViewItem current = m_ListView.Items[i];
string item = current.SubItems[1].Text;
if (m_SubItems.Contains(item)) {
// This code assumes that all integers have only one digit.
// If you want something different, you must change how index is created.
int index = (int)item[item.Length - 1];
item = item.Substring(0, item.Length - 1);
do {
ListViewItem newItem = new ListViewItem();
...
newItem.SubItems.Add(new ListViewSubitem(item + (++index).ToString()));
m_ListView.Items.Add(newItem);
} while (m_SubItems.Contains(item + index.ToString()));
} else {
m_SubItems.Add(item);
}
}
}
Hope this helps!
Jeff
|
|
|
|
|
thanks man!
but this says:
newItem.SubItems.Add(new ListViewSubitem(item + (++index).ToString()));
Error 1 The type or namespace name 'ListViewSubItem' could not be found
tnx
|
|
|
|
|
I never type in a compiler. Push F1 when the cursor is over Add, and see what type it should be
|
|
|
|
|
it does´t work for me, i´m i doing wrong??
i get all the listview items subitem[1] copyied and the rest empty... strange...
|
|
|
|
|
|
IList<string> m_SubItems = new List<string>();
for (int i = listView1.Items.Count - 1; i >= 0; --i)
{
ListViewItem current = listView1.Items[i];
string item = current.SubItems[1].Text;
if (m_SubItems.Contains(item))
{
int index = (int)item[item.Length - 1];
item = item.Substring(0, item.Length - 1);
do
{
ListViewItem newItem = new ListViewItem();
newItem.SubItems.Add(item + (++index).ToString());
listView1.Items.Add(newItem);
}
while (m_SubItems.Contains(item + index.ToString()));
}
else
{
m_SubItems.Add(item);
}
}
}
|
|
|
|
|
you need to copy all subitems, not just the first.
|
|
|
|
|
hi all,
I am using a datagridview to display data. In one of the columns i am displaying the title and when i click the title, the row height is adjusted to include title as well as description. i have managed to do this.
Now when i click another row, in the previous row, only the title should be displayed and the description should be hidden.
i did this using the rowleave event of datagridview. but i am not sure whether i managed it right. because i need to click another row twice to get the title and description.
Hope i am clear in my description.
How can i handle this?
Any suggestions please.
Thanks in advance.
Regards
Anuradha
|
|
|
|
|
Hi All,
I am working on a C# windows application which uses a MySql db as back-end. it is a huge solution with 100 forms. Everything was fine until last week When I was told, " there is a chance this application will be used my multiple users and same forms can be opened simultaneously(from different machines)". so My application was not designed in such a manner that it can handle multiple user access same data and modify it at the same time. For ex: if one user creates/edits/deletes a record then the other user can not know that a record is created/edited/deleted on the same form.
I thought of using remoting. A windows service on the DB server will have the "users + forms opened" list. As the user logs in and tries to open a form, my application will connect to service and check for, if that form is already opened by some one else. if true, then it will open form in a lock mode. But the problem is, if some one opens the form in lock mode and then the form should be notified once it is unlocked. How should i implement this? I read few articles on Remoting and invoking events but everybody says that it is not a suitable way. What can be other ways please suggest ?
Added to this now i came to know that the application will be run on a terminal server . I tested it on terminal server to see if there are any issue, I found, when my application if run by multiple users can't write to the config file. Only the user who installed it can write into the config file. I thought it is a permission issue which can be resolved. Then i read few posts stating .Net application performance degrades when run on a terminal server. in the sense that Memory consumption is too high. Well i have not tested it for sure. but Will there be any problem with the Remotng part if both the service and my application run on the same terminal server ? Will there be any performance issue ? I am worried because my application is already using 100 mb of memory.
I have very little time left please help
Thanks
KSS
|
|
|
|