Results 1 to 28 of 28

Thread: The titlebar with different colors

  1. #1

    Thread Starter
    Addicted Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    149

    The titlebar with different colors

    As attached, the Titlebar of MDIForm and MDIChild are different. How do you standardize?
    Attached Images Attached Images  

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,288

    Re: The titlebar with different colors

    Normally you would leave the settings for those at default so they take on what ever theme the user has selected. On my system they are both the same on all the programs I have created.

    I notice you have blue buttons on the child and grey on the midi and one of the blue buttons is a different shade from the others so it looks like you are overriding the theme somewhere.

  3. #3

    Thread Starter
    Addicted Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    149

    Re: The titlebar with different colors

    I notice you have blue buttons on the child and grey on the midi and one of the blue buttons is a different shade from the others so it looks like you are overriding the theme somewhere.
    Actually the buttons and other controls are my ocx controls ...

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

    Re: The titlebar with different colors

    I think the question is why is the MDI child form's non-client area (titlebar, borders, etc) drawn different than a normal form? Visual appearance isn't the only thing that is different. For example, what happens when your right click on the child title bar? And now when you right click on the MDI titlebar or any non-child form's titlebar?

    Unless someone already tested this by creating dynamic API MDI child forms, it simply looks like VB custom draws the non-client area. If that rendering is how API MDI children look also-- then wow, what a visual goof-up by Microsoft, in my opinion.
    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}

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    21,453

    Re: The titlebar with different colors

    I think it is as simple as MDI being deprecated, and the plumbing that implements it just not being updated. They keep it working but that's about it.

    You see the same thing in C++ and Delphi programs. I don't think any of this is VB-specific.

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

    Re: The titlebar with different colors

    I assume the image is under Windows 10 given the flat appearance.

    I tested mine on this machine which is windows 7 running classic theme and both the parent and child title bars are the same gradient blue. no difference between the two.

    I just tried the same program on my Windows 10 machine and see the different colors on the title bars. Looks a lot better in Windows 7.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    21,453

    Re: The titlebar with different colors

    It isn't just the colors, MDI Child windows also still get the antique-looking Aero styling.

  8. #8
    PowerPoster
    Join Date
    Feb 2017
    Posts
    2,582

    Re: The titlebar with different colors

    I don't know what is behind, but it seems that Windows (at least Windows 10) has two ways for painting the non client area.

    Try this code:
    Code:
    Private Declare Function PrintWindow Lib "user32" (ByVal hWnd As Long, ByVal hdcBlt As Long, ByVal nFlags As Long) As Long
    
    Private Sub Command1_Click()
        AutoRedraw = True
        PrintWindow hWnd, hDC, 0
        Refresh
    End Sub

  9. #9
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    274

    Re: The titlebar with different colors

    hello it is not possible to apply the style to the child windows, the only solution and not the most beautiful is to eliminate the style in the parent window

    Code:
    Option Explicit
    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 Const DWMNCRP_DISABLED = 1
    Private Const DWMNCRP_ENABLED = 2
    Private Const DWMWA_NCRENDERING_POLICY = 2
    
    Private Sub MDIForm_Load()
        Call DwmSetWindowAttribute(hWnd, DWMWA_NCRENDERING_POLICY, DWMNCRP_DISABLED, 4)
    End Sub
    leandroascierto.com Visual Basic 6 projects

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

    Re: The titlebar with different colors

    Quote Originally Posted by LeandroA View Post
    hello it is not possible to apply the style to the child windows, the only solution and not the most beautiful is to eliminate the style in the parent window
    Definitely an option for MDI applications. That at least makes the child & parent have the same non-client look. Unfortunately, but now neither are themed. It's a shame we can't apply some API to the child window to make it themed. It is probably the WS_CHILD or WS_EX_MDICHILD style bit that is the reason?
    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}

  11. #11

    Thread Starter
    Addicted Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    149

    Re: The titlebar with different colors

    the best is standardization ....

  12. #12

    Thread Starter
    Addicted Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    149

    Re: The titlebar with different colors

    If it were possible to get the color of the MDI window then I could paint the color of the child window the same color ...

  13. #13

    Thread Starter
    Addicted Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    149

    Re: The titlebar with different colors

    Quote Originally Posted by LaVolpe View Post
    Definitely an option for MDI applications. That at least makes the child & parent have the same non-client look. Unfortunately, but now neither are themed. It's a shame we can't apply some API to the child window to make it themed. It is probably the WS_CHILD or WS_EX_MDICHILD style bit that is the reason?
    stackoverflow.com/questions/31185594/custom-title-bar-color-for-native-c-app-on-windows-10

    Does the link answer the question?

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

    Re: The titlebar with different colors

    Just a question of curiosity. Not sure why it's important that the titlebars are the same gradient/color when other things like the min/max/restore buttons are completely different, as are the borders?
    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}

  15. #15

    Thread Starter
    Addicted Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    149

    Re: The titlebar with different colors

    stackoverflow.com/questions/37774307/c-get-windows-8-1-10-selected-color-theme


    Code:
    public class ThemeInfo
    {
        [DllImport("uxtheme.dll", EntryPoint = "#95")]
        public static extern uint GetImmersiveColorFromColorSetEx(uint dwImmersiveColorSet, uint dwImmersiveColorType, bool bIgnoreHighContrast, uint dwHighContrastCacheMode);
        [DllImport("uxtheme.dll", EntryPoint = "#96")]
        public static extern uint GetImmersiveColorTypeFromName(IntPtr pName);
        [DllImport("uxtheme.dll", EntryPoint = "#98")]
        public static extern int GetImmersiveUserColorSetPreference(bool bForceCheckRegistry, bool bSkipCheckOnFail);
    
        public Color GetThemeColor()
        {
            var colorSetEx = GetImmersiveColorFromColorSetEx(
                (uint)GetImmersiveUserColorSetPreference(false, false),
                GetImmersiveColorTypeFromName(Marshal.StringToHGlobalUni("ImmersiveStartSelectionBackground")),
                false, 0);
    
            var colour = Color.FromArgb((byte)((0xFF000000 & colorSetEx) >> 24), (byte)(0x000000FF & colorSetEx),
                (byte)((0x0000FF00 & colorSetEx) >> 8), (byte)((0x00FF0000 & colorSetEx) >> 16));
    
            return colour;
        }
    }
    This code returns the color of the title bar, but it is in a language I don't know

  16. #16

    Thread Starter
    Addicted Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    149

    Re: The titlebar with different colors

    Quote Originally Posted by LaVolpe View Post
    Just a question of curiosity. Not sure why it's important that the titlebars are the same gradient/color when other things like the min/max/restore buttons are completely different, as are the borders?
    I don't know if I understood correctly, but is it to discern each other?

  17. #17
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    274

    Re: The titlebar with different colors

    if you really want to complicate your life I invite you to try this
    http://leandroascierto.com/blog/skins-para-formularios/
    leandroascierto.com Visual Basic 6 projects

  18. #18
    PowerPoster
    Join Date
    Feb 2006
    Posts
    21,453

    Re: The titlebar with different colors

    I got this far, but then got stuck:

    Name:  sshot.png
