Autor Tema: Fugas de GDI  (Leído 7151 veces)

0 Usuarios y 1 Visitante están viendo este tema.

TheWatcher

  • Bytes
  • *
  • Mensajes: 16
  • Reputación: +2/-0
    • Ver Perfil
Fugas de GDI
« en: Enero 20, 2010, 03:41:59 am »

TheWatcher

  • Bytes
  • *
  • Mensajes: 16
  • Reputación: +2/-0
    • Ver Perfil
Re:Fugas de GDI
« Respuesta #1 en: Enero 20, 2010, 04:23:52 am »
Las muestras "DrawGrip", "DrawSelectionEx", "FillRectEx", "DrawAlphaSelection", "Texto espejado" tienen los mismos fugas GDI debido a los mismos problemas con la creación y supresión de los objetos dentro de la DC.
« última modificación: Enero 20, 2010, 04:31:28 am por TheWatcher »

LeandroA

  • Administrador
  • Petabyte
  • *****
  • Mensajes: 1128
  • Reputación: +151/-8
    • Ver Perfil
Re:Fugas de GDI
« Respuesta #2 en: Enero 20, 2010, 03:53:46 pm »
Hola, Gracias por la observación, me gustaria poder entender o saber cual es la forma correcta.

pongamos como ejemplo
http://www.leandroascierto.com.ar/tips.php  la función RenderStretchFromDC

no veo ninguna fuga que provoque algun incremento en la memoria u objetos GDI. pero no quiero cerrarme en mi pensamiento/conocimiento, podrias explicarme como, porque o cual es la fuga?

Saludos.

TheWatcher

  • Bytes
  • *
  • Mensajes: 16
  • Reputación: +2/-0
    • Ver Perfil
Re:Fugas de GDI
« Respuesta #3 en: Enero 20, 2010, 09:52:28 pm »
http://msdn.microsoft.com/en-us/library/aa923962.aspx :
Citar
BOOL DeleteObject(
  HGDIOBJ hObject
);

 Parameters

hObject

    [in] Handle to a logical pen, brush, font, bitmap, region, or palette.

 Return Value

Nonzero indicates success.

Zero indicates that the specified handle is not valid or that the handle is currently selected into a device context.

To get extended error information, call GetLastError.
 Remarks

Do not delete a drawing object (pen or brush) while it is still selected into a device context.
Lamentablemente esto también se aplica a otros objetos GDI, como por ejemplo, mapas de bits.

http://msdn.microsoft.com/en-us/library/aa932923.aspx :
Citar
HGDIOBJ SelectObject(
  HDC hdc,
  HGDIOBJ hgdiobj
);

 Parameters

hdc

    [in] Handle to the device context.

hgdiobj

    [in] Handle to the object to be selected.

    The specified object must have been created by using one of the following functions.
...................

 Return Value

If the selected object is not a region, the handle of the object being replaced indicates success.
..................
 Remarks

This function returns the previously selected object of the specified type.

An application should always replace a new object with the original, default object after it has finished drawing with the new object.
..................

Con el fin de que sea completamente compatible con las especificaciones de Windows, el código de RenderStretchFromDC () debería tener el siguiente aspecto:

Código: [Seleccionar]
Private Function RenderStretchFromDC(ByVal DestDC As Long, _
                                ByVal DestX As Long, _
                                ByVal DestY As Long, _
                                ByVal DestW As Long, _
                                ByVal DestH As Long, _
                                ByVal SrcDC As Long, _
                                ByVal x As Long, _
                                ByVal y As Long, _
                                ByVal Width As Long, _
                                ByVal Height As Long, _
                                ByVal Size As Long, _
                                Optional MaskColor As Long = -1)
                               
Dim Sx2 As Long

Sx2 = Size * 2

If MaskColor <> -1 Then
    Dim mDC     As Long
    Dim mX      As Long
    Dim mY      As Long
    Dim DC      As Long
    Dim hBmp    As Long
    Dim hOldBmp    As Long ' storage for the original BMP allocated automatically when CreateCompatibleDC() is called

    mDC = DestDC
    DC = GetDC(0)
    DestDC = CreateCompatibleDC(0)
    hBmp = CreateCompatibleBitmap(DC, DestW, DestH)
    hOldBmp = SelectObject(DestDC, hBmp) ' save the original BMP for later reselection
    mX = DestX: mY = DestY
    DestX = 0: DestY = 0
