Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wanted to get the pixel color beneath the mouse using mouse move and wanted to fill that color into a static controls background color or a rectangle using gdi.

I am not a regular win32 programmer.

I searched and got all the replies form others sources to use the message WM_CTLCOLOREDIT.

But my case is dynamic.

I just tried the following but it did not work...

C++
HWND hwnd, cbox;
COLORREF cboxcolor;

cbox = CreateWindow("STATIC", "ds", WS_CHILD|WS_VISIBLE, 10, 50, 50, 50, hwnd, 0, GetModuleHandle(0), 0);

cboxhdc = GetDC(cbox);
cboxcolor = RGB(255,2,255);
SetBkColor(cboxhdc, cboxcolor);


and when i checked GD functions i assume that brushes needed to be created ... so and so...
that was too many lines thinking that setting a color should be simple and straight forward yet not lazy to do it. but... its like too many options...

So thought of using ExtTextOut... haven't used it.

Want to make sure which way to go?

Which one of the following involves less processing or good for what ever other reason...

1. Create a static control and change the background color on mouse move. if possible
2. Create a bounded area and fill color. which i feel tedious.
3. using ExtTextOut...

?


After a while i found a solution and had replied to my own question. if anybody would like to add more or correct me of anything here then please go on...
Posted
Updated 4-Aug-13 9:05am
v4

1 solution

After exploring websites and documentations i found that ExtTextOut is the fastest among all other options i had mentioned.

Now after few trial and errors i made the setbkcolor and settextcolor to work with exttextout.

I didn't assume the behavior of setbkcolor and settextcolor would be like the old 16bit C graphics functions from Borland.

Now instead of using like the vb6.0 way of coloring a static control i am using the ExtTextOut function with ETO_OPAQUE to apply a background color the the rectangle i needed.

I don't know whether the above code(in my original question) works or not but the following code worked.

As i had said in the question that my need is to pick the color beneath the mouse pointer and to fill a rectangle. all i was confusing was how to setbackground color and now i got it. here it is...

C++
HDC hdc = GetDC(hwnd); //Main Window's dc
SetTextColor(hdc,RGB(0,200,200));
SetBkColor(hdc, RGB(0,0,200));
ExtTextOut(hdc,110,110,ETO_OPAQUE,&rect,"hehehaha",8,0);


it is the same like setcolor followed by setbkcolor followed by outtextxy in Turbo C. hhhmmm... phew... somehow forgot the old style. :)

If anybody would like to correct me of anything here then please go on...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900