-
Oct 6th, 2022, 11:44 PM
#1
Thread Starter
Addicted Member
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.
-
Oct 7th, 2022, 01:04 AM
#2
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.
-
Oct 7th, 2022, 01:20 AM
#3
Thread Starter
Addicted Member
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 ?
-
Oct 7th, 2022, 01:08 PM
#4
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.
-
Oct 7th, 2022, 10:00 PM
#5
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.
-
Oct 8th, 2022, 10:15 AM
#6
Thread Starter
Addicted Member
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.
-
Oct 8th, 2022, 10:19 AM
#7
Thread Starter
Addicted Member
Re: SetBkColor ?
Originally Posted by fafalone
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 ?
-
Oct 8th, 2022, 10:26 AM
#8
Thread Starter
Addicted Member
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.
-
Oct 8th, 2022, 01:34 PM
#9
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.
-
Oct 8th, 2022, 03:44 PM
#10
Thread Starter
Addicted Member
Re: SetBkColor ?
Originally Posted by dilettante
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|