調用user32.dll顯示其他視窗

來源:互聯網
上載者:User
 1 /// 該函數設定由不同線程產生的視窗的顯示狀態 2         /// </summary> 3         /// <param name="hWnd">視窗控制代碼</param> 4         /// <param name="cmdShow">指定視窗如何顯示。查看允許值列表,請查閱ShowWlndow函數的說明部分</param> 5         /// <returns>如果函數原來可見,傳回值為非零;如果函數原來被隱藏,傳回值為零</returns> 6         [DllImport("User32.dll")] 7         private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow); 8         /// <summary> 9         ///  該函數將建立指定視窗的線程設定到前台,並且啟用該視窗。鍵盤輸入轉向該視窗,並為使用者改各種可視的記號。10         ///  系統給建立前台視窗的線程分配的許可權稍高於其他線程。 11         /// </summary>12         /// <param name="hWnd">將被啟用並被調入前台的視窗控制代碼</param>13         /// <returns>如果視窗設入了前台,傳回值為非零;如果視窗未被設入前台,傳回值為零</returns>14         [DllImport("User32.dll")]15         private static extern bool SetForegroundWindow(IntPtr hWnd);16 17 private void BringToFront(IntPtr hWnd)18         {19             //Process currentProcess = Process.GetCurrentProcess();20             //Process process = Process.get(id);21             //if (process != null)22             //{23             //    ShowWindowAsync(process.MainWindowHandle, 1);//顯示24             //    SetForegroundWindow(process.MainWindowHandle);//當到最前端25             //}26             Process[] Processes = Process.GetProcesses();// GetProcessesByName(currentProcess.ProcessName);27             foreach (Process process in Processes)28             {29                 //process.Start();30                 //if (process.Id != currentProcess.Id)31                 //{32                 //                    if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\")33                 //<span style="white-space:pre">            </span> == currentProcess.MainModule.FileName)34                 //                    {35                 //                        return process;36                 //                    }37                 if (process.MainWindowHandle.ToString() == "0")38                 {39                     continue;40                 }41                 if (process.MainWindowHandle == hWnd)42                 {43                     ShowWindowAsync(process.MainWindowHandle, 1);//顯示44                     SetForegroundWindow(process.MainWindowHandle);//當到最前端45                 }46                 //}47             }48         }

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.