Dibujo rápido

Dibujo rápido

Postby antolin » Thu Mar 27, 2014 11:27 am

Hola foreros.

Investigando sobre los Devices Contexts (DC) he descubierto una cosa muy interesante. A lo mejor ya lo teneis implementado en vuestra versión de FWH, pero por si acaso lo explico.

Se trata de las funciones SetDCPenColor(hDc,nColor) y SetDCBrushColor(hDc,nColor). Lo que hacen es que cuando elegis un Pen o un Brush con GetStockObject() podeis cambiarle el color sin tener que definir un pen/brush nuevo. Por lo que he experimentado, sólo funcionan con los objetos del Stock del DC.

Primero hay que crear las funciones:

Code: Select all  Expand view
#pragma BEGINDUMP

#include <wingdi.h>

HB_FUNC( SETDCPENCOLOR )  //  SetDCPenColor( hDc, nColor )
   {
   hb_retnl( SetDCPenColor( ( HDC ) hb_parnl( 1 ), ( COLORREF ) hb_parni( 2 ) ) ) ;
   }


HB_FUNC( SETDCBRUSHCOLOR )  //  SetDCBrushColor( hDc, nColor )
   {
   hb_retnl( SetDCBrushColor( ( HDC ) hb_parnl( 1 ), ( COLORREF ) hb_parni( 2 ) ) ) ;
   }

#pragma ENDDUMP

Se utiliza así: Suponga que necesita un PEN rojo de 1 pixel de ancho (para otro tamaño no funcionaría porque los PENs del STOCK sólo son el negro y el blanco de 1 pixel de ancho) y un brush amarillo.

Code: Select all  Expand view
#define DC_BRUSH   18
#define DC_PEN     19

LOCAL hObj := SelectObject(hDc,GetStockObject(DC_PEN)) // ESTO ES NECESARIO: ELIJE EL PEN POR DEFECTO DEL DC
SelectObject(hDc,GetStockObject(DC_BRUSH))         // ESTO TAMBIEN: ELIJE EL BRUSH POR DEFECTO DEL DC

SetDCPenColor(hDc,CLR_RED)
SetDCBrushColor(hDc,CLR_YELLOW)

Rectangle(hDc,10,10,200,300)

SelectObject(hDc,hObj)

Et Voilà, hemos dibujado un rectángulo amarillo con borde rojo sin tener que definir PENs ni BRUSHs. Así de rápido...

También existen las funciones GetDCPenColor(hDc) y GetDCBrushColor(hDc), pero esas por ahora no me han hecho falta.

Un saludo.
Peaaaaaso de foro...
antolin
 
Posts: 492
Joined: Thu May 10, 2007 8:30 pm
Location: Sevilla

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 36 guests