Maison > développement back-end > Tutoriel C#.Net > Appelez user32.dll pour afficher d'autres fenêtres

Appelez user32.dll pour afficher d'autres fenêtres

PHP中文网
Libérer: 2017-06-17 16:35:15
original
1832 Les gens l'ont consulté
<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>         }
Copier après la connexion

 

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal