Results 1 to 19 of 19

Thread: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    Hi there,

    Windows 10

    I have created a right-click context menu (CreateMenu Win32 API) with 3 menu entries\items. The 3 menu items have all a light-grey background color but, when I point the mouse pointer over any of the menu items, the background of the menu item that is currently under the mouse becomes highlighted (becomes hot) and its color changes to light-blue.

    If I change the machine theme colors via control panel, the highlight color is no longer light-blue. It changes to dark-grey.

    I need to retrieve this highlight color regardless of the current color theme.

    GetSysColor doesn't work with a themed user interface.

    I have done some googling and found that one should use the uxtheme library for retrieving this menu highlight color, namely the OpenThemeData and GetThemeColor apis.

    Questions:

    1- OpenThemeData takes a hwnd. I don't know which hwnd I should pass to this api given the fact that the context menu is for an added system tray icon. Should I pass the hwnd of the application or that of the system tray, the menu handle or some other hwnd?

    2- GetThemeColor takes two arguments (Parts and States)... I am not sure which ones I should use... Should I use (MENU, MENU_POPUPITEM,MENU_POPUPBACKGROUND .... MBI_HOT, MPI_HOT)... etc ?

    Thanks in advance.
    Last edited by JAAFAR; Jul 27th, 2021 at 03:50 PM.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    I have just passed the Menu Handle to the OpenThemeData API and have tested the following constants in the GetThemeColor API arguments.

    PartID=> VSCLASS_MENU
    StateID=> MENU_POPUPITEM
    PropID=> MPI_HOT

    I get a close blue color but not quite the right one.

  3. #3
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    OpenThemeData should work fine with 0 for hWnd.

    Take a look at AeroStyle.xml for ideas about class names and part names.

    cheers,
    </wqw>

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

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    GetSysColor() will not track with theme changes made since the last reboot.

    GetSysColorBrush() will however, since that is what gets used.

    System color brushes track changes in system colors. In other words, when the user changes a system color, the associated system color brush automatically changes to the new color.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    @wqweto
    OpenThemeData should work fine with 0 for hWnd
    Didn't work for me. I had to pass the menu handle in order for it to work.
    Take a look at AeroStyle.xml for ideas about class names and part names.
    I have tried many constant combinations but none of them give me the exact highlight color.

    @dilettante.
    Quote Originally Posted by dilettante View Post
    GetSysColor() will not track with theme changes made since the last reboot.
    GetSysColorBrush() will however, since that is what gets used.
    Tried that already but, just like with GetSysColor, it would only give me the COLOR_MENU. It won't give me the highlight color that I see when selecting the menu item or when hovering it with the mouse.

    Thanks

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    The following light-blue color is the one I am trying to read programmatically.

    The highlighted menu is the menu that is currently HOT ie:=active ie:= under tthe mouse pointer.

    Obviously, that color varies depending on the current applied colors theme in the user machine.

    Name:  Untitled.png
