Cursor a BMP
- cuatecatl82
- Posts: 625
- Joined: Wed Mar 14, 2007 6:49 pm
- Location: San Cristobal de las Casas, Chiapas México
- Contact:
Cursor a BMP
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.
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
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
- cuatecatl82
- Posts: 625
- Joined: Wed Mar 14, 2007 6:49 pm
- Location: San Cristobal de las Casas, Chiapas México
- Contact:
Re: Cursor a BMP
Buscando en San Google encontre lo siguiente usando GDI:


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.


[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);
}
}

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.


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
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
- cuatecatl82
- Posts: 625
- Joined: Wed Mar 14, 2007 6:49 pm
- Location: San Cristobal de las Casas, Chiapas México
- Contact:
Re: Cursor a BMP
Alguna ide de cómo logtarlo??
Saludos
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
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
- karinha
- Posts: 7935
- Joined: Tue Dec 20, 2005 7:36 pm
- Location: São Paulo - Brasil
- Been thanked: 3 times
- Contact:
Re: Cursor a BMP
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 .
Si consigo ponerlos a funcionar te paso el código .
Re: Cursor a BMP
Ya está ...
Si alguna de las funciones falta solo tienes que pedirla
Si alguna de las funciones falta solo tienes que pedirla

Code: Select all | Expand
Function hBitmapfromCursorFile( cFile )
local hCur := ICON_EXEREAD( cFile )
local hGdiBmp := GDIPLUSIMAGEFROMICO( hCur )
local hBitmap := GdiPlusCreateHBitmapImage( hGdiBmp )
GdiPlusImageDispose( hGdiBmp )
Return hBitmap
- cuatecatl82
- Posts: 625
- Joined: Wed Mar 14, 2007 6:49 pm
- Location: San Cristobal de las Casas, Chiapas México
- Contact:
Re: Cursor a BMP
Perfecto yo tenia algo parecido que mas o menos funciona:
Lo mostraba pero con un fondo negro, lo invocaba desde un recurso BITMAP, en tu ejemplo como lo puedo invocar..
Saludos y Gracias..
Code: Select all | Expand
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
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
Re: Cursor a BMP
Exactamante igual ...
Code: Select all | Expand
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
- cuatecatl82
- Posts: 625
- Joined: Wed Mar 14, 2007 6:49 pm
- Location: San Cristobal de las Casas, Chiapas México
- Contact:
Re: Cursor a BMP
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
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