Form wintout border icon missing

Form wintout border icon missing

Post by Gani Gu » Sat, 20 Oct 2001 19:01:34



Hi,

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

Thanks,
Guy

 
 
 

Form wintout border icon missing

Post by Rocky Clar » Sat, 20 Oct 2001 20:06:02


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:
Option Explicit

Private Type Rect
    Left    As Long
    Top     As Long
    Right   As Long
    Bottom  As Long
End Type

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) / _
        Screen.TwipsPerPixelX
    '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
        With rcBox
            '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.
        End With
    End If

End Sub

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)


Quote:> Hi,

> 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

> Thanks,
> Guy


 
 
 

Form wintout border icon missing

Post by Tom E » Sun, 21 Oct 2001 00:55:13


It's not always obvious which Api window styles, etc. VB is
manipulating when you change borderstyle & other props, but with a bit
of experimentation it's usually just a matter timing and/or changing
them yourself with the Api. In this case set the BorderStyle to
FixedSingle and remove the WS_CAPTION style at runtime. Follow up with
a call to SetWindowPos and include the SWP_FRAMECHANGED flag to force
the NC repaint.

Private Sub Form_Load()
        SetWindowLong Me.hwnd, GWL_STYLE, _
                (GetWindowLong(Me.hwnd, GWL_STYLE) And (Not WS_CAPTION))

        SetWindowPos Me.hwnd, 0, 0, 0, 0, 0, _
                SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOZORDER

        Me.Show
End Sub

On Fri, 19 Oct 2001 12:01:34 +0200, "Gani Guy"


>Hi,

>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

>Thanks,
>Guy

-Tom
(please post replies to the newsgroup)
 
 
 

Form wintout border icon missing

Post by Gani Gu » Tue, 23 Oct 2001 20:36:10


Thanks, that's what I was looking for.

I have another question,
When I maximize the form, there is a gap above the top of the form with the
size of the form title bar. also the form size, is a little bit too small
then the original size.
Is there any way to resolve those issues ?

Guy


> 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:
> Option Explicit

> Private Type Rect
>     Left    As Long
>     Top     As Long
>     Right   As Long
>     Bottom  As Long
> End Type

> 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) / _
>         Screen.TwipsPerPixelX
>     '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
>         With rcBox
>             '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.
>         End With
>     End If

> End Sub

> 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)



> > Hi,

> > 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

> > Thanks,
> > Guy

 
 
 

1. icon missing on minimize form!

I miss my icon when I minimize my form. Strange is : in my computer
(Pentium 400 Mhz) everything fine, but on other no-name computers &
laptops in my company I see plain blue square instead of my icon on the
taskbar  when I minimize my form. I already update ComCtl32.dll on all
of that computers and it does not help me.  Any suggestion or ideas will
be really appreciated.
  Thanks in advance, Vitaliy Krasner

2. newbie dvd movie factory question please help!!!!

3. How do I get the size of form borders and title bar on a form

4. The new HTMLDirectory.com free cgi scripts + more

5. Missing Icons and images - Still missing

6. ABUSERe: Powerful Technique 9306

7. Form Icon - How to get small icon

8. Extract icon from dll into form.icon

9. Missing border

10. How can I draw the windows form border ?

11. Remove form borders through api

12. Forms and custom borders, titlebar, toolbar etc.