|
-
Jul 3rd, 2001, 12:11 AM
#1
Thread Starter
PowerPoster
Problem setting the back color
I have problem setting the backcolor on a checkbox or editbox or any other control.
It is like this.
SetBkColor(hdc, color)
I provide it the hdc or the control and the color but it does not change the color of the given control.
Do you know why it does not change it?
-
Jul 3rd, 2001, 12:45 AM
#2
Frenzied Member
Use this code to change the edit control's back color. You need to handle this message. (not send it.)
Code:
case WM_CTLCOLORSTATIC:
if(edithwnd == (HWND)lParam)
{
SetBkMode((HDC)wParam, TRANSPARENT);
SetTextColor((HDC)wParam, RGB(59, 195, 25));
return (LRESULT)GetStockObject(BLACK_BRUSH);
}
break;
-
Jul 3rd, 2001, 08:39 AM
#3
Thread Starter
PowerPoster
But When do i recieve that message
-
Jul 3rd, 2001, 09:32 AM
#4
Frenzied Member
Just handle the messages. Here is some info about them.
Code:
WM_CTLCOLORSTATIC
A static control, or an edit control that is read-only or disabled, sends the WM_CTLCOLORSTATIC message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text and background colors of the static control.
WM_CTLCOLORSTATIC
hdcStatic = (HDC) wParam; // handle to display context
hwndStatic = (HWND) lParam; // handle to static control
Parameters
hdcStatic
Value of wParam. Handle to the device context for the static control window.
hwndStatic
Value of lParam. Handle to the static control.
Return Values
If an application processes this message, the return value is a handle to a brush that the system uses to paint the background of the static control.
Default Action
The DefWindowProc function selects the default system colors for the static control.
Remarks
Edit controls that are not read-only or disabled do not send the WM_CTLCOLORSTATIC message; instead, they send the WM_CTLCOLOREDIT message. However, for compatibility purposes, the system sends the WM_CTLCOLOREDIT message for read-only and disabled edit controls if the application was designed for Windows 3.1 or earlier.
The system does not automatically destroy the returned brush. It is the application's responsibility to destroy the brush when it is no longer needed.
The WM_CTLCOLORSTATIC message is never sent between threads; it is sent only within the same thread.
If a dialog box procedure handles this message, it should cast the desired return value to a BOOL and return the value directly. If the dialog box procedure returns FALSE, then default message handling is performed. The DWL_MSGRESULT value set by the SetWindowLong function is ignored.
Code:
WM_CTLCOLOREDIT
An edit control that is not read-only or disabled sends the WM_CTLCOLOREDIT message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text and background colors of the edit control.
WM_CTLCOLOREDIT
hdcEdit = (HDC) wParam; // handle to display context
hwndEdit = (HWND) lParam; // handle to static control
Parameters
hdcEdit
Value of wParam. Handle to the device context for the edit control window.
hwndEdit
Value of lParam. Handle to the edit control.
Return Values
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.
Default Action
The DefWindowProc function selects the default system colors for the edit control.
Remarks
Read-only or disabled edit controls do not send the WM_CTLCOLOREDIT message; instead, they send the WM_CTLCOLORSTATIC message. However, for compatibility purposes, the system sends the WM_CTLCOLOREDIT message for read-only and disabled edit controls if the application was designed for Windows 3.1 or earlier.
The system does not automatically destroy the returned brush. It is the application's responsibility to destroy the brush when it is no longer needed.
The WM_CTLCOLOREDIT message is never sent between threads, it is only sent within the same thread.
If a dialog box procedure handles this message, it should cast the desired return value to a BOOL and return the value directly. If the dialog box procedure returns FALSE, then default message handling is performed. The DWL_MSGRESULT value set by the SetWindowLong function is ignored.
-
Jul 3rd, 2001, 05:51 PM
#5
Thread Starter
PowerPoster
What is that return value for?
Are doing two things at a time -- setting the textcolor and then the backcolor?
Anyway, I have white textbox so when I run your code, it changes the textcolor and also it changes the backcolor to black. To keep my default backcolor, do I just use "WHITE_BRUSH"?
I was also able to return another type of color using "CreateSolidBrush"
Thanks a lot for that.
And do you know after how much time will msdn be up and running again?
-
Jul 3rd, 2001, 05:56 PM
#6
Monday Morning Lunatic
MSDN's fine at the moment
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jul 3rd, 2001, 08:55 PM
#7
Thread Starter
PowerPoster
I have alomost made a text editor
Lots of links are MSDN down because they are rebuilding that section
---------------------------------------------------------------------------------
I am making a kind of text editor that is able to show two dialog boxes and that can save and open a file.
The problem is that when put this code in my main main windows' message handling routine, it just takes lots of memory. And when I run the application, and try to press enter lots of times or move the text around, it manipulates the whole text like chicken scratches:
Code:
case WM_CTLCOLOREDIT:
if(edithwnd == (HWND)lParam)
{
SetBkMode((HDC)wParam, TRANSPARENT);
SetTextColor((HDC)wParam, RGB(59, 195, 25));
return (LRESULT)GetStockObject(BLACK_BRUSH);
}
break;
It only happens when I put the above code in.
Why is it taking so much memory?
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
|