Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll", SetLastError:=True)> _
Public Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal W As Integer, ByVal H As Integer, _
ByVal uFlags As UInteger) As Boolean
End Function
<DllImport("USER32.DLL", CharSet:=CharSet.Unicode)> _
Public Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hwnd As IntPtr = FindWindow(Nothing, "Калькулятор")
If hwnd = IntPtr.Zero Then
MsgBox("Calculator not found")
Else
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
End If
End Sub
End Class |