Advertisement
Guest User

Untitled

a guest
Dec 30th, 2012
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Runtime.InteropServices
  2.  
  3. Public Class WindowTopmost
  4.     <DllImport("user32.dll", SetLastError:=True)> _
  5.  Private Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, _
  6.                                       ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, _
  7.                                       ByVal cy As Integer, ByVal wFlags As Long) As Boolean
  8.     End Function
  9.     '常に手前 引数は対象のウィンドウハンドル
  10.    Public Sub SetWindowTop(ByVal hWnd As Long)
  11.         Const HWND_TOPMOST = -&H1 '常に最前面
  12.        Const SWP_NOSIZE = &H1    'サイズ変更しない
  13.        Const SWP_NOMOVE = &H2    '位置変更しない
  14.  
  15.         Call SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
  16.  
  17.     End Sub
  18.     '常に手前を解除 引数は対象のウィンドウハンドル
  19.    Public Sub CancelWindowTop(ByVal hWnd As Long)
  20.         Const HWND_NOTOPMOST = -&H2
  21.         Const SWP_NOSIZE = &H1       'サイズ変更しない
  22.        Const SWP_NOMOVE = &H2       '位置変更しない
  23.        Const SWP_SHOWWINDOW = &H40  'ウィンドウを表示
  24.  
  25.         Call SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE Or SWP_SHOWWINDOW)
  26.  
  27.     End Sub
  28.  
  29. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement