|
Description
The PBX_DrawVisualObject function has been added to the pbext.h header file. Export this new function in your PowerBuilder extension if you want the visual object to be drawn in the development environment.
Usage
The syntax of the PBX_DrawVisualObject function is:
PBXEXPORT PBXRESULT PBXCALL PBX_DrawVisualObject ( HDC hDC, LPCTSTR className, const PBX_DrawItemStruct& property );
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. The return value of this function is currently ignored.
The PBX_DrawItemStruct structure contains the properties of the external visual control that you want to draw:
struct PBX_DrawItemStruct { int x; int y; int width; int height; LPCTSTR objectName; LPCTSTR tag; BOOL enabled; BOOL visible; enum PBBorderStyle borderStyle; DWORD backColor; };
The following table describes each of the members of PBX_DrawItemStruct.
|
Field
|
Description
|
|
x
|
X coordinate of the visual control relative to its parent control (for example, the window that contains it).
|
|
y
|
Y coordinate of the visual control relative to its parent control.
|
|
width
|
Width of the visual control.
|
|
height
|
Height of the visual control.
|
|
objectName
|
The name of the visual object, for example: uo_1.
|
|
tag
|
Field to be used to pass any value at the user's discretion.
|
|
enabled
|
Whether the visual control is enabled. Possible values are true and false.
|
|
visible
|
Whether the visual control is visible. Possible values are true and false. In the development environment, PowerBuilder does not call the PBX_DrawVisualObject function if this field is set to false and the Design>Show Invisibles menu item is not selected.
|
|
borderstyle
|
Border style of the visual control. A value of the pbborder_style enumerated variable. Possible values are:
- 0 - none
- 1 - shadowbox
- 2 - box
- 5 - lowered
- 6 - raised
|
|
backColor
|
Background color of the visual control. You can obtain the RGB value of the background color using the Windows API functions GetRValue, GetGValue, and GetBValue.
|
Examples
This is an extension of a sample that is available in the PBNI samples on the Sybase CodeXchange Web site for PowerBuilder. 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 DLL is dynamically linked against the MFC // DLLs, any functions exported from this DLL 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; }
|