Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Form - resize rubber band
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00944495
Message ID:
00945224
Vues:
36
Herman,

>Hmm.. I don't have the VFP code for this right now. I translated
>this directly from C++ code. Hope this works :)

Hey, I really do appreciate Your support in this!

This was all I needed to get me going. I found the declaration of the PatBlt and I remembererd You saying I should not forget to delete the brush.

When working with the "borders", I found that the edges may not overlap otherwise they get inverted again.

Do I need to DeleteObject() more than just the Brush? How about the handle to the Bitmap?

I need to do the declaration only once, so I'll put it out later but that's the (working) code so far.
PROCEDURE DrawPatternedRubber
*-- This will draw a patterned rubber around a given area in
*-- order to mimic Window's resizing - optic

#Define BOOL       long
#Define HANDLE     long
#Define PSTR       String @
#Define PRECT      String @
#Define UINT         Long
#Define PATINVERT    0x005A0049

#Define HWND_DESKTOP    0

lparameters    tnTop, tnLeft, tnBottom, tnRight
tnTop      = iif(vartype(tnTop) = "N", tnTop, this.nTop)
tnLeft     = iif(vartype(tnLeft) = "N", tnLeft, this.nLeft)
tnBottom   = iif(vartype(tnBottom) = "N", tnBottom, this.nBottom)
tnRight    = iif(vartype(tnRight) = "N", tnRight, this.nRight)

LOCAL lnWidth, lnHeight, rgbPatGray, hBitmap, hPatBrush

*-- Declaration of the necessary Windows-Functions
*-- Later put aside
Declare BOOL     DeleteObject in GDI32 HANDLE hDC
Declare BOOL     PatBlt in GDI32 HANDLE hDC, Integer nXLeft, ;
                    Integer nYLeft, Integer nWidth, integer nHeight, ;
                    INTEGER dwRop
*-- dwRop should be a DWORD but as PATINVERT is numeric
*-- already, Integer does the trick
                    
Declare HANDLE   CreateBitmap in GDI32 ;
                       Integer nWidth, Integer nHeight, ;
                       UINT cPlanes, UINT cBitsPerPel, PSTR lpvBits
Declare HANDLE   CreatePatternBrush in GDI32 HANDLE hBitmap
Declare HANDLE   GetDC in User32 HANDLE nhWnd
Declare HANDLE   SelectObject in GDI32 HANDLE hDC, HANDLE hObject
Declare Integer  ReleaseDC in User32 HANDLE nhWnd, HANDLE hDC

*-- Erstellen eines Bitmap-Brush mit dem gescheckten
*-- Muster für das Zeichnen des Randes
rgbPatGray  = replicate( Word(0x55) + Word(0xAA), 4 )
hBitmap     = CreateBitmap( 8, 8, 1, 1, rgbPatGray )
hPatBrush   = CreatePatternBrush( hBitmap )

*-- Ermitteln des Rechtecks zum Zeichnen des Rahmens
*-- Buff2Num ist eine Funktion in WordProcs.prg. Es
*-- geht aber auch meine Funktion String2Long(), dann 
*-- mit einem Aufruf substr(cRect,5,4) etc.

*-- Getting the Recangle of the form is done in a
*-- separate method now
*-- cRect     = space( 16 )
*-- GetWindowRect( ThisForm.hWnd, @cRect )
*-- nLeft     = Buff2Num( cRect, (4*0)+1, .F. )
*-- nTop      = Buff2Num( cRect, (4*1)+1, .F. )
*-- nRight    = Buff2Num( cRect, (4*2)+1, .F. )
*-- nBottom   = Buff2Num( cRect, (4*3)+1, .F. )

*-- calculate Width and height for better
*-- handling
lnWidth     = tnRight - tnLeft
lnHeight    = tnBottom - tnTop

*-- Width and height of a sizable window-frame
lnXFrame    = SysMetric(3)
lnYFrame    = SysMetric(4)

hDC         = GetDC( HWND_DESKTOP )
hOldBrush   = SelectObject( hDC, hPatBrush )

*-- Drawing each of the four borders but without
*-- overlapping the thick lines at the edges, as this 
*-- would invert them at the corners
PatBlt( hDC, tnLeft, tnTop, lnWidth, lnYFrame, PATINVERT )                                  && top side
PatBlt( hDC, tnLeft, tnTop+lnYFrame, lnXFrame, lnHeight-(2*lnYFrame), PATINVERT )           && left side
PatBlt( hDC, tnLeft, tnBottom-lnYFrame, lnWidth, lnYFrame, PATINVERT)                       && bottom side
PatBlt( hDC, tnRight-lnXFrame, tnTop+lnYFrame, lnXFrame ,lnHeight-(2*lnYFrame), PATINVERT)  && right side

*-- reset the brush
SelectObject( hDC, hOldBrush )

ReleaseDC( HWND_DESKTOP, hDC )

*-- and Delete the brush and bitmap
DeleteObject(hPatBrush)
DeleteObject(hBitmap)

*-- Finally keep the lower right corner
*-- for later. Needed to remove the frame
this.nOldBottom = tnBottom
this.nOldRight  = tnRight


Works and looks really cool now.

Thanks again.

Frank
Regards from Berlin

Frank

Dietrich Datentechnik (Berlin)
Softwarekombinat Teltow (Teltow)

Frank.Dietrich@dd-tech.de
DFPUG # 327
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform