Make a MDI Form borderless

sidnei -1 Tallied Votes 675 Views Share

This code show how to made a MDI Form Borderless.
Tested on Visual Basic 6 under Windows XP SP3 platform.

AndreRet commented: Not enough comments added, no help on how to instigate. -1
'This is the API declaration; I suggest to put it in a module, OR change private to public
Private Declare Function GetWindowLong Lib "USER32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "USER32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

'Constants to make code more readable
Private Const GWL_STYLE = (-16)
Private Const WS_BORDER = &H800000
Private Const WS_CAPTION = &HC00000

'A generic function to make a form borderless
Public Sub RetiraBorda(ByRef nFormHWND As Long)

  Dim nEstilo As Long
  On Error GoTo errRetiraBorda
  nEstilo = GetWindowLong(nFormHWND, GWL_STYLE)
  nEstilo = nEstilo And Not WS_CAPTION
  SetWindowLong nFormHWND, GWL_STYLE, nEstilo

Exit Sub

  MsgBox "Erro na execução da rotina:" & vbNewLine & vbNewLine & Err.Number & " - " & Err.Description, vbExclamation, "RetiraBorda"

End Sub

'The function can be called this way, in the form for example
Private Sub MDIForm_Activate()

  Dim rTela As tCoord
  RetiraBorda Me.hwnd
  rTela = AreaTrabalho
  'Some other code to initialize application

End Sub
labq5 0 Newbie Poster

could you to tell us what your Project Component and Project References
B'cause I get error on descr below

Dim rTela As tCoord

AndreRet 397 Senior Poster

@labq5, There are easier ways to make your form borderless. You do however need to open a new thread of your own. This was only a code snippet from 2009, I doubt it if anyone will answer your question.

I'll reply on your new thread once it is open.:)

sidnei 12 Junior Poster in Training

Hi, labq5

Sorry for this mistake...
tCoord is a structure I define in a module:

Type tCoord
  Left As Long
  Top As Long
  Right As Long
  Bottom As Long
End Type

It holds the information of my desktop bounds, this way I can resize my form to the max available space on the screen without covering the taskbar (if you maximize a borderless form, it will cover the taskbar, and I hate this behaviour!).

The AreaTrabalho function performs the calculation of available desktop area, as I mentioned before.
Here is the code for that function:

Public Function AreaTrabalho() As tCoord
  Dim rCoord As tCoord
  On Error GoTo errAreaTrabalho
  If SystemParametersInfo(48, vbNull, rCoord, 0) Then
    AreaTrabalho = rCoord
  End If
  Exit Function
  MsgBox "Erro na execução da rotina:" & vbNewLine & vbNewLine & Err.Number & " - " & Err.Description, vbExclamation, "AreaTrabalho"
End Function

Both declarations (the structure and the function) are typed in a module, this way it can be used for any form in your application.

In addition, all code showed in the original post can be put in a module, only the piece "MDIForm_Activate()" should be on form's activate event, AND YOU NEED to declare this API function too:

Private Declare Function SystemParametersInfo Lib "USER32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long

(make it on the same module you put the function into)

Hope it helps!

labq5 commented: justiça, de acordo com o que eu esperava. +1
sidnei 12 Junior Poster in Training

Hi, AndreRet!

This is an older post, I agree...
But I reply to it cause I have a extremely dificult to find ANY information on how to put a MDI form borderless.

Do you know a way to do it more simpler? Note that I'm using VB6 under Windows XP, and it's not a common form, but a MDI form, the one that doesn't have the "BorderStyle" property to be set on the properties window...

Can you put a link or piece of code to show how to make this task easier?
I know it's an older thread, but I'm really interested...

Best regards,

AndreRet commented: Seems I'm getting older.:) +6
AndreRet 397 Senior Poster

No problem, I'll post it tomorrow, time for my daily beer.;)

labq5 0 Newbie Poster


I just can say Thank you to @sidnei and @AndreRet, for any enlightenment.
I'll tried.

Best regards,

AndreRet 397 Senior Poster

@Sidnei, seems I'm getting older. Your way is about the quickest and best. I gave you your rep back.;)

anbarasan 0 Newbie Poster

thanks for sharing

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.