|
-
May 4th, 2005, 08:57 AM
#1
Edit Box SetBkColor
Anyone can tell me why this code does not work. The only thing that comes out is that the editbox becomes grey??
I am missing something??
{
PAINTSTRUCT ps;
HWND htest = GetDlgItem(hDlg, IDC_CHANNEL);
HDC hdc = GetWindowDC(htest);
hdc = BeginPaint (htest, &ps);
SetBkMode(hdc, TRANSPARENT);
SetBkColor(hdc, RGB(0, 255, 0));
EndPaint(htest, &ps);
ReleaseDC(htest, hdc);
}
thanks,
see u!
-
May 4th, 2005, 09:01 AM
#2
Re: Edit Box SetBkColor
Well... why not handle WM_CTLCOLOREDIT message?
-
May 4th, 2005, 09:46 AM
#3
Re: Edit Box SetBkColor
Actually I have tryed to put this code inside a "case WM_CTLCOLOREDIT", but I am not sure how to make it work!!
I am trying to find something around...
-
May 4th, 2005, 11:31 AM
#4
Re: Edit Box SetBkColor
Well WM_CTLCOLOREDIT requires you to return a HBRUSH from the handle. That means you can return every brush you need from WM_CTLCOLOREDIT and the edit will draw itself with it.
Code:
LRESULT CALLBACK WndProc ( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
static HBRUSH hBrush = NULL;
switch ( msg )
{
case WM_CTLCOLOREDIT:
{
if ( hBrush == NULL )
{ // Red color
hBrush = CreateSolidBrush(RGB(0xFF, 0x00, 0x00));
}
}
return (LRESULT)hBrush;
case WM_CLOSE:
{
if ( hBrush != NULL )
{
DestroyObject((HGDIOBJ)hBrush);
}
} break;
}
}
Now the edit control should be painted red.
Last edited by NoHero; May 4th, 2005 at 12:14 PM.
-
May 4th, 2005, 12:04 PM
#5
Re: Edit Box SetBkColor
Good example. And don't forget to DestroyObject() in WM_CLOSE or something similar.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-
May 4th, 2005, 12:11 PM
#6
Re: Edit Box SetBkColor
 Originally Posted by Bond
Good example. And don't forget to DestroyObject() in WM_CLOSE or something similar.
Thank you missed that!
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
|