Monday 25 May 2020

HideWindow Hides an existing window or shows a hidden window.

This uses the inbuilt compilers in Windows 10 - there are three VB.NET compilers and three C# compilers - just copy each text file into the same folder and double click the batch file to make the program.
Window Manipulation Posts

@Echo Off
Echo HideWindow.bat
Echo This file compiles HideWindow.vb to HideWindow.exe
Echo HideWindow.exe hide or shows a window
Echo To use 
Echo     HideWindow Hide ^<Window Title^>
Echo     HideWindow Show ^<Window Title^>
Echo E.G.
Echo     HideWindow Hide Untitled - Notepad
Echo     HideWindow Show Untitled - Notepad
Echo -----------------------------------------------------
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:winexe /out:"%~dp0\HideWindow.exe" "%~dp0\HideWindow.vb" 
pause


'HideWindow.vb
Imports System
Imports System.IO
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Public Module TopMost
 Public Declare UNICODE Function FindWindowW Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
 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
 Public Const HWND_TOPMOST = -1
 Public Const HWND_NOTOPMOST = -2
 Public Const SWP_NOMOVE = &H2
 Public Const SWP_NOSIZE = &H1
 Public Const SWP_SHOWWINDOW = &H40
 Public Const SWP_HIDEWINDOW = &H80
 Public Const SWP_NOOWNERZORDER = &H200      '  Don't do owner Z ordering
 Public Const SWP_NOREDRAW = &H8
 Public Const SWP_NOREPOSITION = &H200
 Public Const SWP_NOZORDER = &H4

 Sub Main()
  On Error Resume Next
  Dim hWindows as IntPtr
  Dim CmdLine as String
  Dim Ret as Integer
  CmdLine = Mid(Command(),6)
  hwindows = FindWindowW(vbNullString, CmdLine)
  If hwindows = 0 then
   Msgbox(Cmdline & " cannot be found.")
  Else
   If LCase(Left(Command(), 4)) = LCase("Hide") then
    Ret = SetWindowPos(hwindows, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_NOZORDER + SWP_HIDEWINDOW)
    If Ret = 0 Then MsgBox("Set Pos Error is " & Err.LastDllError)
   ElseIf LCase(Left(Command(), 4)) = LCase("Show") then
    Ret = SetWindowPos(hwindows, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_NOZORDER + SWP_SHOWWINDOW)
    If Ret = 0 Then MsgBox("Set Pos Error is " & Err.LastDllError)
   Else
    Msgbox("Command line not recognised")
   End If
  End If
 End Sub
End Module

No comments:

Post a Comment