視窗句柄 4 /// 指定視窗如何顯示。查看允許值列表,請查閱ShowWlndow函數的說明部分"/> 視窗句柄 4 /// 指定視窗如何顯示。查看允許值列表,請查閱ShowWlndow函數的說明部分">

首頁  >  文章  >  後端開發  >  呼叫user32.dll顯示其他窗口

呼叫user32.dll顯示其他窗口

PHP中文网
PHP中文网原創
2017-06-17 16:35:151782瀏覽
<span style="color: #008080"> 1</span> <span style="color: #808080">///</span><span style="color: #008000"> 该函数设置由不同线程产生的窗口的显示状态
</span><span style="color: #008080"> 2</span>         <span style="color: #808080">///</span> <span style="color: #808080"></summary></span>
<span style="color: #008080"> 3</span>         <span style="color: #808080">///</span> <span style="color: #808080"><param name="hWnd"></span><span style="color: #008000">窗口句柄</span><span style="color: #808080"></param></span>
<span style="color: #008080"> 4</span>         <span style="color: #808080">///</span> <span style="color: #808080"><param name="cmdShow"></span><span style="color: #008000">指定窗口如何显示。查看允许值列表,请查阅ShowWlndow函数的说明部分</span><span style="color: #808080"></param></span>
<span style="color: #008080"> 5</span>         <span style="color: #808080">///</span> <span style="color: #808080"><returns></span><span style="color: #008000">如果函数原来可见,返回值为非零;如果函数原来被隐藏,返回值为零</span><span style="color: #808080"></returns></span>
<span style="color: #008080"> 6</span>         [DllImport(<span style="color: #800000">"</span><span style="color: #800000">User32.dll</span><span style="color: #800000">"</span><span style="color: #000000">)]
</span><span style="color: #008080"> 7</span>         <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">extern</span> <span style="color: #0000ff">bool</span> ShowWindowAsync(IntPtr hWnd, <span style="color: #0000ff">int</span><span style="color: #000000"> cmdShow);
</span><span style="color: #008080"> 8</span>         <span style="color: #808080">///</span> <span style="color: #808080"><summary></span>
<span style="color: #008080"> 9</span>         <span style="color: #808080">///</span><span style="color: #008000">  该函数将创建指定窗口的线程设置到前台,并且激活该窗口。键盘输入转向该窗口,并为用户改各种可视的记号。
</span><span style="color: #008080">10</span>         <span style="color: #808080">///</span><span style="color: #008000">  系统给创建前台窗口的线程分配的权限稍高于其他线程。 
</span><span style="color: #008080">11</span>         <span style="color: #808080">///</span> <span style="color: #808080"></summary></span>
<span style="color: #008080">12</span>         <span style="color: #808080">///</span> <span style="color: #808080"><param name="hWnd"></span><span style="color: #008000">将被激活并被调入前台的窗口句柄</span><span style="color: #808080"></param></span>
<span style="color: #008080">13</span>         <span style="color: #808080">///</span> <span style="color: #808080"><returns></span><span style="color: #008000">如果窗口设入了前台,返回值为非零;如果窗口未被设入前台,返回值为零</span><span style="color: #808080"></returns></span>
<span style="color: #008080">14</span>         [DllImport(<span style="color: #800000">"</span><span style="color: #800000">User32.dll</span><span style="color: #800000">"</span><span style="color: #000000">)]
</span><span style="color: #008080">15</span>         <span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">extern</span> <span style="color: #0000ff">bool</span><span style="color: #000000"> SetForegroundWindow(IntPtr hWnd);
</span><span style="color: #008080">16</span> 
<span style="color: #008080">17</span> <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span><span style="color: #000000"> BringToFront(IntPtr hWnd)
</span><span style="color: #008080">18</span> <span style="color: #000000">        {
</span><span style="color: #008080">19</span>             <span style="color: #008000">//</span><span style="color: #008000">Process currentProcess = Process.GetCurrentProcess();
</span><span style="color: #008080">20</span>             <span style="color: #008000">//</span><span style="color: #008000">Process process = Process.get(id);
</span><span style="color: #008080">21</span>             <span style="color: #008000">//</span><span style="color: #008000">if (process != null)
</span><span style="color: #008080">22</span>             <span style="color: #008000">//</span><span style="color: #008000">{
</span><span style="color: #008080">23</span>             <span style="color: #008000">//</span><span style="color: #008000">    ShowWindowAsync(process.MainWindowHandle, 1);</span><span style="color: #008000">//</span><span style="color: #008000">显示
</span><span style="color: #008080">24</span>             <span style="color: #008000">//</span><span style="color: #008000">    SetForegroundWindow(process.MainWindowHandle);</span><span style="color: #008000">//</span><span style="color: #008000">当到最前端
</span><span style="color: #008080">25</span>             <span style="color: #008000">//</span><span style="color: #008000">}</span>
<span style="color: #008080">26</span>             Process[] Processes = Process.GetProcesses();<span style="color: #008000">//</span><span style="color: #008000"> GetProcessesByName(currentProcess.ProcessName);</span>
<span style="color: #008080">27</span>             <span style="color: #0000ff">foreach</span> (Process process <span style="color: #0000ff">in</span><span style="color: #000000"> Processes)
</span><span style="color: #008080">28</span> <span style="color: #000000">            {
</span><span style="color: #008080">29</span>                 <span style="color: #008000">//</span><span style="color: #008000">process.Start();
</span><span style="color: #008080">30</span>                 <span style="color: #008000">//</span><span style="color: #008000">if (process.Id != currentProcess.Id)
</span><span style="color: #008080">31</span>                 <span style="color: #008000">//</span><span style="color: #008000">{
</span><span style="color: #008080">32</span>                 <span style="color: #008000">//</span><span style="color: #008000">                    if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\")
</span><span style="color: #008080">33</span>                 <span style="color: #008000">//</span><span style="color: #008000"><span style="white-space:pre">            </span> == currentProcess.MainModule.FileName)
</span><span style="color: #008080">34</span>                 <span style="color: #008000">//</span><span style="color: #008000">                    {
</span><span style="color: #008080">35</span>                 <span style="color: #008000">//</span><span style="color: #008000">                        return process;
</span><span style="color: #008080">36</span>                 <span style="color: #008000">//</span><span style="color: #008000">                    }</span>
<span style="color: #008080">37</span>                 <span style="color: #0000ff">if</span> (process.MainWindowHandle.ToString() == <span style="color: #800000">"</span><span style="color: #800000">0</span><span style="color: #800000">"</span><span style="color: #000000">)
</span><span style="color: #008080">38</span> <span style="color: #000000">                {
</span><span style="color: #008080">39</span>                     <span style="color: #0000ff">continue</span><span style="color: #000000">;
</span><span style="color: #008080">40</span> <span style="color: #000000">                }
</span><span style="color: #008080">41</span>                 <span style="color: #0000ff">if</span> (process.MainWindowHandle ==<span style="color: #000000"> hWnd)
</span><span style="color: #008080">42</span> <span style="color: #000000">                {
</span><span style="color: #008080">43</span>                     ShowWindowAsync(process.MainWindowHandle, <span style="color: #800080">1</span>);<span style="color: #008000">//</span><span style="color: #008000">显示</span>
<span style="color: #008080">44</span>                     SetForegroundWindow(process.MainWindowHandle);<span style="color: #008000">//</span><span style="color: #008000">当到最前端</span>
<span style="color: #008080">45</span> <span style="color: #000000">                }
</span><span style="color: #008080">46</span>                 <span style="color: #008000">//</span><span style="color: #008000">}</span>
<span style="color: #008080">47</span> <span style="color: #000000">            }
</span><span style="color: #008080">48</span>         }

 

以上是呼叫user32.dll顯示其他窗口的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn