Results 1 to 24 of 24

Thread: Remove the title bar from a Form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    77

    Remove the title bar from a Form

    Do I hear a collective groan of "Oh, no that's been addressed 1000 times". Bear with me please ...
    I have this code to turn off WS_CAPTION and DLGFRAME

    Code:
        ' GWL_STYLE = (-16)
        ' WS_DLGFRAME = &H400000
        ' WS_CAPTION = &HC00000
        SetWindowLong Me.hwnd, -16, GetWindowLong(Me.hwnd, -16) And Not &H400000 And Not &HC00000
    In the IDE, I see exactly what I wanted:
    Name:  1.bmp
Views: 304
Size:  71.0 KB

    After compilation, the Form looks like this:
    Name:  2.bmp
Views: 311
Size:  60.2 KB

    I have spent hours experimenting with other settings like different BorderStyles, different Appearance settings (Flat/3D). But I can't get rid of the mini title bar. Any ideas? TIA, Bob.

    PS. The upper picture was made when the form did not have the focus. When it does, it has the same blue border and blue color under the X as the lower picture, but no title bar.

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,343

    Re: Remove the title bar from a Form

    Hello K4CY,

    Could you explain why you are doing this using an API function call? If it involves a vb6 form simply set the BorderStyle property to none in the properties window. Or is this something you need to do with an externa program or during runtime?

    yours,
    Peter Swinkels

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    77

    Re: Remove the title bar from a Form

    Peter, this is VB6 Form within my application that I want/need shown with no title bar. Why use APIs? If I set the Form BorderStyle = 0 then I can't resize the form. Thanks, Bob.

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,343

    Re: Remove the title bar from a Form

    Quote Originally Posted by K4CY View Post
    Peter, this is VB6 Form within my application that I want/need shown with no title bar. Why use APIs? If I set the Form BorderStyle = 0 then I can't resize the form. Thanks, Bob.
    K4CY,

    I am afraid I have no direct answer for you. It is possbile my "Create Window" or "Window-Scanner-vb6-" projects have code that you could use. They are on my Github page. Perhaps you could add custom mechanisms to resize the window? What kind of application are you trying to build?

    yours,
    Peter Swinkels

  5. #5
    Frenzied Member
    Join Date
    Nov 2017
    Posts
    1,561

    Re: Remove the title bar from a Form

    Quote Originally Posted by K4CY View Post
    Peter, this is VB6 Form within my application that I want/need shown with no title bar. Why use APIs? If I set the Form BorderStyle = 0 then I can't resize the form. Thanks, Bob.
    On the form in question:

    Set the ControlBox property to False
    Make sure the Caption of the Form is empty
    Set the BorderStyle to 2 - Sizable

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,533

    Re: Remove the title bar from a Form

    Well one possible option with no api would be

    Set the border to sizable, blank out the caption, set control box to false. This leaves a sizable border around the form and nothing else. You would have to add your own X button to the top right corner to get the look you want.

    It does not have a place to grab and move it though so that may not work for you

    Edit: Just saw the post above after I submitted this one. Same basic info

  7. #7
    Addicted Member
    Join Date
    Jun 2016
    Location
    Espaņa
    Posts
    245

    Re: Remove the title bar from a Form

    it doesn't work that way.
    The one with the blue border also appears to me.
    Attachment 177914

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    77

    Re: Remove the title bar from a Form

    Thanks for trying ... OptionBase1, Those are the settings I'm using. DataMiser, That doesn't work either. Looks as expected in the IDE, but compiled there's the mini caption bar back. Thanks, Bob.

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,543

    Re: Remove the title bar from a Form

    Problems we have when we try to force windows out of its norm. To indicate a window is sizeable, a sizeable border style is set. Without that border style, then windows doesn't give you the sizing cursor when you move over the edges. To overcome that, one could use logic like this:

    1. True borderless form
    2. Trap the mousemove events for the form
    3. If the mouse is over the form's edges + some buffer, then use SendMessage to trigger sizing

    sample code for proof of concept.
    New project, make form borderless and add command button to form
    Add this code and click on right edge of form to start sizing
    Code:
    Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
    Private Declare Function ReleaseCapture Lib "user32.dll" () As Long
    
    Private Const WM_NCLBUTTONDOWN As Long = &HA1
    Private Const HTLEFT As Long = 10
    Private Const HTRIGHT As Long = 11
    Private Const HTTOP As Long = 12
    Private Const HTTOPLEFT As Long = 13
    Private Const HTTOPRIGHT As Long = 14
    Private Const HTBOTTOM As Long = 15
    Private Const HTBOTTOMLEFT As Long = 16
    Private Const HTBOTTOMRIGHT As Long = 17
    
    Private Sub Command1_Click()
    Unload Me
    End Sub
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If X > Me.ScaleWidth - 60 Then
            ReleaseCapture
            SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTRIGHT, ByVal 0& 
        End If
    End Sub
    This might get you started. Doesn't address the cursor to be displayed, but that is workable too.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,442

    Re: Remove the title bar from a Form

    using this kind of API usually require you to also "refresh" the form to apply it.
    try using the API MoveWindow with bRepaint set to True

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,543

    Re: Remove the title bar from a Form

    Quote Originally Posted by baka View Post
    using this kind of API usually require you to also "refresh" the form to apply it.
    try using the API MoveWindow with bRepaint set to True
    Well, form resize events are triggered
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,543

    Re: Remove the title bar from a Form

    @K4CY

    If the SendMessage option seems to be the ticket, here are a couple suggestions if you don't want to deal with testing whether the mouse is down on the form and whether it is left/right, top/bottom, corners, etc...

    Add an 8 image control array to your form.
    - one across the top of the form with height equal to what you'd like your "border" to be
    - one in top left corner, sized as "border" width/height
    - one in top right corner, similar to left corner
    - do similar actions for the left/right/bottom edges and bottom corners
    - make the corner images have the highest ZOrder (bring to front) vs. the edge images

    For each of those set the MousePointer property to the applicable sizing cursor

    Instead of trapping the mouse down event for the form, trap it for the images. To make the logic better, probably don't want to start sizing until the user clicks and moves the mouse. So a bit more logic is needed there.

    Remember to reposition/resize the image controls, as needed, after the SendMessage call returns
    Last edited by LaVolpe; Jul 12th, 2020 at 01:28 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    77

    Resolved Re: Remove the title bar from a Form

    LaVolpe, that's it, works as expected, with the additional advantage of allowing me to only have horizontal sizing, which was something I'd have to jump through hoops later to achieve. Perfect, thanks, Bob.

    PS. The hardest was trying to remember the vbConstant for an East/West mousepointer.

  14. #14
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,533

    Re: Remove the title bar from a Form

    Quote Originally Posted by K4CY View Post
    Thanks for trying ... OptionBase1, Those are the settings I'm using. DataMiser, That doesn't work either. Looks as expected in the IDE, but compiled there's the mini caption bar back. Thanks, Bob.
    Interesting. I tried it here on this Windows 7 PC and it looks exactly as expected in the IDE and compiled.

  15. #15
    PowerPoster
    Join Date
    Feb 2017
    Posts
    3,219

    Re: Remove the title bar from a Form

    Quote Originally Posted by K4CY View Post
    LaVolpe, that's it, works as expected, with the additional advantage of allowing me to only have horizontal sizing, which was something I'd have to jump through hoops later to achieve. Perfect, thanks, Bob.

    PS. The hardest was trying to remember the vbConstant for an East/West mousepointer.
    You could add a size grip for making more obvious to the user that the form is resizable. Just an idea.

  16. #16
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,442

    Re: Remove the title bar from a Form

    well, I did a try, IDE and compiled, using K4CY code + the movewindow API, and I get a title-less form that is resizable.
    I thought that was what K4CY wanted? without movewindow API it will not work.
    Attachment 177915

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    77

    Re: Remove the title bar from a Form

    baka, I tried your suggestion - MoveWindow with bRepaint True, but same result for me. The IDE looks as expected, but the exe shows still some of the title bar. The only solution I've found so far is to run the exe in XP (SP3) compatibility mode. Thanks, Bob.

  18. #18
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,607

    Re: Remove the title bar from a Form

    You're fighting standard styling. The thin area at the top is there so the user can move the form. It's put there by the OS in vista and above. You should have realized this when running your app in xp mode got rid of it. Your best option is to ignore it since it serves a purpose. If not, run it borderless and manage the mouse cursor and drag areas yourself. You're better off leaving it though.

  19. #19
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,457

    Re: Remove the title bar from a Form

    Is this of any help (from the great Karl E Peterson) -
    http://vb.mvps.org/samples/FormBdr/

  20. #20
    Addicted Member
    Join Date
    Jun 2010
    Posts
    166

    Re: Remove the title bar from a Form

    The download of FormBdr.zip file on the vb.mvps.org site no longer works, url just points back to the page. Anyone have this file archived to share? <assuming there are no legal obstacles or breakage of forum rules) I found a few older topics with the file attached, but clicking on the url just returns a black page.
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  21. #21
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,457

    Re: Remove the title bar from a Form

    Quote Originally Posted by 7edm View Post
    The download of FormBdr.zip file on the vb.mvps.org site no longer works, url just points back to the page. Anyone have this file archived to share? <assuming there are no legal obstacles or breakage of forum rules) I found a few older topics with the file attached, but clicking on the url just returns a black page.
    Yup I have it in my collection. See attached.
    Also attached is a copy of the web page at the time. In .mht format which opens in IE (and FF if you 'install' the extension)
    Attached Files Attached Files

  22. #22
    Addicted Member
    Join Date
    Jun 2010
    Posts
    166

    Re: Remove the title bar from a Form

    Thanks Bobbles, I'm forever grateful
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  23. #23
    Addicted Member
    Join Date
    Jun 2010
    Posts
    166

    Re: Remove the title bar from a Form

    Hmm, didn't solve it for me, but I will open my own topic to demonstrate my issue.
    M$ vs. VB6 = The biggest betrayal and strategic mistake of the century!?

  24. #24
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    321

    Re: Remove the title bar from a Form

    hello that upper edge I would say that it is an error in windows 10, in previous OS this does not happen, the only way I found to eliminate it is with subclassing and with WM_NCCALCSIZE adjust that size making a very unpleasant calculation.

    Anyway maybe for your purpose it is only necessary to disable DWM, only that there is a somewhat thicker border that I could not remove (I also tried to remove the windows themes but the border is still there)
    Code:
    Option Explicit
    Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function DwmSetWindowAttribute Lib "dwmapi.dll" (ByVal hWnd As Long, ByVal dwAttribute As Long, ByRef pvAttribute As Long, ByVal cbAttribute As Long) As Long
    Private Declare Function SetWindowTheme Lib "UxTheme.dll" (ByVal hWnd As Long, ByVal pszSubAppName As Long, ByVal pszSubIdList As Long) As Long
      
    Private Const DWMNCRP_DISABLED = 1
    Private Const DWMNCRP_ENABLED = 2
    Private Const DWMWA_NCRENDERING_POLICY = 2
    
    
    
    Private Sub Form_Load()
        Call DwmSetWindowAttribute(Me.hWnd, DWMWA_NCRENDERING_POLICY, DWMNCRP_DISABLED, 4)
        SetWindowLong Me.hWnd, -16, GetWindowLong(Me.hWnd, -16) And Not &H400000 And Not &HC00000
    End Sub
    
    Private Sub Command1_Click()
        Unload Me
    End Sub
    leandroascierto.com Visual Basic 6 projects

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width