Results 1 to 35 of 35

Thread: The titlebar with different colors

  1. #1

    Thread Starter
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    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
    14,205

    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
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

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

    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
    24,482

    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
    14,205

    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
    24,482

    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
    5,064

    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
    439

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

    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
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    Re: The titlebar with different colors

    the best is standardization ....

  12. #12

    Thread Starter
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    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
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

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

    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
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    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
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    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
    439

    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
    24,482

    Re: The titlebar with different colors

    I got this far, but then got stuck:

    Name:  sshot.png
Views: 1573
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
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    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
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    603

    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
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

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

    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
    9,937

    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. To all, peace and happiness.

  24. #24
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    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
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    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
    439

    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
    Lively Member
    Join Date
    Jan 2020
    Posts
    120

    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
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

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

  29. #29
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    Re: The titlebar with different colors

    Quote Originally Posted by Episcopal View Post
    As attached, the Titlebar of MDIForm and MDIChild are different. How do you standardize?
    normally,windows (xp to 11) cant appl DWM.exe to childs because those windowses are in other type (in execute not in vb)
    we cant see this on xp because non dwm and dwm is same themed but in vista(i hate it) to 11,they re not same
    Basic page
    Text

  30. #30
    Member Taro's Avatar
    Join Date
    Feb 2014
    Posts
    33

    Re: The titlebar with different colors

    I found this website. It very valuable information. Check this out. https://leandroascierto.com/blog/ski...a-formularios/

  31. #31
    Addicted Member ISAWHIM's Avatar
    Join Date
    Jan 2023
    Posts
    181

    Re: The titlebar with different colors

    Just adding here...

    Windows changed the code for display of title-bars and the OCX no longer works correctly. Microsoft stated, in various posts, that they have no intention of "updating that OCX". It will no longer work as desired, even with API.

    Solution: Make your own title-bar and the problem is solved. Make it an OCX, if desired, so you can just replace it in any form. However, it will now be within the "client area", but API can trick that, if needed.

    You can hijack the settings for the actual title-bar, and adopt them into the one you make.

    Windows created the "title-bar", which is actually the real "form", which has a "sub-form", within it, which we are tricked into knowing as the "client area form". That primary container, which is the shell of a program/form, is never truly "gone", when it is hidden. It is always there and just reduced to match the frame of the "client area", unless you select borderless form also. So every aspect of the title-bar should always be available, at all times, even when unseen. Like "form1.caption", the buttons for minimize, maximize and close, etc..

    There is a similar issue with the "file menu", where it will no longer change colors, correctly. Again, that can be hidden too, and still be used for input, if you make your own custom "file menu". The "file menu" is also a sub-form, which pushes the client-area down lower too.
    Last edited by ISAWHIM; Mar 2nd, 2024 at 09:00 AM.
    Please, chime-in on my latest WIP.
    I can use all the help I can get.
    [VB6 Game], (In Development), "Galactic-Bondsman"

  32. #32

    Thread Starter
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    Re: The titlebar with different colors

    Quote Originally Posted by Taro View Post
    I found this website. It very valuable information. Check this out. https://leandroascierto.com/blog/ski...a-formularios/
    The owner provided this link in post 17.

  33. #33

    Thread Starter
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    Re: The titlebar with different colors

    Quote Originally Posted by ISAWHIM View Post
    Windows changed the code for display of title-bars and the OCX no longer works correctly. Microsoft stated, in various posts, that they have no intention of "updating that OCX". It will no longer work as desired, even with API.
    Which ocx are you referring to ... ???

  34. #34
    Member Taro's Avatar
    Join Date
    Feb 2014
    Posts
    33

    Re: The titlebar with different colors

    Quote Originally Posted by Episcopal View Post
    The owner provided this link in post 17.
    Yaaaa, you are right. Since I'm walking around to find many information about this issue. I may confused that this is the original post that I found the link here. Thank you for updating me.

    Anyway, I still looking for the VB.Net for this issue. I just want to change the MDI Child form border color. No need for any skin. Even, now I'm working with non-border forms already. Better if I know how to change its color by the sizeable window style.
    Last edited by Taro; Mar 3rd, 2024 at 12:09 AM.

  35. #35

    Thread Starter
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    Re: The titlebar with different colors

    Quote Originally Posted by Taro View Post
    Yaaaa, you are right. Since I'm walking around to find many information about this issue. I may confused that this is the original post that I found the link here. Thank you for updating me.

    Anyway, I still looking for the VB.Net for this issue. I just want to change the MDI Child form border color. No need for any skin. Even, now I'm working with non-border forms already. Better if I know how to change its color by the sizeable window style.
    yes friend... in post 9 and 15, we talked about alternatives, explore them for VB.Net as you said

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