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:
00945256
Vues:
34
Frank,

>
>Hey, I really do appreciate Your support in this!
>

No problem :-)


>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?
>

Yes, you have to delete the Bitmap also. You can just delete it right after creating the brush.


>I need to do the declaration only once, so I'll put it out later but that's the (working) code so far.
>

You also doesn't need to create & destroy the brush anytime it draws. Just create it one time, use it subsequently until you don't need it anymore ( or end of the application ) then destroy it.


>
>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.
>

Glad you can make it worked. Now you know it's not too hard, right ;-)
I think you already know this, but I just want to tell about this line:
nLeft = Buff2Num( cRect, (4*0)+1, .F. )
The rectangle value actually is a type of LONG . But I use WORD conversion instead, because I think windows rectangle will never reach the highest WORD value (0xFFFF). So it's up to you which one you want to use.


>Thanks again.
>

You are welcome :)
Herman
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform