PDA

Click to See Complete Forum and Search --> : API Color Problem


Vlatko
Oct 5th, 2000, 04:15 PM
I am making an app using only API(no MFC).Now ,the problem is that i don't know how to change the backcolor of a window or the text in that window.I tried to use the SetBkColor function but don't know how.I don't know how to use the COLORREF structure.
Any help appreciated.

Oct 5th, 2000, 05:08 PM
I also code in only API and i would also like to know how to do this.

parksie
Oct 5th, 2000, 05:16 PM
COLORREF isn't a structure. It's a typedef alias (a type that is created from another standard type, in this case an unsigned long).
So, you pass the values as:

SetBkColor(..., RGB(255,255,255), ...);

...using the RGB macro. The values are stored as 0x00BBGGRR internally.

Vlatko
Oct 6th, 2000, 11:58 AM
I tried this but it doesn't work:

HWND db=FindWindow(NULL,"bb");
HDC dbdc = GetDC(db);
SetBkColor(dbdc,RGB(255,0,128));

WHY??

V(ery) Basic
Oct 7th, 2000, 08:07 AM
Okay, I'm not exactly a C++ expert, but:


ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.hbrBackground = GetSysColorBrush(COLOR_BTNFACE) ;

//Other wcex stuff



Works fine.

Also:


case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
RECT rct;
HBRUSH hBrush;
POINT p;

GetWindowRect(hWnd, &rct);

p.x = rct.top;
p.y = rct.left;
ScreenToClient(hWnd, &p);
rct.top = p.x;
rct.left = p.y;

p.x = rct.bottom;
p.y = rct.right;
ScreenToClient(hWnd, &p);
rct.bottom = p.x;
rct.right = p.y;

hBrush = GetSysColorBrush(COLOR_BTNFACE);
hdc = BeginPaint(hWnd, &ps);
FillRect(hdc, &rct, hBrush);
DeleteObject((HGDIOBJ) hBrush);
ReleaseDC(hWnd, hdc);

break;


Works I think.

I hope.

Oh, well.

Bye!