- take a new project named - calculatorviewer solution explorer autometically created
- take a button in your form .
- use namespace System.Runtime.InteropServices;
- 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