Cursor a BMP

Cursor a BMP

Postby cuatecatl82 » Mon Nov 23, 2015 6:54 pm

Saludos al foro:

Pues eso, es posible mostrar un cursor (.Cur o .Ani) en un Bitmap.. No doy como, ni con GDI me sale..

Alguien lo ha logradado.? Saludos y Gracias.
Soluciones y Diseño de Software
Damos Soluciones...

I.S.C. Victor Daniel Cuatecatl Leon
Director y Diseñador de Proyectos

http://www.soldisoft.unlugar.com
http://www.sisa.unlugar.com
danyleon82@hotmail.com
www.facebook.com/victordaniel.cuatecatlleon
User avatar
cuatecatl82
 
Posts: 625
Joined: Wed Mar 14, 2007 6:49 pm
Location: San Cristobal de las Casas, Chiapas México

Re: Cursor a BMP

Postby cuatecatl82 » Tue Nov 24, 2015 1:48 am

Buscando en San Google encontre lo siguiente usando GDI:

Image

[StructLayout(LayoutKind.Sequential)]
private struct ICONINFO
{
public bool fIcon;
public int xHotspot;
public int yHotspot;
public IntPtr hbmMask;
public IntPtr hbmColor;
}

[DllImport("user32")]
private static extern bool GetIconInfo(IntPtr hIcon, out ICONINFO pIconInfo);

[DllImport("user32.dll")]
private static extern IntPtr LoadCursorFromFile(string lpFileName);

[DllImport("gdi32.dll", SetLastError = true)]
private static extern bool DeleteObject(IntPtr hObject);

private Bitmap BitmapFromCursor(Cursor cur)
{
ICONINFO ii;
GetIconInfo(cur.Handle, out ii);

Bitmap bmp = Bitmap.FromHbitmap(ii.hbmColor);
DeleteObject(ii.hbmColor);
DeleteObject(ii.hbmMask);

BitmapData bmData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, bmp.PixelFormat);
Bitmap dstBitmap = new Bitmap(bmData.Width, bmData.Height, bmData.Stride, PixelFormat.Format32bppArgb, bmData.Scan0);
bmp.UnlockBits(bmData);

return new Bitmap(dstBitmap);
}

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
//Using LoadCursorFromFile from user32.dll, get a handle to the icon
IntPtr hCursor = LoadCursorFromFile("C:\\Windows\\Cursors\\Windows Aero\\aero_busy.ani");

//Create a Cursor object from that handle
Cursor cursor = new Cursor(hCursor);

//Convert that cursor into a bitmap
using (Bitmap cursorBitmap = BitmapFromCursor(cursor))
{
//Draw that cursor bitmap directly to the form canvas
e.Graphics.DrawImage(cursorBitmap, 50, 50);
}
}


Image
De Icono a Bmp lo he logrado facil con la ayuyda de GDI, pero con Cursores en .Ani o .Cur no me da, intente traducirlo a Harbour sin Exito, ojala alguien pueda hecharme una mano, la información la he obtenido desde este link http://stackoverflow.com/questions/4451839/how-to-render-a-transparent-cursor-to-bitmap-preserving-alpha-channel

Gracias. :lol: :lol:
Soluciones y Diseño de Software
Damos Soluciones...

I.S.C. Victor Daniel Cuatecatl Leon
Director y Diseñador de Proyectos

http://www.soldisoft.unlugar.com
http://www.sisa.unlugar.com
danyleon82@hotmail.com
www.facebook.com/victordaniel.cuatecatlleon
User avatar
cuatecatl82
 
Posts: 625
Joined: Wed Mar 14, 2007 6:49 pm
Location: San Cristobal de las Casas, Chiapas México

Re: Cursor a BMP

Postby cuatecatl82 » Tue Nov 24, 2015 12:09 pm

Alguna ide de cómo logtarlo??

Saludos
Soluciones y Diseño de Software
Damos Soluciones...

I.S.C. Victor Daniel Cuatecatl Leon
Director y Diseñador de Proyectos

http://www.soldisoft.unlugar.com
http://www.sisa.unlugar.com
danyleon82@hotmail.com
www.facebook.com/victordaniel.cuatecatlleon
User avatar
cuatecatl82
 
Posts: 625
Joined: Wed Mar 14, 2007 6:49 pm
Location: San Cristobal de las Casas, Chiapas México

Re: Cursor a BMP

Postby karinha » Tue Nov 24, 2015 1:06 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Cursor a BMP

Postby mastintin » Tue Nov 24, 2015 1:49 pm

Con los cursores *.ani no existe gran problema con gdi+ , el problema surge con los cursores *.cur .
Si consigo ponerlos a funcionar te paso el código .
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Cursor a BMP

Postby mastintin » Wed Nov 25, 2015 9:22 am

Ya está ...
Si alguna de las funciones falta solo tienes que pedirla :-)
Code: Select all  Expand view


