Some APIs used in a recent project are useful in solving some practical problems (especially dealing with external programs. Specific parameters are available online!
Code
// Set the top form to [DllImport ("user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = true)]
Private static extern bool SetForegroundWindow (IntPtr hwnd );
// Find the form. Generally, you can obtain the form handle to facilitate subsequent operations.
[DllImport ("user32.dll")]
Public static extern IntPtr FindWindow (string className, string title );
// Display the form (including minimizing and maximizing the form)
[DllImport ("user32.dll")]
Public static extern bool ShowWindow (IntPtr hwnd, int cmdshow );
// Obtain the position of the form (relative to the entire screen)
[DllImport ("user32.dll")]
Public static extern int GetWindowRect (IntPtr hwnd, ref Rectangle rc );
// Mouse click event
Private readonly int MOUSEEVENTF_LEFTDOWN = 0x2;
Private readonly int MOUSEEVENTF_LEFTUP = 0x4;
[DllImport ("user32")]
Public static extern void mouse_event (int dwFlags, int dx, int dy, int dwData, int dwExtraInfo );
// Set the mouse position, which is generally used with mouse_event
[DllImport ("user32.dll")]
Static extern bool SetCursorPos (int X, int Y );
// Obtain the cursor position
[DllImport ("user32.dll")]
Static extern bool GetCursorPos (ref Point lpPoint );
// Set the location of the form
[DllImport ("user32.dll", EntryPoint = "SetWindowPos")]
Public static extern IntPtr SetWindowPos (IntPtr hWnd, int <