End If

SetStretchBltMode DestDC, vbPaletteModeNone

BitBlt DestDC, DestX, DestY, Size, Size, SrcDC, x, y, vbSrcCopy  'TOP_LEFT
StretchBlt DestDC, DestX + Size, DestY, DestW - Sx2, Size, SrcDC, x + Size, y, Width - Sx2, Size, vbSrcCopy 'TOP_CENTER
BitBlt DestDC, DestX + DestW - Size, DestY, Size, Size, SrcDC, x + Width - Size, y, vbSrcCopy 'TOP_RIGHT
StretchBlt DestDC, DestX, DestY + Size, Size, DestH - Sx2, SrcDC, x, y + Size, Size, Height - Sx2, vbSrcCopy 'MID_LEFT
StretchBlt DestDC, DestX + Size, DestY + Size, DestW - Sx2, DestH - Sx2, SrcDC, x + Size, y + Size, Width - Sx2, Height - Sx2, vbSrcCopy 'MID_CENTER
StretchBlt DestDC, DestX + DestW - Size, DestY + Size, Size, DestH - Sx2, SrcDC, x + Width - Size, y + Size, Size, Height - Sx2, vbSrcCopy 'MID_RIGHT
BitBlt DestDC, DestX, DestY + DestH - Size, Size, Size, SrcDC, x, y + Height - Size, vbSrcCopy 'BOTTOM_LEFT
StretchBlt DestDC, DestX + Size, DestY + DestH - Size, DestW - Sx2, Size, SrcDC, x + Size, y + Height - Size, Width - Sx2, Size, vbSrcCopy   'BOTTOM_CENTER
BitBlt DestDC, DestX + DestW - Size, DestY + DestH - Size, Size, Size, SrcDC, x + Width - Size, y + Height - Size, vbSrcCopy 'BOTTOM_RIGHT

If MaskColor <> -1 Then
    TransparentBlt mDC, mX, mY, DestW, DestH, DestDC, 0, 0, DestW, DestH, MaskColor
    SelectObject DestDC, hOldBmp  ' reselect the original BMP and deselect the new BMP
    DeleteObject hBmp                  ' now you are free to delete the new BMP
    DeleteDC DC
    DeleteDC DestDC                    ' delete DestDC with its original BMP
End If

End Function

Hay muchas piezas de código similar en las aplicaciones de ejemplo presentado en este sitio web. Mientras que las muestras pequeñas pueden parecer relativamente estable, porque la pintura relativamente poco lo que se hace, los grandes programas pueden sufrir caídas inesperadas y congelar al azar.

El manejo cuidadoso y limpio de objetos GDI a menudo pueden hacer que el código se comporte de una manera más previsible y previsto, debido al hecho de que la asignación automática / cancelación de asignación de memoria del sistema será compatible con los requisitos generales de Windows.

Espero sinceramente que mis observaciones hará que el contenido de su excelente sitio web todavía un poco mejor, si se puede hacer en absoluto.

Mike :)

LeandroA

  • Administrador
  • Petabyte
  • *****
  • Mensajes: 1128
  • Reputación: +151/-8
    • Ver Perfil
Re:Fugas de GDI
« Respuesta #4 en: Enero 20, 2010, 11:39:50 pm »
Hola Mike, muchas gracias por su aclaración, tiene usted toda la razón, es un mal habito que había tomado, me llevara un largo tiempo poder corregir todos los códigos, pero siempre es mejor ganar conocimiento.

bienvenido al foro, esperamos contar con mas de su conocimiento por aquí.

Saludos y muchas gracias.

TheWatcher

  • Bytes
  • *
  • Mensajes: 16
  • Reputación: +2/-0
    • Ver Perfil
Re:Fugas de GDI
« Respuesta #5 en: Enero 21, 2010, 01:27:57 am »
Muchas gracias por sus cálidas palabras de bienvenida. Espero que puedan beneficiarse mutuamente el uno del otro ahora y en el futuro.

