C language > Windows questions
Color inside the "Ellipse"
alderman2:
I need to use the "Ellipse" function in a program I'm working on. I can color the edges around but not inside the circle. I've tried everything I can find on how to but nothing has worked yet. The others I've seen do this use add-on libraries, but I don't want to do that.
Anyone know the easiest way to color the circle surface with any color?
This is what it looks like when I can color the border around the circle, but how do you paint in the circle:
HPEN hpen,hpenOld;
PAINTSTRUCT ps ;
BeginPaint(hwnd, &ps);
hpen=CreatePen(PS_SOLID,0,color);
hpenOld=SelectObject(hDC,hpen);
Ellipse( hDC, 400, 300,200, 200);
SelectObject(hDC,hpenOld);
DeleteObject(hpen);
TimoVJL:
Using Filled Shapes
alderman2:
--- Quote from: TimoVJL on December 17, 2022, 10:43:23 PM ---Using Filled Shapes
--- End quote ---
I solved it!!! After two weeks of trying, and when I finally post the question here, I found the solution!
This is how it works:
--- Code: ---HDC hDC;
HBRUSH hBrush;
hDC = GetDC(hwnd);
hBrush = CreateSolidBrush (RGB(0, 0, 255));
SelectObject (hDC, hBrush);
Ellipse( hDC, 300, 300, 100, 100);
--- End code ---
Is there something missing in the code?
MrBcx:
--- Quote from: alderman2 on December 17, 2022, 11:14:18 PM ---Is there something missing in the code?
--- End quote ---
Impossible to say because you only shared a fragment of code.
The function below was copied from the BCX runtime library.
It might provide clues that you can use.
--- Code: --- int BCX_Circle (HWND Wnd, int X, int Y, int R, int Pen, int Fill, HDC DrawHDC)
{
int a,b=0;
if (!DrawHDC) DrawHDC=GetDC(Wnd),b=1;
HPEN hNPen=CreatePen(PS_SOLID,1,Pen);
HPEN hOPen=(HPEN)SelectObject(DrawHDC,hNPen);
HBRUSH hOldBrush;
HBRUSH hNewBrush;
if (Fill)
{
hNewBrush=CreateSolidBrush(Pen);
hOldBrush=(HBRUSH)SelectObject(DrawHDC,hNewBrush);
}
else
{
hNewBrush=(HBRUSH)GetStockObject(NULL_BRUSH);
hOldBrush=(HBRUSH)SelectObject(DrawHDC,hNewBrush);
}
a = Ellipse(DrawHDC,X-R,Y+R,X+R,Y-R);
DeleteObject(SelectObject(DrawHDC,hOPen));
DeleteObject(SelectObject(DrawHDC,hOldBrush));
if (b) ReleaseDC(Wnd,DrawHDC);
return a;
--- End code ---
John Z:
Hi MrBcx,
--- Quote from: MrBcx on December 18, 2022, 12:42:59 AM ---
--- Code: --- if (!DrawHDC) DrawHDC=GetDC(Wnd),b=1;
--- End code ---
--- End quote ---
This code snippet works? I've never seen this syntax, I surmise if no HDC it will get one, then it will set b equal to 1
as a flag to later allow the release of the DC; but I've never run across this use of a comma..... I would have had to write
--- Code: --- if (!DrawHDC)
{ DrawHDC=GetDC(Wnd) ; b=1;}
--- End code ---
Are multiple commas allowed too? As in
if (!DrawHDC) DrawHDC=GetDC(Wnd),b=1,c=2,d=3;
John Z
Navigation
[0] Message Index
[#] Next page
Go to full version