|
Hello,
I was wondering if there is a way to perform a simple left mouse click anywhere on the screen?
Thanks.
|
|
|
|
|
The last time I tried this (about 4 years ago) it was complicated, assuming you want to move the mouse outside the bounds of the executing app. I had to hook the Windows Queue and intercept / process the mouse messages.
There is an article for something similar here
http://blogs.msdn.com/toub/archive/2006/05/03/589468.aspx[^]
I'm not sure this will work on OSs newer than XP, or even if this is the best way to go about it. Hopefully one of the opther CPians will have a better suggestion
CCC solved so far: 2 (including a Hard One!)
|
|
|
|
|
Hi,
yes you can click anywhere using P/Invoke and calling
[DllImport("user32.dll", CallingConvention=CallingConvention.StdCall, SetLastError=true)]
public static extern IntPtr SendInput(int count, ref INPUT input, int size);
I've built a little class that moves and clicks any way I want.
Of course clicking at (x,y) in screen coordinates assumes the thing you want to click really is there (the user or some code may move objects around) and is not covered by something else.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I create class library, its name "SharedObjects". This library contain one class, its name "Sample". Class "Sample" contain following codes;
private static readonly Sample m_Instance = new Sample();
private Sample()
{
}
public static Sample Instance
{
get { return m_Instance; }
}
public string Name { get; set; }
Sample class is singleton, and have one property which is "Name". I add two Windows Forms Application to my solution which are "Win1" and "Win2".
In Win1 contain following code;
Sample.Instance.Name = "ABC";
MessageBox.Show(Sample.Instance.Name);
In Win2 contain following code;
MessageBox.Show(Sample.Instance.Name);
My problem is, I run Win1 code its properly work but after that I run Win2 do not show "ABC", its show empty string.
I think my problem is related about application domain, but I can't solve my problem. I wrote CrossAppDomainSingleton class but I can't solve my problem.
Please help me...
|
|
|
|
|
Yes you have found expected behavior. The two applications are in separate AppDomains with separate memory spaces. Typically when sharing information between apps you would set up an intermediary source, like a database or a message queue. You could also create a WCF or Remoting service to share the data between apps
only two letters away from being an asset
|
|
|
|
|
Aoooo, actually my project already use WCF. Real senario like this, SharedObjects is inherit from generic list and this dll is shared dll, its mean using server-side and client-side. Run thread on application server when WCF service hosting and use "SharedObjects" dll.
Client use this dll, two times in one operation. First is using in client-side, second is server side via WCF. So add data to SharedObjects list. Its properly work. But another client want to use SharedObjects list in server side via WCF, SharedObjects list count is zero, main problem is this.
|
|
|
|
|
I don't understand your whole server side and client side breakdown. All you need is the WCF service, once instantiated the client has a proxy, an instance of the class, no need for a client copy also. What are you using with the WCF service?
only two letters away from being an asset
|
|
|
|
|
Sorry, I fix my question and ask again in the form.
I wrote class library (dll) and this library contains one singleton class. Like this;
public class MyList : List<string>
{
private static readonly MyList m_Instance = new MyList();
private MyList()
{
}
public static MyList Instance
{
get { return m_Instance; }
}
}
Client --- WCF --> Server; add item to MyList class, its properly work.
Another Client --- WCF --> Server; add item to MyList class, its properly work.
But;
I have a thread in server side. If this thread add to item to MyList, clients items not contain in the MyList. Actually main problem is I can't see MyList items which are aded by clients in server thread.
I think this problem related about AppDomain. How can I solve it?
Best Regards...
|
|
|
|
|
You still haven't answered the question. How have you constructed the WCF service? What InstanceMode are you using? What persistance mechanism are you using? How much do you really understand about WCF and using it?
only two letters away from being an asset
|
|
|
|
|
My WCF Service use TcpBinding and host on windows service. I am not use ServiceBehavior InstanceContextMode... Problem not related about WCF.
I wrote class which is MyClass1, this class in server side. This class have a Start() function.
public void Start()
{
Thread thread = new Thread(new ThreadStart(CheckTablesAreChanged));
thread.IsBackground = true;
thread.Start();
}
private void CheckTablesAreChanged()
{
while (true)
{
... ADD ITEM TO MyLIST CLASS ...
}
}
Start() function call when WCF is hoting like this;
host.Open();
MyClass1.Start();
So this side not related about WCF.
In Client side;
Client --> WCF --> Server --> ADD ITEM TO MyLIST CLASS
For example client add 3 ITEM TO MyLIST CLASS, after that I check MyLIST CLASS count property in "CheckTablesAreChanged()" function, MyLIST CLASS count is 0.
|
|
|
|
|
As Pete said in the prevous posts, each AppDomain is in its own memory space and is therefore isolated, marshalling objects between domains is not a facile task. In any case I think the architecture you describe is unsound:
- It breaks the principles of client / server architecture. If you want to access a common object you should only do this on the server via method calls. There are several ways of persisting the common object between calls / clients
- By attempting to call methods/set properties on an object instanced on the server from the client, you are opening up a security hole
CCC solved so far: 2 (including a Hard One!)
|
|
|
|
|
|
What is the easiest way to activate a specific excel worksheet within a workbook. I am using MS visual C#
|
|
|
|
|
Youre description is a bit vauge, but I'm guessing it would be something like Worksheets("someSheetName").Active ??
|
|
|
|
|
-David
I tried this method and it says
Error 2
The name 'Worksheets' does not exist in the current context
|
|
|
|
|
How about supplying the name you're using for the Excel Application object?
myExcelAppObject.Worksheets...
|
|
|
|
|
Actually.... Im not clear on excel worksheet within a workbook? Could you clarify on this?
Thanks
Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Example you can have one Excel workbook with multiple tabs I am trying to figure out how to make the 3rd tab the active tab to manipulate the data.
|
|
|
|
|
antsims wrote: What is the easiest way to activate a specific excel worksheet within a workbook.
The easiest way is to search the MSDN documentation & samples[^].
|
|
|
|
|
Hi,
I have an application used to print certain product info sheets. It is normally launched as a conventional application and works exactly as intended. The associated database editor can also launch it (using Process.Start()) to print any changed product sheets; in that case the application prints correctly but remains open after completing its work. If I call this.Close() explicitly from anyplace other than the Quit menu item handler an exception is thrown; using Application.Exit() or Environment.Exit() has no effect. Looking at the Process documentation on MSDN yields no obvious clues.
How can I have the application quit automatically after being launched by the database editor?
Thanks in advance,
-Frank Alviani
|
|
|
|
|
You really have no control over that. The application that you launch has to supply that kind of functionality, maybe through a command line switch. You'll have to consult with the documentation or the manufacturer of the app you're launching.
|
|
|
|
|
Thanks for the info. I wrote the app myself, and know *when* I should be quitting automatically - I just can't figure out which method to call to do so
|
|
|
|
|
OK, I read the original post wrong. Application.Exit() is what you should be using. If it's not working, then you've got something else wrong in your app that is preventing your app from closing.
How do you have your app processing command line arguments and printing your document? Are you doing this in the forms Load event? IIRC, calling Application.Exit() in the Load event doesn't do anything.
|
|
|
|
|
Thanks for your hint. During the form constructor, I detect if I have a command line argument listing the sheets to print and immediately proceed to handle it. This occurs before the main window is shown. I now set a flag that is tested during the form_Shown() handler and if I have printed sheets I call Application.Exit() as you recommended. Works like a charm
Again, thanks!
-Frank
|
|
|
|
|
OK - it's kind of the wacky way to go about it, but whatever works.
I'd normally create my own Main method, do whatever command line stuff I need to there and if I need to start the Windows Form app, branch off to the Application.Run(new MyMainForm). Other than that, let the Main method die normally.
|
|
|
|