Hi All, I am using Vs05 + Windows application + c#. In my application i want to call system calculator. I have caleed this using
System.Diagnostics. Process.Start("Calc.exe"); But this applcation is open anywhere on myt form, I want to 1)open this form on my particular location. In short i want to set location of this form programatically. 2) I also want when user done some calculations in that calculator at that time the final value should assign to the textbox which is present on my form. Thanks in advance. | | sunDAC Wednesday, March 04, 2009 9:38 AM | You need to use Win32 api for doing this.
Open the calculator as you have done.
After Process.Start
Call Win32 API function to move the application to the specified location.
Use Win32 API function to get the value of the calculator text box. Thanks,
A.m.a.L- Proposed As Answer byKenky Dude Friday, March 06, 2009 5:56 AM
- Marked As Answer byBruce.ZhouMSFT, ModeratorTuesday, March 10, 2009 6:56 AM
-
| | A.m.a.L - aditi.com - Think Product Wednesday, March 04, 2009 10:28 AM |
Hi Thanks for the reply. I have gone through the link.But really cant get how to use that code for my application. Do you haveany procedure so that i can programatically allocate location to that calculator.
Waiting for the reply.
Try to set the poisition of the Window using SetWindowPos method. The effect may be not as you expect. Please refer to the following code.
| [DllImport("user32.dll")] |
| staticexternboolSetWindowPos(IntPtrhWnd,IntPtrhWndInsertAfter,intX,intY,intcx,intcy,uintuFlags); |
|
| privatevoidbutton2_Click(objectsender,EventArgse) |
| { |
| System.Diagnostics.Processp=newSystem.Diagnostics.Process(); |
| p.StartInfo=newSystem.Diagnostics.ProcessStartInfo("calc.exe"); |
| p.Start(); |
| Thread.Sleep(400); |
| SetWindowPos(p.MainWindowHandle,(IntPtr)0,10,10,260,300,0); |
| } | For VB.NET:
| DeclareAutoFunctionSetWindowPosLib"user32"(ByValhWndAsIntPtr,ByValhWndInsertAfterAsIntPtr,_ |
| ByValXAsInteger,ByValYAsInteger,ByValcxAsInteger,ByValcyAsInteger,ByValuFlagsAsUInteger)AsBoolean |
|
| PrivateDeclareFunctionSetParentLib"user32"(ByValhWndChildAsSystem.IntPtr,ByValhWndNewParentAsSystem.IntPtr)AsInteger |
| PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click |
| DimpAsNewProcess |
| p.StartInfo.FileName="calc.exe" |
| p.Start() |
| System.Threading.Thread.Sleep(500) |
| SetWindowPos(p.MainWindowHandle,NewIntPtr,10,10,200,200,0) |
| EndSub |
| EndClass | Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer byBruce.ZhouMSFT, ModeratorTuesday, March 10, 2009 6:56 AM
-
| | Bruce.Zhou Thursday, March 05, 2009 11:06 AM | You need to use Win32 api for doing this.
Open the calculator as you have done.
After Process.Start
Call Win32 API function to move the application to the specified location.
Use Win32 API function to get the value of the calculator text box. Thanks,
A.m.a.L- Proposed As Answer byKenky Dude Friday, March 06, 2009 5:56 AM
- Marked As Answer byBruce.ZhouMSFT, ModeratorTuesday, March 10, 2009 6:56 AM
-
| | A.m.a.L - aditi.com - Think Product Wednesday, March 04, 2009 10:28 AM | Hi ,Thanks for the reply. Can you give me procedure in c#, how to call Win32 api and so that i can programatically allocate location to that calculator.
Waiting for the reply. | | sunDAC Thursday, March 05, 2009 8:50 AM | http://www.c-sharpcorner.com/UploadFile/shrijeetnair/win32api12062005005528AM/win32api.aspx Thanks,
A.m.a.L- Proposed As Answer byKenky Dude Friday, March 06, 2009 5:56 AM
-
| | A.m.a.L - aditi.com - Think Product Thursday, March 05, 2009 9:05 AM | Hi Thanks for the reply. I have gone through the link.But really cant get how to use that code for my application. Do you haveany procedure so that i can programatically allocate location to that calculator. Waiting for the reply.
| | sunDAC Thursday, March 05, 2009 10:04 AM | That link is only for an intro.
There are more methods available.
Search in web. Thanks,
A.m.a.L- Proposed As Answer byKenky Dude Friday, March 06, 2009 5:56 AM
-
| | A.m.a.L - aditi.com - Think Product Thursday, March 05, 2009 10:39 AM |
Hi Thanks for the reply. I have gone through the link.But really cant get how to use that code for my application. Do you haveany procedure so that i can programatically allocate location to that calculator.
Waiting for the reply.
Try to set the poisition of the Window using SetWindowPos method. The effect may be not as you expect. Please refer to the following code.
| [DllImport("user32.dll")] |
| staticexternboolSetWindowPos(IntPtrhWnd,IntPtrhWndInsertAfter,intX,intY,intcx,intcy,uintuFlags); |
|
| privatevoidbutton2_Click(objectsender,EventArgse) |
| { |
| System.Diagnostics.Processp=newSystem.Diagnostics.Process(); |
| p.StartInfo=newSystem.Diagnostics.ProcessStartInfo("calc.exe"); |
| p.Start(); |
| Thread.Sleep(400); |
| SetWindowPos(p.MainWindowHandle,(IntPtr)0,10,10,260,300,0); |
| } | For VB.NET:
| DeclareAutoFunctionSetWindowPosLib"user32"(ByValhWndAsIntPtr,ByValhWndInsertAfterAsIntPtr,_ |
| ByValXAsInteger,ByValYAsInteger,ByValcxAsInteger,ByValcyAsInteger,ByValuFlagsAsUInteger)AsBoolean |
|
| PrivateDeclareFunctionSetParentLib"user32"(ByValhWndChildAsSystem.IntPtr,ByValhWndNewParentAsSystem.IntPtr)AsInteger |
| PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click |
| DimpAsNewProcess |
| p.StartInfo.FileName="calc.exe" |
| p.Start() |
| System.Threading.Thread.Sleep(500) |
| SetWindowPos(p.MainWindowHandle,NewIntPtr,10,10,200,200,0) |
| EndSub |
| EndClass | Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer byBruce.ZhouMSFT, ModeratorTuesday, March 10, 2009 6:56 AM
-
| | Bruce.Zhou Thursday, March 05, 2009 11:06 AM | Hi Thanks for the reply. I have gone through the code. It will set the window of calculator as per my location. But problem is that coz here we use Thread.Sleep(400); so that the calculator form is just blinked and then set to appropiate position which i given. If i incresed sleep time ie.10000 at that time the user cant senese blink of that form but when i try to close that calculator at that time it throws exception System.InvalidOperationException was unhandled Message="Process has exited, so the requested information is not available."
Can i avoid this blink of form. Waiting for the reply. | | sunDAC Thursday, March 05, 2009 12:53 PM | Hi sunDAC,
As I said in my previous post, the effect may not be as satisifed as you expected. Actually, we set the position after the calculator is shown, so you can see the blink form. I think it can hardly be fixed if we are using this way.
Maybe using Global hook can do the trick, but I haven't tried yet. Usingglobal hook to intercept thewindows creation event, and set the poistion of the Windows in the callback method.Global hook is not supported by .NET Framework by default, you may gain some clues from this article.
Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't. | | Bruce.Zhou Friday, March 06, 2009 5:52 AM |
|