• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetLineRect

Started by José Roca, June 22, 2008, 02:18:00 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a linear gradient brush. Then the code gets the brush's rectangle and draws it.

C++


VOID Example_GetRect(HDC hdc)
{
   Graphics myGraphics(hdc);

   // Create a linear gradient brush.
   LinearGradientBrush linGrBrush(
      Point(20, 10),
      Point(60, 110),
      Color(255, 0, 0, 0),     // black
      Color(255, 0, 0, 255));  // blue

   // Obtain information about the linear gradient brush.
   Rect rect;
   linGrBrush.GetRectangle(&rect);

   // Draw the retrieved rectangle.
   Pen myPen(Color(255, 0, 0, 0));
   myGraphics.DrawRectangle(&myPen, rect);
}


PowerBASIC


SUB GDIP_GetLineRect (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pLinBrush AS DWORD
   LOCAL pPen AS DWORD
   LOCAL pt1 AS POINTF
   LOCAL pt2 AS POINTF
   LOCAL colorBlack AS DWORD
   LOCAL colorBlue AS DWORD
   LOCAL rc AS RECTF

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   pt1.x = 20 : pt1.y = 10 : pt2.x = 60 : pt2.y = 110
   colorBlack = GDIP_ARGB(255, 0, 0, 0)
   colorBlue = GDIP_ARGB(255, 0, 0, 255)

   hStatus = GdipCreateLineBrush(pt1, pt2, colorBlack, colorBlue, %WrapModeTile, pLinBrush)

   ' // Obtain information about the linear gradient brush.
   hStatus = GdipGetLineRect(pLinBrush, rc)

   ' // Draw the retrieved rectangle.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 1, %UnitPixel, pPen)
   hStatus = GdipDrawRectangle(pGraphics, pPen, rc.x, rc.y, rc.Width, rc.Height)

   ' // Cleanup
   IF pPen THEN GdipDeletePen(pPen)
   IF pLinBrush THEN GdipDeleteBrush(pLinBrush)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB