elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a la Factorización De Semiprimos (RSA)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  FillRectEx [Source]
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: FillRectEx [Source]  (Leído 1,197 veces)
LeandroA
Moderador
***
Desconectado Desconectado

Mensajes: 760


www.leandroascierto.com


Ver Perfil WWW
FillRectEx [Source]
« en: 2 Febrero 2009, 01:25 am »

Hola estas es una funcion para poder pintar un Hdc con una imagen en forma repetitiva, pero partiendo de otro hdc, creo que no exite un api que directamente haga esto, ya que utilizando CreatePatternBrush lo hace desde un bmp, bueno no se si les pueda servir pero en fin es mucho mas rapido que usar bucles, como veran en el siguiente ejemplo pueden compara la funcion "Pintar" con  "FillRectEx"


Código:
Option Explicit
'Function: FillRectEx
'Autor Leandro Ascierto
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Private Declare Function CreatePatternBrush Lib "gdi32.dll" (ByVal hBitmap As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Private Declare Function GetTickCount& Lib "kernel32" ()

Private Sub Pintar()
Dim x As Long
Dim y As Long

Do While y < Me.ScaleHeight
    Do While x < Me.ScaleWidth
        BitBlt Me.hdc, x, y, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, vbSrcCopy
        x = x + Picture1.ScaleWidth
    Loop
    y = y + Picture1.ScaleHeight
    x = 0
Loop

End Sub

Private Sub Form_Load()
Me.Show
DoEvents
Me.ScaleMode = vbPixels
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = True
Form_Resize
End Sub

Private Sub Form_Resize()
Dim i As Integer
Dim lTime As Long

'lTime = GetTickCount&
'For i = 0 To 100
    FillRectEx Me.hdc, 0, 0, Me.ScaleWidth, Me.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
    'call Pintar
'Next

'Debug.Print GetTickCount& - lTime
End Sub


Private Sub FillRectEx(DestDC As Long, DestX As Long, DestY As Long, DestWidth As Long, DestHeight As Long, SrcDC As Long, SrcX As Long, SrcY As Long, SrcWidth As Long, SrcHeight As Long)
        Dim DC As Long
        Dim hDCMemory As Long
        Dim hBmp As Long
        Dim mBrush As Long
        Dim Rec As RECT

        DC = GetDC(0)
        hDCMemory = CreateCompatibleDC(0)
        hBmp = CreateCompatibleBitmap(DC, SrcWidth, SrcHeight)
        Call SelectObject(hDCMemory, hBmp)
        BitBlt hDCMemory, 0, 0, SrcWidth, SrcHeight, SrcDC, SrcX, SrcY, vbSrcCopy
        mBrush = CreatePatternBrush(hBmp)
        SetRect Rec, DestX, DestY, DestWidth + DestX, DestHeight + DestY
        FillRect DestDC, Rec, mBrush
       
        DeleteObject mBrush
        DeleteObject hBmp
        DeleteDC DC
        DeleteDC hDCMemory
End Sub


Saludos


En línea

el_c0c0


Desconectado Desconectado

Mensajes: 307


Ver Perfil
Re: FillRectEx [Source]
« Respuesta #1 en: 2 Febrero 2009, 03:28 am »

interesante, ideal para volar al carajo el BitBlt con bucles y mandarle esto

saludos


En línea

'-     coco
"Te voy a romper el orto"- Las hemorroides
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines