VpeGetUDODC

<< Click to Display Table of Contents >>

Navigation:  UDO - User Defined Objects >

VpeGetUDODC

Previous pageReturn to chapter overviewNext page

[Windows platform only, Professional Edition and above]

This property is only accessible while your application is processing the event VPE_UDO_PAINT. Retrieving this value while not processing the event will return invalid - and therefore useless - data.

It returns the current Device Context VPE is painting on (this maybe the screen or a printer Device Context). Using this Device Context, you can call any Windows GDI function and paint yourself into Device Context. Be careful, do not destroy the Device Context and make sure to free all used system resources. In case of misuse the system may hang or fail to work correctly.

HDC VpeGetUDODC(

VpeHandle hDoc

)

VpeHandle hDoc

Document Handle

Returns:

the HDC of the UDO that needs to be drawn

Remarks:

Before VPE fires the event VPE_UDO_PAINT, it draws the Box object the UDO object is inherited from. Afterwards VPE saves the Device Context with the Windows GDI function SaveDC( ) and creates a clipping rectangle around the object.

 

After you have finished painting and return control to VPE by returning from your event-handler, VPE will delete the clipping rectangle and restore the Device Context with the Windows GDI function RestoreDC( ).

Example:

VpeCreateUDO(hDoc, 1, 1, -18, -18, 1);

Creates a UDO with the current properties for the Box-Object and the ID "1" (=lParam)

 

Processing of the VPE_UDO_PAINT event in C/C++

(in the window-procedure of the parent window of the VPE preview):

case VPE_UDO_PAINT:

 UdoPaint(lParam);

 break;

 

The function UdoPaint() looks like this:

void UdoPaint(VpeHandle hDoc)

{

 HDC hDC;

 RECT rc;

 HPEN hpen, holdpen;

 

 hDC = VpeGetUDODC(hDoc);

 VpeGetUDODrawRect(hDoc, &rc);

 

 if (VpeGetUDOlParam(hDoc) == 1)

 {

         hpen = CreatePen(PS_SOLID, 1, COLOR_RED);

         holdpen = SelectObject(hDC, hpen);

         MoveToEx(hDC, rc.left, rc.top, NULL);

         // LineTo() draws a line from the current position up to,

         // but not including, the specified point.

         // Therefore we add 1 to each coordinate.

         LineTo(hDC, rc.right + 1, rc.bottom + 1);        

         MoveToEx(hDC, rc.right, rc.top, NULL);

         LineTo(hDC, rc.left - 1, rc.bottom + 1);

         SelectObject(hDC, holdpen);

         DeleteObject(hpen);

 }

}

 

The example draws two crossing lines within the UDO.