This is by design when you remove the titlebar from a form. The following
code is a workaround for this. To use this code, set your Form's BorderStyle
to something other than 0-None. Copy the code to the form and run it.
'Form's Declaration Section:
Private Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
Private Declare Function GetClientRect Lib "user32" _
(ByVal hWnd As Long, lpRect As Rect) As Long
Private Declare Function CreateRectRgn Lib "gdi32" _
(ByVal X1 As Long, ByVal Y1 As Long, _
ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" _
(ByVal hWnd As Long, ByVal hRgn As Long, _
ByVal bRedraw As Boolean) As Long
Private Sub Form_Load()
Dim lOffstX As Long
Dim lOffstY As Long
Dim hRgn As Long
Dim rcBox As Rect
'Calc width of Left border of Form in pixels.
lOffstX = ((Me.Width - Me.ScaleX(Me.ScaleWidth, _
Me.ScaleMode, vbTwips)) / 2) / _
'Calc Height of Top border of Form
'(including the titlebar) in pixels
lOffstY = ((Me.Height - Me.ScaleY(Me.ScaleHeight, _
Me.ScaleMode, vbTwips)) / _
Screen.TwipsPerPixelY) - lOffstX
'Start with the client rect (inside) of the Form.
If GetClientRect(Me.hWnd, rcBox) Then
'Offset the rectangle to exclude the borders.
.Left = .Left + lOffstX
.Top = .Top + lOffstY
.Right = .Right + lOffstX
.Bottom = .Bottom + lOffstY
'Create a region from the rectangle
hRgn = CreateRectRgn(.Left, .Top, .Right, .Bottom)
'Set the Form's window region to this region
Call SetWindowRgn(Me.hWnd, hRgn, True)
'Note: Do not delete this region.
'It is now owned by Windows and Windows
'will destroy it when the Form unloads.
This code simply removes the Form's titlebar and border from it's visible
area. The titlebar still exists, it's just not visible. If you look in the
taskbar at run time, you'll see the caption and icon as expected.
Hope this helps,
Rocky Clark (Kath-Rock Software)
> I have an application with one main form which does not have a border and
> title bar. (BorderStyle = 0).
> The problem that I have is that the form caption in the taskbar does not
> include the project icon, I tried to load the icon manually and it doesn't
> wotk also. The form's caption appears correctlly