問題
使用 API 變更另一程式的標題
解決方法
public static class SystemMenuExtendMethod { //以下為api函式 [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern bool SetWindowText(IntPtr hwnd, String lpString); [DllImport("user32.dll", EntryPoint = "FindWindow")] public static extern int FindWindow(string lpClassName, string lpWindowName); //變更目標視窗的TITLE public static void SetWindowText(string titlename ,string titlemsg) { //SetWindowText(form.Handle, title); Process[] processes = Process.GetProcesses(); List windowHandles = new List(); foreach (Process process in processes) { if (process.MainWindowTitle == titlename) { //windowHandles.Add(process.Handle); SetWindowText((IntPtr)_processname, titlemsg); break; } } } //變更自己本身的TITLE public static void SetThisWindowText(Form form, string titlemsg) { SetWindowText(form.Handle, titlemsg); } int _processname = FindWindow(process.MainProcessName.ToString(), null); }
沒有留言:
張貼留言