También he enviado un mensaje personal en el foro FBSL (en Inglés, para un cambio :) ).

Tal vez usted también gusta lo que ves en este enlace:
http://www.fbsl.net/phpbb2/viewtopic.php?p=8394#8394

Mike  :)

LeandroA

  • Administrador
  • Petabyte
  • *****
  • Mensajes: 1128
  • Reputación: +151/-8
    • Ver Perfil
Re:Fugas de GDI
« Respuesta #6 en: Enero 21, 2010, 08:35:08 pm »
Permita me felicitarlo a usted y todo su equipo por el excelente trabajo con FBSL, realmente me pareció fantástico, es muy similar a visual basic en ciertos aspecto, también a C++ y PHP, los Script son muy claros de entender.
excelente el Glossy Buttons.
Intentare más adelante crear algún script para poder compartirlo.

Espero que la traducción sea entendible
Saludos :).

Gerome

  • Bit
  • Mensajes: 2
  • Reputación: +0/-0
    • Ver Perfil
    • Freestyle Basic Script Language
Re:Fugas de GDI
« Respuesta #7 en: Enero 22, 2010, 05:41:30 am »
Permita me felicitarlo a usted y todo su equipo por el excelente trabajo con FBSL, realmente me pareció fantástico, es muy similar a visual basic en ciertos aspecto, también a C++ y PHP, los Script son muy claros de entender.
excelente el Glossy Buttons.
Intentare más adelante crear algún script para poder compartirlo.

Espero que la traducción sea entendible
Saludos :).

Hola Leandro !

Gracias por los cumplimientos!
El equipo FBSL trabaja desde hace nueve años en este proyecto.
Tenemos ahora un lenguaje qué no tiene que envidiarles nada a otros profesionalmente gracias a Mike y Mehdi mis dos co-autores :)

Saludos a tod@s !
« última modificación: Enero 22, 2010, 05:48:36 am por Gerome »
Yours,

(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
:: Full SETUP w. HELP 27th of October 2009 ::
http://gedd123.free.fr/FBSLv3.exe [3.4.0.5]
http://gedd123.free.fr/FBSLv3bin.zip [minimal]
Laissons les jolies femmes aux hommes sans imagination. / Let us leave pretty women to men without imagination.(M.Proust)
The success is a defeat for the one who does not want to dance any more! (H.F. Thiefaine)

ssccaann43

  • Terabyte
  • *****
  • Mensajes: 970
  • Reputación: +97/-58
    • Ver Perfil
    • Sistemas Nuñez, Consultores y Soporte, C.A.
Re:Fugas de GDI
« Respuesta #8 en: Enero 22, 2010, 10:36:23 am »
Ese lenguaje es creado en????
Miguel Núñez.

Gerome

  • Bit
  • Mensajes: 2
  • Reputación: +0/-0
    • Ver Perfil
    • Freestyle Basic Script Language
Re:Fugas de GDI
« Respuesta #9 en: Enero 22, 2010, 12:05:38 pm »
Ese lenguaje es creado en????

Ese lenguaje creado en ANSI C con GCC/MinGW para Windows => http://fbsl.net/pmwiki/
« última modificación: Enero 22, 2010, 12:16:50 pm por Gerome »
Yours,

(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
:: Full SETUP w. HELP 27th of October 2009 ::
http://gedd123.free.fr/FBSLv3.exe [3.4.0.5]
http://gedd123.free.fr/FBSLv3bin.zip [minimal]
Laissons les jolies femmes aux hommes sans imagination. / Let us leave pretty women to men without imagination.(M.Proust)
The success is a defeat for the one who does not want to dance any more! (H.F. Thiefaine)

ssccaann43

  • Terabyte
  • *****
  • Mensajes: 970
  • Reputación: +97/-58
    • Ver Perfil
    • Sistemas Nuñez, Consultores y Soporte, C.A.
Re:Fugas de GDI
« Respuesta #10 en: Enero 22, 2010, 12:17:39 pm »
Interesante...! Bienvenido Gerome y TheWatcher...! Excelente trabajo con FBSL, lo he bajado... Ahora me toca darme trancazos..! :D
Miguel Núñez.