Views: 144
Size:  3.0 KB

    Code:
    SetWindowTheme .hWnd, WIN32_NULL, StrPtr("WindowStyle")
    Did that on each child Form as each instance is created.

    Sort of works, but the non-client buttons don't get painted (yet they work), Form borders are the wrong width, etc.

    Suggests it may still be possible with a lot more theming calls.

  19. #19

    Thread Starter
    Addicted Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    149

    Re: The titlebar with different colors

    Quote Originally Posted by LeandroA View Post
    if you really want to complicate your life I invite you to try this
    http://leandroascierto.com/blog/skins-para-formularios/
    If the symptoms persist it is better to invest in a good skin ... as long as it does not result in a breakdown in win10 ...

  20. #20
    Hyperactive Member
    Join Date
    Aug 2016
    Posts
    282

    Re: The titlebar with different colors

    Quote Originally Posted by LaVolpe View Post
    Definitely an option for MDI applications. That at least makes the child & parent have the same non-client look. Unfortunately, but now neither are themed. It's a shame we can't apply some API to the child window to make it themed. It is probably the WS_CHILD or WS_EX_MDICHILD style bit that is the reason?
    Different theme of titlebar seems to identify whether it is normal window or Child window on win10. On Win7, turn off theme, they are the same.

  21. #21

    Thread Starter
    Addicted Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    149

    Re: The titlebar with different colors

    Quote Originally Posted by LaVolpe View Post
    Just a question of curiosity. Not sure why it's important that the titlebars are the same gradient/color when other things like the min/max/restore buttons are completely different, as are the borders?
    https://social.msdn.microsoft.com/Fo...forum=winforms

    I found this ... but I don't know any dialect other than vb6

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

    Re: The titlebar with different colors

    The article is suggesting trapping WM_NCPAINT and filling the title bar with a solid color. Find VB examples that subclass WM_NCPAINT. I would think simply searching for WM_NCPAINT as a key word should get you started.

    Subclassing to change the non-client (NC in the WM_NCPAINT) is not a trivial exercise with VB.
    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}

  23. #23
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    6,482

    Re: The titlebar with different colors

    Quote Originally Posted by LaVolpe View Post
    The article is suggesting trapping WM_NCPAINT and filling the title bar with a solid color. Find VB examples that subclass WM_NCPAINT. I would think simply searching for WM_NCPAINT as a key word should get you started.

    Subclassing to change the non-client (NC in the WM_NCPAINT) is not a trivial exercise with VB.
    LaVolpe, I just grabbed your post to quote. However, I've been thinking this every time I look at this thread.

    Episcopal, why don't you just create a borderless MDI child and build your own form to look and behave exactly how you want. It would take a bit of work, but at least it'd be clear what you need to do:

    • Dig out the Windows titlebar color and use it for your custom titlebar.
    • Build little Min, Max, Close buttons that behaved the way you wanted (I'd probably use labels).
    • Build custom side bars for resizing, if you wanted this.
    • Build a "move" ability for your custom titlebar.


    When you got it all done, you could throw it into a class, and then attach the class to your form, using a little "WithEvents" magic to make it all general purpose.

    Heck, such an endeavor would be CodeBank worthy.

    Take Care,
    Elroy

    EDIT1: Just thinking through how I'd do it, I'd make sure to "attach the class" (i.e., instantiate it) in the Form_Initialize event, and not the Form_Load event. If you had the class reference in the form's module level code, that way it'd have the correct lifetime, and you wouldn't need to worry about uninstantiating the class.
    EDIT2: Or even better (than the above), just use the "New" keyword when declaring the class at the form's module level. Ackk, you've still got to somehow tell the class which form it's working with. Form_Initialize, call some method in the class and tell it.

    EDIT3: Just in case you decide to go this route, there are some interesting pages to assist with fetching these colors, such as here or here ... or this is also a helpful page.
    Last edited by Elroy; Aug 9th, 2020 at 03:20 PM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  24. #24
    PowerPoster
    Join Date
    Feb 2006
    Posts
    21,453

    Re: The titlebar with different colors

    Or.. just use MDI as it is.

    Instead of getting hung up on gingerbread, make sure your program has enough useful functionality to outweigh silly skinning.

    You can try to build a Buck Roger's Rocket Ship look and never get off the ground. Or put the engineering into practical needs instead of looks and get to the Moon.

    VB6 is all about getting things done. If you really must be competitive on looks you may as well write it all in C++ from dirt.

  25. #25

    Thread Starter
    Addicted Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    149

    Re: The titlebar with different colors

    Quote Originally Posted by LeandroA View Post
    if you really want to complicate your life I invite you to try this
    http://leandroascierto.com/blog/skins-para-formularios/
    I liked this skin ... however I would have to edit it ... it's just a few details ...

    Attachment 178255

  26. #26
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    274

    Re: The titlebar with different colors

    Quote Originally Posted by Episcopal View Post
    I liked this skin ... however I would have to edit it ... it's just a few details ...

    Attachment 178255
    The Skin Editor
    http://leandroascierto.com/blog/editor/
    leandroascierto.com Visual Basic 6 projects

  27. #27

    Re: The titlebar with different colors

    Add This to a Module:
    Code:
    Declare Function SetSysColors Lib "user32" _
    (ByVal nChanges As Long, lpSysColor As _
    Long, lpColorValues As Long) As Long
     
    Public Const COLOR_CAPTIONTEXT = 9
    And in your form add this:
    Code:
    Private Sub Form_Load()
    'You can change the title bar text color to 
    'anytihng you want by changing the "VbBlack to Whatever you want"
      s = SetSysColors(1, COLOR_CAPTIONTEXT, vbBlack)
    End Sub
     
     
    Private Sub Form_Unload(Cancel As Integer)
    'To set default colors...... (Don't Change or remove this)
      s = SetSysColors(1, COLOR_CAPTIONTEXT, vbWhite)
    'Removing this will make all app's Titlebar text to be that color!!
    End Sub

  28. #28

    Thread Starter
    Addicted Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    149

    Re: The titlebar with different colors

    Quote Originally Posted by Prahlad View Post
    Add This to a Module:
    Code:
    Declare Function SetSysColors Lib "user32" _
    (ByVal nChanges As Long, lpSysColor As _
    Long, lpColorValues As Long) As Long
     
    Public Const COLOR_CAPTIONTEXT = 9
    And in your form add this:
    Code:
    Private Sub Form_Load()
    'You can change the title bar text color to 
    'anytihng you want by changing the "VbBlack to Whatever you want"
      s = SetSysColors(1, COLOR_CAPTIONTEXT, vbBlack)
    End Sub
     
     
    Private Sub Form_Unload(Cancel As Integer)
    'To set default colors...... (Don't Change or remove this)
      s = SetSysColors(1, COLOR_CAPTIONTEXT, vbWhite)
    'Removing this will make all app's Titlebar text to be that color!!
    End Sub
    This code does not work in win10 ...

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