-2

What is the easiest and quickest way to open notepad without a border. What I want is to remove the blue markings you see in the image below:

enter image description here

The code I've got so far [Opens notepad]:

Private Sub Button_StartQuiz_Click(sender As Object, e As EventArgs) Handles Button_StartQuiz.Click

    Dim vPID As Object
    vPID = Shell("notepad.exe", vbNormalFocus)

End Sub
Elias Wick
  • 483
  • 6
  • 21
  • 1
    you wouldn't be able to do it directly with .net you would need to use windows dll and see if they allow you to change the window style for an app wasn't designed for that. Worst case scenario you can just create a borderless form with textbox to create your own borderless notepad – Mederic May 17 '17 at 07:14
  • Hey, thanks for the information. Am I not able to just import the windows dll files and use that to manipulate the border of a given window, in this case notepad? Because that is what I am having trouble with. – Elias Wick May 17 '17 at 07:27
  • I have no idea if that is even possible you would need to do the research sorry. – Mederic May 17 '17 at 07:58
  • Can you use a dialog at all? – David May 17 '17 at 13:53

1 Answers1

1

The results here are not perfect, so you may need to mess with the API parameters, but something along these lines (a VB.NET port of this answer) may be close.

Dim p = Process.Start("notepad.exe")
p.WaitForInputIdle()

Dim styles As WindowStyles = GetWindowLong(p.MainWindowHandle, GWL_STYLE)
styles = styles And Not (WindowStyles.WS_CAPTION Or WindowStyles.WS_THICKFRAME Or WindowStyles.WS_MINIMIZE Or WindowStyles.WS_MAXIMIZE Or WindowStyles.WS_SYSMENU)
SetWindowLong(p.MainWindowHandle, GWL_STYLE, styles)

Dim stylesex As ExtendedWindowStyles = GetWindowLong(p.MainWindowHandle, GWL_EXSTYLE)
stylesex = stylesex And Not (ExtendedWindowStyles.WS_EX_DLGMODALFRAME Or ExtendedWindowStyles.WS_EX_CLIENTEDGE Or ExtendedWindowStyles.WS_EX_STATICEDGE)
SetWindowLong(p.MainWindowHandle, GWL_EXSTYLE, stylesex)

SetWindowPos(p.MainWindowHandle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_FRAMECHANGED Or SetWindowPosFlags.SWP_NOMOVE Or SetWindowPosFlags.SWP_NOSIZE Or SetWindowPosFlags.SWP_NOZORDER Or SetWindowPosFlags.SWP_NOOWNERZORDER)


<DllImport("User32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Shared Function GetWindowLong(hWnd As IntPtr, nIndex As Int16) As Int32
End Function

<DllImport("User32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Shared Function SetWindowLong(hWnd As IntPtr, nIndex As Int16, dwNewLong As Int32) As Int32
End Function

<DllImport("User32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Shared Function SetWindowPos(hWnd As IntPtr, hWndInsertAfter As IntPtr, X As Int16, Y As Int16, cx As Int16, cy As Int16, uFlags As UInt16) As Boolean
End Function

Const GWL_STYLE As Int16 = -16
Const GWL_EXSTYLE As Int16 = -20

<Flags>
Enum WindowStyles
    WS_CAPTION = &HC00000
    WS_THICKFRAME = &H40000
    WS_MINIMIZE = &H20000000
    WS_MAXIMIZE = &H1000000
    WS_SYSMENU = &H80000
End Enum

<Flags>
Enum ExtendedWindowStyles
    WS_EX_DLGMODALFRAME = &h00000001
    WS_EX_CLIENTEDGE = &h00000200
    WS_EX_STATICEDGE = &h00020000
End Enum

<Flags>
Enum SetWindowPosFlags As UInt16
    SWP_FRAMECHANGED = &h0020
    SWP_NOMOVE = &h0002
    SWP_NOSIZE = &h0001
    SWP_NOZORDER = &h0004
    SWP_NOOWNERZORDER = &h0200
End Enum

The result is a little funky on my PC (the blue is my desktop color), since the menu is still showing and everything has shifted to take up the space occupied by the border, but not expanded to take up the extra room. Maybe different parameters will fix that?

Borderless Notepad.exe

Community
  • 1
  • 1
Mark
  • 8,140
  • 1
  • 14
  • 29