PBX_DrawVisualObject

PowerBuilder Native Interface

Exported methods:

PBX_DrawVisualObject method

Description

Draws a visual object in the PowerBuilder development environment.

Syntax

PBX_DrawVisualObject(HDC hDC, LPCTSTR className, const PBX_DrawItemStruct& property)[Unmapped Entity: middot ]
 

Argument

Description

hDC

A handle to the device context of the object

classname

The name of the visual extension object to be drawn

property

A PBX_DrawItemStruct structure specifying the display properties of the object

Return Values

PBXRESULT. The return value of this function is currently ignored.

Examples

This is an extension of a sample that is available on the PowerBuilder CodeXchange Web site . It draws a representation of a light-emitting diode (LED) and uses Microsoft Foundation Classes (MFC):

PBXEXPORT PBXRESULT PBXCALL PBX_DrawVisualObject
(
HDC hDC,
LPCTSTR xtraName,
const PBX_DrawItemStruct& property
)
{
  // If this PBX is dynamically linked against the MFC
  // DLLs, any functions exported from this PBX that
  // call into MFC must have the AFX_MANAGE_STATE macro
  // added at the very beginning of the function.
   AFX_MANAGE_STATE( AfxGetStaticModuleState() );   

   // Variables to hold the Led control and a pointer
   // to Device Context
   CLed *myLed;
   CDC* pDC;

// The name must not contain uppercase letters
   if ( strcmp( xtraName, "u_cpp_led" ) == 0 )
   {
      CRect rc( property.x, property.y, property.x +
        property.width, property.y + property.height );
      
      //Create a new LED
      myLed = new CLed();
      
      // Get the handle from the hDC
      pDC = CDC::FromHandle(hDC);
      CWnd* pWnd = pDC->GetWindow();
      
      // Create the window
      myLed->Create(NULL, WS_CHILD | WS_VISIBLE |
        SS_BITMAP, rc, pWnd);

      // Function that handles the background
      // rendering of the control
      myLed->OnEraseBkgndIDE(pDC);
      
      // Draw the LED in default mode (red, on, round)
      myLed->DrawLed(pDC,0,0,0);
      myLed->SetLed(0,0,0);
      
      //done
      delete myLed;
   }

   return PBX_OK;
}

Usage

In a visual extension, export this function if you want the visual control to be drawn in the development environment. If you do not export the function, you need to run the application to see the appearance of the visual control.

See Also