CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2012
    Posts
    15

    get window border color

    I am trying to get the current color of a window border

    Code:
    Enum WINDOWPARTS
        WP_CAPTION = 1
        WP_SMALLCAPTION = 2
        WP_MINCAPTION = 3
        WP_SMALLMINCAPTION = 4
        WP_MAXCAPTION = 5
        WP_SMALLMAXCAPTION = 6
        WP_FRAMELEFT = 7
        WP_FRAMERIGHT = 8
        WP_FRAMEBOTTOM = 9
        WP_SMALLFRAMELEFT = 10
        WP_SMALLFRAMERIGHT = 11
        WP_SMALLFRAMEBOTTOM = 12
        WP_SYSBUTTON = 13
        WP_MDISYSBUTTON = 14
        WP_MINBUTTON = 15
        WP_MDIMINBUTTON = 16
        WP_MAXBUTTON = 17
        WP_CLOSEBUTTON = 18
        WP_SMALLCLOSEBUTTON = 19
        WP_MDICLOSEBUTTON = 20
        WP_RESTOREBUTTON = 21
        WP_MDIRESTOREBUTTON = 22
        WP_HELPBUTTON = 23
        WP_MDIHELPBUTTON = 24
        WP_HORZSCROLL = 25
        WP_HORZTHUMB = 26
        WP_VERTSCROLL = 27
        WP_VERTTHUMB = 28
        WP_DIALOG = 29
        WP_CAPTIONSIZINGTEMPLATE = 30
        WP_SMALLCAPTIONSIZINGTEMPLATE = 31
        WP_FRAMELEFTSIZINGTEMPLATE = 32
        WP_SMALLFRAMELEFTSIZINGTEMPLATE = 33
        WP_FRAMERIGHTSIZINGTEMPLATE = 34
        WP_SMALLFRAMERIGHTSIZINGTEMPLATE = 35
        WP_FRAMEBOTTOMSIZINGTEMPLATE = 36
        WP_SMALLFRAMEBOTTOMSIZINGTEMPLATE = 37
        WP_FRAME = 38
    End Enum
    
    ' WINDOWSTYLEPARTS WINDOWPARTS;
    
    Enum FRAMESTATES
        FS_ACTIVE = 1
        FS_INACTIVE = 2
    End Enum
    
    Enum CAPTIONSTATES
        CS_ACTIVE = 1
        CS_INACTIVE = 2
        CS_DISABLED = 3
    End Enum
    
    Enum MAXCAPTIONSTATES
        MXCS_ACTIVE = 1
        MXCS_INACTIVE = 2
        MXCS_DISABLED = 3
    End Enum
    
    Enum MINCAPTIONSTATES
        MNCS_ACTIVE = 1
        MNCS_INACTIVE = 2
        MNCS_DISABLED = 3
    End Enum
    
    Enum HORZSCROLLSTATES
        HSS_NORMAL = 1
        HSS_HOT = 2
        HSS_PUSHED = 3
        HSS_DISABLED = 4
    End Enum
    
    Enum HORZTHUMBSTATES
        HTS_NORMAL = 1
        HTS_HOT = 2
        HTS_PUSHED = 3
        HTS_DISABLED = 4
    End Enum
    
    Enum VERTSCROLLSTATES
        VSS_NORMAL = 1
        VSS_HOT = 2
        VSS_PUSHED = 3
        VSS_DISABLED = 4
    End Enum
    
    Enum VERTTHUMBSTATES
        VTS_NORMAL = 1
        VTS_HOT = 2
        VTS_PUSHED = 3
        VTS_DISABLED = 4
    End Enum
    
    Enum SYSBUTTONSTATES
        SBS_NORMAL = 1
        SBS_HOT = 2
        SBS_PUSHED = 3
        SBS_DISABLED = 4
    End Enum
    
    Enum MINBUTTONSTATES
        MINBS_NORMAL = 1
        MINBS_HOT = 2
        MINBS_PUSHED = 3
        MINBS_DISABLED = 4
    End Enum
    
    Enum MAXBUTTONSTATES
        MAXBS_NORMAL = 1
        MAXBS_HOT = 2
        MAXBS_PUSHED = 3
        MAXBS_DISABLED = 4
    End Enum
    
    Enum RESTOREBUTTONSTATES
        RBS_NORMAL = 1
        RBS_HOT = 2
        RBS_PUSHED = 3
        RBS_DISABLED = 4
    End Enum
    
    Enum HELPBUTTONSTATES
        HBS_NORMAL = 1
        HBS_HOT = 2
        HBS_PUSHED = 3
        HBS_DISABLED = 4
    End Enum
    
    Enum CLOSEBUTTONSTATES
        CBS_NORMAL = 1
        CBS_HOT = 2
        CBS_PUSHED = 3
        CBS_DISABLED = 4
    End Enum
               Private Const EP_EDITTEXT = 1
                Private Const ETS_NORMAL = 1
                Private Const TMT_BORDERCOLOR = 3801
                Const TMT_ACTIVEBORDER = 1611
                 Const S_OK = 0&
                 
                Private Declare Function OpenThemeData Lib "uxtheme.dll" _
                   (ByVal hwnd As Long, ByVal pszClassList As Long) As Long
                 
                Private Declare Function CloseThemeData Lib "uxtheme.dll" _
                   (ByVal hTheme As Long) As Long
                 
                Private Declare Function GetThemeColor Lib "uxtheme.dll" ( _
                   ByVal hTheme As Long, _
                   ByVal iPartId As Long, _
                   ByVal iStateId As Long, _
                   ByVal iPropId As Long, _
                   ByRef pColor As OLE_COLOR) As Long
                 
                 
                Public Function TextBoxBorderColor(lhWnd As Long) As OLE_COLOR
                 
                   Dim hTheme As Long
                   Dim pColor As OLE_COLOR
                   Dim oRetVal As OLE_COLOR
                 
                   hTheme = OpenThemeData(lhWnd, StrPtr("Edit"))
                   If hTheme <> 0 Then
                      If GetThemeColor(hTheme, EP_EDITTEXT, ETS_NORMAL, TMT_BORDERCOLOR, pColor) = S_OK Then
                         oRetVal = pColor
                      End If
                   End If
                   CloseThemeData hTheme
                   If oRetVal = 0 Then
                      oRetVal = vbButtonShadow
                   End If
                   TextBoxBorderColor = oRetVal
                End Function
                  Function WindowBorderColor(lhWnd As Long) As OLE_COLOR
                 
                   Dim hTheme As Long
                   Dim pColor As OLE_COLOR
                   Dim oRetVal As OLE_COLOR
                 
                   hTheme = OpenThemeData(lhWnd, StrPtr("Window"))
                   If hTheme <> 0 Then
                      If GetThemeColor(hTheme, WP_FRAME, FS_ACTIVE, TMT_ACTIVEBORDER, pColor) = S_OK Then
                         oRetVal = pColor
                      End If
                   End If
                   CloseThemeData hTheme
                   If oRetVal = 0 Then
                      oRetVal = vbButtonShadow
                   End If
                   WindowBorderColor = oRetVal
                End Function
                
    
    
    
    Private Sub Form_Load()
    dim w as long
    Show
    w = WindowBorderColor(Me.hwnd)
    End Sub
    I get a wrong color
    any idea?

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: get window border color

    What color is the border and what color do you get?
    Is the window in question using themes or is it set to use a specific color?
    I would only expect the code shown to return the color defined in the current theme for the border color no matter if that is the color used by the window or not.
    Always use [code][/code] tags when posting code.

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: get window border color

    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Join Date
    Feb 2012
    Posts
    15

    Re: get window border color

    Quote Originally Posted by DataMiser View Post
    What color is the border and what color do you get?
    Is the window in question using themes or is it set to use a specific color?
    I would only expect the code shown to return the color defined in the current theme for the border color no matter if that is the color used by the window or not.
    The color is 69C8F0 but I get 80000010
    I am using win8.1
    Attached Images Attached Images  

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

Featured