Results 1 to 10 of 10

Thread: SetBkColor ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2022
    Posts
    98

    SetBkColor ?

    Is it fair to say that in order for the SetBkColor function to work , it has to be called in response to WM_PAINT or WM_ERASEBKGND messages ?

    Thanks.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    23,803

    Re: SetBkColor ?

    I'm not sure how those two things are related. SetBkColor works wherever I need it.

    A window and a device context are different things.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2022
    Posts
    98

    Re: SetBkColor ?

    Thanks.

    I mean when you simply call SetBkColor hdc, vbRed on a window dc , the window dc color doesn't change to red.

    If you setbkcolor in response to WM_PAINT or WM_ERASEBKGND in the windows procedure , will it then change the dc color ?

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    23,803

    Re: SetBkColor ?

    No. It is the background color used for things like writing text to the DC when the background mode is opaque.

    If you want to fill the DC with a color or a pattern use something like FillRect() calls.

  5. #5
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    3,603

    Re: SetBkColor ?

    If the window in question is certain controls, however, it may be possible to use in response to a different message.

    For example, with Edit controls (textboxes), WM_CTLCOLOREDIT; with labels, WM_CTLCOLORSTATIC; and several others.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2022
    Posts
    98

    Re: SetBkColor ?

    @dilettante

    No. It is the background color used for things like writing text to the DC when the background mode is opaque.
    If you want to fill the DC with a color or a pattern use something like FillRect() calls.
    In other words, SetBkColor sets the text background not the actual window background... In order to set the window background we need a gdi brush. Is that accurate ?

    If that is the case, the name of the function is really misleading and counter-intuitive to say the least. A function name such as *SetTextBkColor* would have saved much of the confusion.

    Even the official MS documentation doesn't mention anything about text background:

    This is a passage taken from the MS documentation on the function:
    "The SetBkColor function sets the current background color to the specified color value, or to the nearest physical color if the device cannot represent the specified color value."

    No mention there (or elsewhere) relating to text background.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2022
    Posts
    98

    Re: SetBkColor ?

    Quote Originally Posted by fafalone View Post
    If the window in question is certain controls, however, it may be possible to use in response to a different message.

    For example, with Edit controls (textboxes), WM_CTLCOLOREDIT; with labels, WM_CTLCOLORSTATIC; and several others.
    Is that for filling the control background with color or the text background ?

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jun 2022
    Posts
    98

    Re: SetBkColor ?

    Ok-

    I think I was unfair in my above posts regarding the MS documentation.

    Further down in the Remarks section it reads :
    "This function fills the gaps between styled lines drawn using a pen created by the CreatePen function; it does not fill the gaps between styled lines drawn using a pen created by the ExtCreatePen function. The SetBkColor function also sets the background colors for TextOut and ExtTextOut."

    So, yes. It does talk about text background after all, although I still wish the name of the function was less misleading.

    Thanks everyone.

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    23,803

    Re: SetBkColor ?

    SetBkColor also plays a role in blitting to a monochrome bitmap to create a mask bitmap from an existing multicolor bitmap. It identifies the "transparent" color to become black in the mask.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jun 2022
    Posts
    98

    Re: SetBkColor ?

    Quote Originally Posted by dilettante View Post
    SetBkColor also plays a role in blitting to a monochrome bitmap to create a mask bitmap from an existing multicolor bitmap. It identifies the "transparent" color to become black in the mask.
    Yes. Like in the following function that masks the background color of a bitmap:
    Code:
    Public Sub Render( _
        ByVal Dest As Object, _
        ByVal DestX As Long, _
        ByVal DestY As Long, _
        ByVal DestWidth As Long, _
        ByVal DestHeight As Long, _
        ByVal Source As StdPicture, _
        ByVal MaskColor As Long, _
        Optional ByVal Rotation As Double, _
        Optional ByVal SourceScale As Double = 1, _
        Optional ByVal SourceX As Long, _
        Optional ByVal SourceY As Long, _
        Optional ByVal SourceWidth As Long, _
        Optional ByVal SourceHeight As Long)
    Thanks.

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