Monday, August 31, 2009

How to view windows calculator from program c#

To view windows calculator from your program

  1. take a new project named - calculatorviewer solution explorer autometically created
  2. take a button in your form .
  3. use namespace System.Runtime.InteropServices;
  4. button click event write the folowwing code
[DllImport("shell32.dll")]
private static extern long ShellExecute(IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);

[DllImport("user32.dll")]
private static extern int FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll")]
private static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);

[DllImport("user32.dll")]
private static extern int GetParent(int hWnd);

[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);

//Gets window attributes
[DllImport("USER32.DLL")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

private const int WM_COMMAND = 0x0112;

private const int WM_CLOSE = 0xF060;

private const int BN_CLICKED = 245;

private const int GWL_ID = -12;

IntPtr hwndChild = IntPtr.Zero;

IntPtr hwnd = IntPtr.Zero;


System.Diagnostics.Process.Start("Calc");

run your project click the button windows calculator will show .

No comments:

Post a Comment