> 백엔드 개발 > C#.Net 튜토리얼 > 다른 창을 표시하려면 user32.dll을 호출하세요.

다른 창을 표시하려면 user32.dll을 호출하세요.

PHP中文网
풀어 주다: 2017-06-17 16:35:15
원래의
1825명이 탐색했습니다.
<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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