Function hBitmapfromCursorFile( cFile )
 
local hCur  := ICON_EXEREAD( cFile )
local hGdiBmp := GDIPLUSIMAGEFROMICO( hCur )
local hBitmap := GdiPlusCreateHBitmapImage( hGdiBmp )

      GdiPlusImageDispose( hGdiBmp )
     
Return hBitmap

 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Cursor a BMP

Postby cuatecatl82 » Wed Nov 25, 2015 3:55 pm

Perfecto yo tenia algo parecido que mas o menos funciona:

Code: Select all  Expand view

REDEFINE BITMAP    oIma                                 ID 101   OF oDlg
REDEFINE BUTTONBMP oBtn   TEXTRIGHT RESOURCE "ABRIR"    ID 105   OF oDlg ACTION (cApp:= ALLTRIM( cGetFile( "Cursor Estatico (*.cur) |*.cur|" + ;
                                                                                                           "Cursor Animado  (*.ani) |*.ani|", "Seleccione Cursor"  )),;
                                                                                 IF(!EMPTY(cApp),( ImagenFromIco(oIma1,cApp,32,32) ),(SysRefresh())))

//----------------------------------------------------------------------------//
STATIC FUNCTION ImagenFromIco(oImage,cFile,nWidth,nHeight)

LOCAL Ico:= ICON_EXEREAD( cFile )
            BmpFromHIcon( ico, oImage, nWidth, nHeight )
            DestroyIcon( ico )
RETURN Nil

//----------------------------------------------------------------------------//
STATIC FUNCTION BmpFromHIcon( hIcon, oImage, nWidth, nHeight )

LOCAL hBmp:= BmpFromIcon( hIcon )    
             DeleteObject( oImage:hBitmap )          
             oImage:hBitmap = ReSizeBMP( hBmp, nWidth, nHeight, .T. )
             DeleteObject( hBmp )          
             oImage:HasAlpha()
             oImage:Refresh()
             
RETURN Nil


#pragma BEGINDUMP

#include <windows.h>
#include <wintrust.h>
#include <hbapi.h>
#include <commctrl.h>
#include <commoncontrols.h>

HB_FUNC( ICON_EXEREAD )
{
SHFILEINFO sfi;

ZeroMemory(&sfi, sizeof(SHFILEINFO));

SHGetFileInfo(hb_parc(1), 0, &sfi, sizeof(SHFILEINFO), SHGFI_ICON );

hb_retnl( ( LONG ) sfi.hIcon );

}

#pragma ENDDUMP


Lo mostraba pero con un fondo negro, lo invocaba desde un recurso BITMAP, en tu ejemplo como lo puedo invocar..

Saludos y Gracias..
Soluciones y Diseño de Software
Damos Soluciones...

I.S.C. Victor Daniel Cuatecatl Leon
Director y Diseñador de Proyectos

http://www.soldisoft.unlugar.com
http://www.sisa.unlugar.com
danyleon82@hotmail.com
www.facebook.com/victordaniel.cuatecatlleon
User avatar
cuatecatl82
 
Posts: 625
Joined: Wed Mar 14, 2007 6:49 pm
Location: San Cristobal de las Casas, Chiapas México

Re: Cursor a BMP

Postby mastintin » Wed Nov 25, 2015 5:10 pm

Exactamante igual ...
Code: Select all  Expand view


STATIC FUNCTION ImagenFromIco(oImage,cFile,nWidth,nHeight)

LOCAL Ico:= ICON_EXEREAD( cFile )
            BmpFromHIcon( ico, oImage, nWidth, nHeight )
            DestroyIcon( ico )
RETURN Nil


STATIC FUNCTION BmpFromHIcon( hIcon, oImage, nWidth, nHeight )

local hGdiBmp := GDIPLUSIMAGEFROMICO( hIcon )
local hBmp := GdiPlusCreateHBitmapImage( hGdiBmp )

      GdiPlusImageDispose( hGdiBmp )

      DeleteObject( oImage:hBitmap )          
      oImage:hBitmap = ReSizeBMP( hBmp, nWidth, nHeight, .T. )
      DeleteObject( hBmp )          
      oImage:HasAlpha()
      oImage:Refresh()

RETURN Nil
 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Cursor a BMP

Postby cuatecatl82 » Wed Nov 25, 2015 6:11 pm

Perfecto.. Muchas Gracias..
Soluciones y Diseño de Software
Damos Soluciones...

I.S.C. Victor Daniel Cuatecatl Leon
Director y Diseñador de Proyectos

http://www.soldisoft.unlugar.com
http://www.sisa.unlugar.com
danyleon82@hotmail.com
www.facebook.com/victordaniel.cuatecatlleon
User avatar
cuatecatl82
 
Posts: 625
Joined: Wed Mar 14, 2007 6:49 pm
Location: San Cristobal de las Casas, Chiapas México


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 77 guests