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.
[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);
}
}
Function hBitmapfromCursorFile( cFile )
local hCur := ICON_EXEREAD( cFile )
local hGdiBmp := GDIPLUSIMAGEFROMICO( hCur )
local hBitmap := GdiPlusCreateHBitmapImage( hGdiBmp )
GdiPlusImageDispose( hGdiBmp )
Return hBitmap
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
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
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: No registered users and 60 guests