반응형

* VBNET API 윈도우 (Window) 창 찾기 예제...

 

메인화면

전체 소스 코드

Form1.vb

 

Imports System.Runtime.InteropServices

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

    Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Integer) As Integer
    Declare Function ShowWindowAsync Lib "user32" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer


    Private Const SW_WINDOW_NORMAL As Integer = 1
    Private Const SW_WINDOW_MINIMIZED As Integer = 2
    Private Const SW_WINDOW_MAXIMIZED As Integer = 3

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        ' 윈도우 타이틀명으로 핸들을 찾음.
        Dim hWnd As IntPtr = FindWindow(Nothing, TextBox1.Text)

        If Not hWnd.Equals(IntPtr.Zero) Then
            ' 윈도우가 최소화 되어 있다면 활성화 
            ShowWindowAsync(hWnd, SW_WINDOW_NORMAL)

            ' 윈도우에 포커스를 줘서 최상위로 만든다
            SetForegroundWindow(hWnd)
        End If
    End Sub
End Class

* 예제 결과

 

반응형

+ Recent posts