News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

SetBkColor

Started by RedXVII, February 27, 2006, 05:58:35 PM

Previous topic - Next topic

RedXVII

i want to set the backround of my edit box to black.

however, after a SetBkColor call, only the fist line is backrounded black. When my text moves onto the second line, the second line is then backrounded black! I want the whole edit box backround to be black. Am i using the right function?

.elseif eax==WM_CTLCOLOREDIT
mov eax, lParam
.if eax==hIDC_EDT2
invoke SetBkColor, wParam, RGB(0,0,0)
.else
invoke DefWindowProc, hWin, uMsg, wParam, lParam
.endif


Cheers  :U

Mark Jones

"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

MichaelW

Quote
If an application processes this message, it must return the handle of a brush. The system uses the brush to paint the background of the edit control.
MSDN: WM_CTLCOLOREDIT Notification

Quote
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.
MSDN: SetBkColor
eschew obfuscation

RedXVII

Got it working now

I used CreatSolidBrush in WM_INITDIALOG. Then used the return value from that for the return value for WM_CTLCOLOREDIT. I will post some code when im finished.

I am unfamiliar with brushes. If i use CreateSolidBrush does it not allocate memory for that brush? If it uses memory and my program is running for a long time, How do i remove/stop using it. How do i change the color? Create SolidBrush will only make a new one...

thx  :U

MichaelW

For black you could use:

invoke GetStockObject, BLACK_BRUSH

There is no need to delete stock objects.

MSDN: Brush Functions
eschew obfuscation

RedXVII

Why is there no need to delete stock objects?

I might be changing the color of my edit box a rather large number of times. If thats the case, i will be calling CreateSolidBrush and it will be using more and more memory for the brushes i wont be using, right? This is a bad thing? Or i should just not worry about it?

  :U

Tedd

There is no need to delete 'stock' objects. There is a set of system created objects (brushes, fonts, pens, etc) which are avaiable to use (using GetStockObject), but since you didn't create them, you shouldn't be the one to destroy them.
However, if you're creating your own set of brushes (using CreateSolidBrush) then it's for you to destroy them. If you plan on doing this a lot, then it may be a good idea to create all the brushes you need at startup, keep track of the handles, and then delete them when you've finished. But this would require that you know which brushes you want in advance.
No snowflake in an avalanche feels responsible.

RedXVII

Yes, the point is, the user has to be able to change the color of the editbox at will, without 1) slowing down the other intensive tasks, 2) messing things up. Windows is so messed up when it comes to changing colors, its so dammed difficult to do and just plain odd. So if the user specifies the color, i cant use GetStockObject, cause they are only system colors   :snooty: 

On the other hand I dont see any delete function for deleting brushes, maybe the OS deals with this automatically?

anon

Use DeleteObject to delete your custom brush.

From PSDK:

The DeleteObject function deletes a logical pen, brush, font, bitmap, region, or palette, freeing
all system resources associated with the object. After the object is deleted, the specified handle
is no longer valid.

BOOL DeleteObject(
  HGDIOBJ hObject   // handle to graphic object
);

MichaelW

eschew obfuscation

Tedd

Quote from: RedXVII on March 02, 2006, 04:03:39 PM
Yes, the point is, the user has to be able to change the color of the editbox at will, without 1) slowing down the other intensive tasks, 2) messing things up. Windows is so messed up when it comes to changing colors, its so dammed difficult to do and just plain odd. So if the user specifies the color, i cant use GetStockObject, cause they are only system colors   :snooty: 

On the other hand I dont see any delete function for deleting brushes, maybe the OS deals with this automatically?

But would you expect the user to change the colour of the edit box every few seconds? Once they've decided upon a colour, I think they'll stick with it. Which means even if changing colour took a long time, it would only really be done once.
Anyway, you can just create it initially with the stockobject brush (default colour) and then upon selection of a new brush, set it and deleteobject for the old one (deleteobject for stock-objects has no real effect.)
No snowflake in an avalanche feels responsible.

RedXVII

Ah! Thats what I wanted to hear  :bg

Im now on my way to coloring windows and things rediculous colors,  :bdg

Thanks all  :U