dcandygmailcom

TopMost.exe sets a window on top or not

Feb 15th, 2019
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.78 KB | None | 0 0
  1. REM TopMost.bat
  2. REM This file compiles TopMost.vb to TopMost.exe
  3. REM TopMost.exe sets a window on top or not
  4. REM To use
  5. REM TopMost Top <Windowtitle>
  6. REM TopMost Not <Windowtitle>
  7. REM E.G.
  8. REM TopMost Top Untitled - Notepad
  9. "C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:winexe /out:"%~dp0\TopMost.exe" "%~dp0\TopMost.vb" /verbose
  10. pause
  11.  
  12. --------------------------------------------------
  13.  
  14. 'TopMost.vb
  15. Imports System
  16. Imports System.IO
  17. Imports System.Runtime.InteropServices
  18. Imports Microsoft.Win32
  19.  
  20. Public Module TopMost
  21.     Public Declare UNICODE Function FindWindowW Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
  22.     Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As IntPtr, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
  23.     Public Const HWND_TOPMOST = -1
  24.     Public Const SWP_NOMOVE = &H2
  25.     Public Const SWP_NOSIZE = &H1
  26.     Public Const HWND_NOTOPMOST = -2
  27.  
  28.  
  29.     Sub Main()
  30.         On Error Resume Next
  31.         Dim hWindows as IntPtr
  32.         Dim CmdLine as String
  33.         Dim Ret as Integer
  34.         CmdLine = Mid(Command(),5)
  35.         hwindows = FindWindowW(vbNullString, CmdLine)
  36.         If hwindows = 0 then
  37.             Msgbox(Cmdline & " cannot be found.")
  38.         Else
  39.             If LCase(Left(Command(), 3)) = LCase("Top") then
  40.                 Ret = SetWindowPos(hwindows, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE)
  41.                 If Ret = 0 Then MsgBox("Set Pos Error is " & Err.LastDllError)
  42.             ElseIf LCase(Left(Command(), 3)) = LCase("Not") then
  43.                 Ret = SetWindowPos(hwindows, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE)
  44.                 If Ret = 0 Then MsgBox("Set Pos Error is " & Err.LastDllError)
  45.             Else
  46.                 Msgbox("Command line not recognised")
  47.             End If
  48.         End If
  49.     End Sub
  50. End Module
Advertisement
Add Comment
Please, Sign In to add comment