반응형

* C# API 를 이용해 해당 윈도우 폼(Window Form) 을 찾아서 최상위 윈도우로 포커스(Focus) 맞추기 예제...

 

메인 화면

 

전체 소스 코드

Form1.vb

 

Imports System.Runtime.InteropServices

Public Class Form1

    'API 선언...
    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function FindWindow( _
     ByVal lpClassName As String, _
     ByVal lpWindowName As String) As IntPtr
    End Function

    <DllImport("user32.dll")> _
    Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
     Private Shared Function ShowWindowAsync(ByVal hwnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
    End Function

    '윈도우 상태...
    Const SHOWHIDE As Integer = 0
    Const SHOWNORMAL As Integer = 1
    Const SHOWMINIMIZED As Integer = 2
    Const SHOWMAXIMIZED As Integer = 3

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

        Dim ipHandle As IntPtr = FindWindow(Nothing, textBox1.Text)

        '해당 윈도우를 찾았으면...
        If Not ipHandle.Equals(IntPtr.Zero) Then

            '해당 윈도우가 최소화 되어 있으면 노멀로 변경...
            ShowWindowAsync(ipHandle, SHOWNORMAL)

            '해당 윈도우에 포커스를 줘서 최상위로 올리기...
            SetForegroundWindow(ipHandle)

        End If

    End Sub

End Class

*예제 결과

 

결과 화면

 

https://kdsoft-zeros.tistory.com/108

 

[VBNET] [API] 윈도우 창 찾기 (Window Form Search)

* VBNET API 윈도우 (Window) 창 찾기 예제... 전체 소스 코드 Form1.vb Imports System.Runtime.InteropServices Public Class Form1 <dllimport("user32.dll", setlasterror:="True," charset:="CharSet.Auto)"> _..</dllimport("user32.dll",>

kdsoft-zeros.tistory.com

 

반응형

+ Recent posts