• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetPenMode

Started by José Roca, July 01, 2008, 10:57:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a Pen object, sets the alignment, draws a line, and then gets the pen alignment settings.

C++


VOID Example_GetAlignment(HDC hdc)
{
   Graphics graphics(hdc);

   // Create a Pen object and set its alignment.
   Pen pen(Color(255, 0, 255, 0), 15);
   pen.SetAlignment(PenAlignmentCenter);

   // Draw a line.
   graphics.DrawLine(&pen, 0, 0, 100, 50);

   // Obtain information about the Pen object.
   PenAlignment penAlignment;
   penAlignment = pen.GetAlignment();

   if(penAlignment == PenAlignmentCenter)
      ;  // The pixels will be centered on the theoretical line.
   else if(penAlignment == PenAlignmentInset)
      ;  // The pixels will lie inside the filled area  of the theoretical line.
}


PowerBASIC


SUB GDIP_GetPenMode (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPen AS DWORD

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a Pen object and set its alignment.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 255, 0), 15, %UnitWorld, pPen)
   hStatus = GdipSetPenMode(pPen, %PenAlignmentInset)

   ' // Draw a line.
   hStatus = GdipDrawLineI(pGraphics, pPen, 0, 0, 100, 50)

   ' // Obtain information about the Pen object.
   LOCAL penAlignment AS LONG
   hStatus = GdipGetPenMode(pPen, penAlignment)

   IF penAlignment = %PenAlignmentCenter THEN
      ' ;  // The pixels will be centered on the theoretical line.
   ELSEIF penAlignment = %PenAlignmentInset THEN
      ' ;  // The pixels will lie inside the filled area  of the theoretical line.
   END IF

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

END SUB


The following illustration shows the output of the preceding code.