Views: 432
Size:  2.5 KB
    Last edited by JAAFAR; Jul 28th, 2021 at 11:07 AM.

  7. #7
    Fanatic Member
    Join Date
    Jul 2007
    Location
    Essex, UK.
    Posts
    578

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    I don't know if it might help but that colour is &HF7C991.

  8. #8
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    There is a

    <class name="CommunicationsStyle">
    <part name="Tab">
    <state name="Hot">
    <AccentColorHint>148 201 254</AccentColorHint>

    . . . in AeroStyle.xml above which is a very close &HFEC994 color hint.

    cheers,
    </wqw>

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    Quote Originally Posted by Steve Grant View Post
    I don't know if it might help but that colour is &HF7C991.
    Thanks Steve ... That is indeed the correct color but I need to get it programmatically as the color varies from one user machine to another depending on the machine color theme currently applied.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    Quote Originally Posted by wqweto View Post
    There is a

    <class name="CommunicationsStyle">
    <part name="Tab">
    <state name="Hot">
    <AccentColorHint>148 201 254</AccentColorHint>

    . . . in AeroStyle.xml above which is a very close &HFEC994 color hint.

    cheers,
    </wqw>
    Hi wqweto,

    You nailed it !!

    I successfully read the correct color. (Note: This time, passing the menu handle in the OpenThemeData hwnd arg didn't work. I had to pass 0 like you suggested in an earlier post.

    This is what works:
    Code:
    Const VSCLASS_COMMUNICATIONSSTYLE = "COMMUNICATIONSSTYLE"
    Const CSST_TAB = 1
    Const CSTB_HOT = 2
    Const TMT_ACCENTCOLORHINT = 3823
    
    Theme = OpenThemeData(0, StrPtr(VSCLASS_COMMUNICATIONSSTYLE))
    Result = GetThemeColor(Theme, _
                           CSST_TAB, _
                           CSTB_HOT, _
                           TMT_ACCENTCOLORHINT, _
                           Color)
    Relying on the class names as well as the part names is not intuitive at all ... I would have never guessed that CommunicationsStyle was the class I needed for menus... Constants not descriptive at all

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

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    How are you using this color anyway?

    Seems like it would require a lot of subclassing and bitmap swapping. Is it really worth all that?

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    Quote Originally Posted by dilettante View Post
    How are you using this color anyway?

    Seems like it would require a lot of subclassing and bitmap swapping. Is it really worth all that?
    What I have in mind is to make that color as the background color of the menu bitmap in the last argument of the SetMenuItemBitmaps API so that the bitmap background looks transparent when the user hovers the menu entry with the mouse.

    Haven't tested the idea yet and I don't even know if this will work in the end but, in any case, even if this doesn't work, I still will have learnt a few interesting things in the process.
    Last edited by JAAFAR; Jul 28th, 2021 at 07:55 PM.

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

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    Wrong call, that one only sets the checked and unchecked bitmaps. The one you want is SetMenuItemInfo() instead.

    But in both cases the bitmaps are meant to be monochrome mask bitmaps. Using a color bitmap, the best you can do is use the menu color. Choosing the hover color will look really bad.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    Quote Originally Posted by dilettante View Post
    Wrong call, that one only sets the checked and unchecked bitmaps. The one you want is SetMenuItemInfo() instead.

    But in both cases the bitmaps are meant to be monochrome mask bitmaps. Using a color bitmap, the best you can do is use the menu color. Choosing the hover color will look really bad.
    Ok, I see ...Thanks for the advice.
    I quick search on this api came up with this old code of yours. I will take a close look at it and see what I can learn from it.

    Thanks.

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

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    I'm not sure whether the corrected version ever got posted. Version 6 is the newest I have here.

    I have another example that is very stripped down, just a Form with all of the giblets in it instead of a Class to hold the fiddly bits. I can tell you now that since it uses a color bitmap it will not have the look you want when selected though. However it does track theme changes for the "non-hover" menu background color.

    If you figure that out, then great. But as the documentation says, these are supposed to be monochrome mask bitmaps and color bitmaps "may give crappy results."

    The selected and clear bitmaps should be monochrome. The system uses the Boolean AND operator to combine bitmaps with the menu so that the white part becomes transparent and the black part becomes the menu-item color. If you use color bitmaps, the results may be undesirable.
    Attached Files Attached Files

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    Quote Originally Posted by dilettante View Post
    I'm not sure whether the corrected version ever got posted. Version 6 is the newest I have here.

    I have another example that is very stripped down, just a Form with all of the giblets in it instead of a Class to hold the fiddly bits. I can tell you now that since it uses a color bitmap it will not have the look you want when selected though. However it does track theme changes for the "non-hover" menu background color.

    If you figure that out, then great. But as the documentation says, these are supposed to be monochrome mask bitmaps and color bitmaps "may give crappy results."
    Hi dilettante,
    Thanks for taking the time to help. I will take a look at the example and see if I can adapt it to my needs.

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

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    Test it first. It should run fine in the IDE.

    I do not think it will do exactly what you want though. I can't think of any way to avoid showing the menu background color in the square of a color bitmap when you hover over the item. I.e. it is not "transparent."

    The only thing I can imagine might be to use subclassing to detect hovering and replace the bitmap again with one painted on the hover-color background, then flip back after hovering moves on. If you do that you'll probably have to call DrawMenuBar() each time you change bitmaps.

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

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    It sounds like what you want can be done by creating a 32-bit DIB with premultiplied alpha. I don't have an example of that though.

    As far as I can tell LoadImage() can do that using a premultiplied BMP file source.

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2013
    Posts
    658

    Re: OpenThemeData For Getting Background Color Of Context Menu Item ? (uxtheme.dll)

    Quote Originally Posted by dilettante View Post
    It sounds like what you want can be done by creating a 32-bit DIB with premultiplied alpha. I don't have an example of that though.

    As far as I can tell LoadImage() can do that using a premultiplied BMP file source.
    Thanks.

    It will be a while before I wrap my mind around these topics.

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