|
I have a requirement to be able to send keypresses to another application(yes this is the only option). I also cannot bring that application to the foreground(voiding the use of sendkeys). Ive found "postmessage" which does work, except that it seems to send the key directly to the program instead of simulating a keyboard press. So I need something that makes the application think it has come directly from the keyboard(which will also mean that another logging application I have will be able to pick the press up - as it doesnt with postmessage).
Is there maybe a function that I can call with p/invoke?
Thanks
Strive to be humble enough to take advice, and confident enough to do something about it.
|
|
|
|
|
roguemat wrote: I also cannot bring that application to the foreground(voiding the use of sendkeys).
Not sure if this is any help, but: Have you thought about bringing it to the foreground outside of the visible desktop area?
You could bring the window up at -1000, -1000 (and make sure it's window size doesn't exceed that of course), use SendKey and put it back to its original position. May not be very elegant, but it should work.
Standards are great! Everybody should have one!
|
|
|
|
|
I am tryng to split a process in some methods stopping the methods with objects ManualResetEvent and AutoResetEvent but I am having problems with the WaitHandle.WaitAll() method with this method I want stop the proccess until everyone event is pointed, but I receive the error message of "Not valid WaitAll for various events in a STA proccess"
Please ho can I solve the problem
|
|
|
|
|
Use Google. The first hit that comes up already provides a solution:
private void WaitAll(WaitHandle[] waitHandles) {
if (Thread.CurrentThread.ApartmentState == ApartmentState.STA) {
foreach(WaitHandle myWaitHandle in waitHandles) {
WaitHandle.WaitAny(new WaitHandle[]{myWaitHandle});
}
}
else {
WaitHandle.WaitAll(waitHandles);
}
}
Standards are great! Everybody should have one!
|
|
|
|
|
You can start a new thread, set its apartment state to MTA and call the WaitAll method there. Then just call Join on the thread. It is much better then using a foreach loop.
|
|
|
|
|
Hi anyone, i asking about managed and unmanaged code and why we need that???
I need a good reference to know in depth about them...........
Regards
|
|
|
|
|
This looks ok. Or you can just try Wikipedia and the references in the bottom of the page.
Standards are great! Everybody should have one!
|
|
|
|
|
I would also recommend you pick up a book like CLR via C# and read.
Now...bring me that horizon. And really bad eggs...Drink up me hearties, YO HO!
|
|
|
|
|
|
I have an address book program completely done, except for one thing...
When a name is highlighted in the listbox, I need all of their information displayed in the related textboxes. All the contact information is stored in an array. I was playing with the code, and I know how to display just the information in the listbox, which is the first and last name, but I need ALL of the contact info displayed in the textboxes. I have included my code, and a screenshot of what should happen when a name is selected from the listbox.
Screen Shot[]
public partial class frmAddressBook : Form
{
string[] Contacts = new string[20];
int i = 0;
public frmAddressBook()
{
InitializeComponent();
}
private void AddressBook_Load(object sender, EventArgs e)
{
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnAdd_Click(object sender, EventArgs e)
{
string lastName = tbxLastName.Text;
string firstName = tbxFirstName.Text;
string street = tbxStreet.Text;
string city = tbxCity.Text;
string state = tbxState.Text;
string zip = tbxZip.Text;
if (i < 20)
{
Contacts[i] = lastName + ", " + firstName;
i++;
}
else
{
MessageBox.Show("The Address Book Can Hold a Maximum of 20 Contacts.", "Address Book Full");
}
tbxFirstName.Text = "";
tbxLastName.Text = "";
tbxStreet.Text = "";
tbxCity.Text = "";
tbxState.Text = "";
tbxZip.Text = "";
lstContacts.Items.Clear();
for (int j = 0; j < 20; j++)
{
if (Contacts[j] != null)
{
lstContacts.Items.Add(Contacts[j].ToString().Trim());
}
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
for (int k = 0; k < Contacts.Length; k++)
{
try
{
if (Contacts[k].Contains(lstContacts.SelectedItem.ToString()))
{
Contacts[k] = null;
}
}
catch
{
}
}
lstContacts.Items.Clear();
for (int j = 0; j < 10; j++)
{
if (Contacts[j] != null)
{
lstContacts.Items.Add(Contacts[j].ToString().Trim());
}
}
}
private void lstContacts_SelectedIndexChanged(object sender, EventArgs e)
{
tbxFirstName.Text = lstContacts.SelectedItem.ToString();
}
}
}
|
|
|
|
|
Hi,
I have a lot of comments, here are some:
1.
you should not try and keep a lot of information in a single string, so string[] Contacts isn't a good choice.
2.
you should also not try and keep an unknown number of items in an array, as that will become a functional limitation, and needs code to guard you against an overflow. Instead use some kind of list; ArrayList is simple, however it got superceded by List<sometype> which is known as a generic list.
3.
a ListBox can hold items of any kind you choose, not just strings. So what you could and should do is:
- declare a Contact class, with all the fields you like;
- create, then add, such Contact instances to the ListBox;
- to get it painted, do one of these:
a) give Contact a ToString() method that lists all fields, each with a constant width (i.e. use string.PadRight() or string.PadLeft() to add spaces;
b) make the ListBox ownerdrawn, and provide a DrawItem handler which basically does a Graphics.DrawString() for each of the fields.
4.
If you want to be able to sort your contacts on each of the fields, then you would be better of with a DataGridView
5.
some comments on coding style:
- don't call ToString() on strings, as it doesn't achieve anything (see Contacts[j].ToString())
- don't use short identifiers for class members (your int i); a one-letter identifier is OK for a local for loop, not for a state variable.
- don't create empty catch blocks; always specify what it is you catch, and then show it, so no problem can go unnoticed and waste hours of debugging. Example:
try {
...
} catch(Exception exc) {
MessageBox.Show(exc.ToString());
}
6.
and finally, if you haven't done so yet, buy and study a book on C#, it introduces you to all major language features and good coding practices.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
I will take some of your suggestions into consideration. I am doing all of this as the guidelines in my C# book dictate. I am trying to learn C#, I just need some help every now and then on some of the problems in the book. Thi sis the first real problem I have come across, and I am totally lost.
|
|
|
|
|
CarlMartin10 wrote: I just need some help every now and then
No problem. You found the right forum to ask away. Just make sure you show you made an effort, as you did, and people will be glad to help.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Instead of storing your contact data as an array of strings. You could create another class to contain all the data you need, and then use a list or array of that. For example:
class ContactData
{
string FirstName;
string LastName;
string Address;
string City;
string State;
string Zip;
public override string ToString()
{
return FirstName + ", " + LastName;
}
}
You could then add this class to your listbox just as you do with your current array of strings.
The override for ToString is so that the listbox knows what text to display for that item. So you can just do this when adding items (assuming Contacts is now an array of ContactData )
for (int j = 0; j < 20; j++)
{
if (Contacts[j] != null)
{
lstContacts.Items.Add(Contacts[j]);
}
}
Then, to get the information back out you can get the selected item from your listbox and cast it back to a ContactData and access your information:
private void lstContacts_SelectedIndexChanged(object sender, EventArgs e)
{
ContactData myData = lstContacts.SelectedItem as ContactData;
tbxFirstName.Text = myData.FirstName;
...
}
My current favourite word is: Sammidge!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
I would love to do it this way, but that defeats the purpose of the problem, which is to illustrate how to do it with an array. I need to learn C#, and this book has been very useful, but it really does not explain how to do this part, at all.
|
|
|
|
|
let us consider we have two forms form1 and form2 and there are some information in form1 that i would like to use in form2... which method should i use to perform this action?
|
|
|
|
|
if form1 create form2 then from form2 you can define a public var. like this:
int x;
public int X
{
set
{
x=value;
}
}
then when you create you can send the var. like this:
form2 f2=new form2();
f2.X=5;
f2.show();
|
|
|
|
|
suppose we have a tab of buttons in form1 and i want to use the text of the clicked button in form2... how can i do such a thing?
|
|
|
|
|
use delegation:
in form1 create textbox and put:
public delegate void dd(string s);
public static dd d;
and put (d=new dd(write);) in public Form1()
then write method (write):
privet void write(string s)
{
textbox1.text=s;
}
in form2 create button and textbox then in click event put:
Form1.d(textbox1);
modified on Wednesday, January 20, 2010 6:53 PM
|
|
|
|
|
There are three obvious ways if Form1 is the parent.
1. Form1 sets a property in Form2 (as suggested above)
2. Form1 calls a method in Form2
3. Form2 raises a custom DataRequest event with custom EventArgs . Form1 subscribes to this and fills the event args accordingly when it handles the event.
If Form2 is the parent form then a DataChanged event in Form1 and a suitable handler in Form2 is the way to go.
If the hierachy is different, then a combination of the above up and down the hierachy will work. If that gets too complex then a separate manager class that routes events between the class instances can be useful.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi
I need to validate the email addresses to check if they are existing or not.
I used the following code to check first for the validation of domain but it failed with the following exception : A connection attempt failed because the connected party did not properly respond after a certain period of time, or established connection failed because conencted host has failed to respond 209.85.135.17:25
Here I used 25 port but is that port valid or i have to use someother port.
string address = "test@g.com";
string[] host = (address.Split('@'));
string hostname = host[1];
IPHostEntry IPhst = Dns.Resolve(hostname);
IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
Socket s= new Socket(endPt.AddressFamily,
SocketType.Stream,ProtocolType.Tcp);
s.Connect(endPt);
Can anyone please help me. Any Ideas please!! I need it urgently.
Thanks in advance,
--
http://ashakthi.blogspot.com
http://kids-articles.blogspot.com
|
|
|
|
|
In my country many providers block port 25 to reduce spam. tried another?
|
|
|
|
|
This will also depend on the firewall settings on your network setting etc.
Now...bring me that horizon. And really bad eggs...Drink up me hearties, YO HO!
|
|
|
|
|
|
Hi men and womens
I want to reading email message by C#
and as you know the c# dont apply the pop3 protocol
so I used The Tcp class to connect and reading message from the server
But the problem is when I try to read the message ,it read all the content of the message
as Message Id and some html tages
so
How can I read The Body Or Subject only
because I want to use form to Show From ,To,Subject,Body only so how
and thanks so so so so so much
|
|
|
|
|
Such email message is a file containing:
- a header
- a blank line
- the body (in ascii, can be empty)
- followed with 0 or more attachments
Rfc 822 descibes this and http://www.ietf.org/rfc/rfc2045.txt?number=2045[^] descibes the attachments (also read 2046,2047,2048)
Because many people use an email-client that produces a html-version of the body, these messages will have an ASCII-version in the body and the html-version as an (hidden) attachment. Sometimes the body is empty and there's only an attachment.
Hope this answers your question.
|
|
|
|
|
My apologies if something like this has already been asked and answered; I did some Google searching, as well searching on this site, and didn't find it, so here goes. I'm new to the world of .NET 3.5 and Linq. What I have are 1 + n xml files. The first Xml file looks sort of like this:
<files>
<file id="1" name="(some guid)"/>
<file id="2" name="(some guid)"/>
</files>
There are then files in the same directory, whose name matches the guid plus .xml, like so:
<file id="1">
<prop1>Value 1</prop1>
<prop1>Value 1</prop1>
<prop1>Value 1</prop1>
</file>
What I'd like to be able to do is this: for each file listed in the first xml blob, I want to create an object based on the values in each of the other xml files that look like the 2nd blob, and return that as an IEnumerable<Thing>. Does anybody know where I can find an example of how to do this?
Thanks in advance.
|
|
|
|