Multimidia - carregando bitmaps e cursores do res |
Top Previous Next |
Lendo Bitmaps e Cursores de RES -------------------------------
A chamada à API de LoadBitmap:
function LoadBitmap(Instance: THandle; BitmapName: PChar): HBitmap;
Exemplo lê um bitmap chamado BITMAP_1: --------------------------------------
procedure TForm1.Button1Click(Sender: TObject); var Bmp: TBitmap; begin Bmp := TBitmap.Create; Bmp.Handle := LoadBitmap(HInstance,'BITMAP_1'); Canvas.Draw(0, 0, Bmp); Bmp.Free; end;
{ Outro método }
procedure TForm1.Button1Click(Sender: TObject); const BM = $4D42; {Bitmap type identifier} var Bmp: TBitmap; BMF: TBitmapFileHeader; HResInfo: THandle; MemHandle: THandle; Stream: TMemoryStream; ResPtr: PByte; ResSize: Longint; begin BMF.bfType := BM; {Find, Load, and Lock the Resource containing BITMAP_1} HResInfo := FindResource(HInstance, 'BITMAP_1', RT_Bitmap); MemHandle := LoadResource(HInstance, HResInfo); ResPtr := LockResource(MemHandle);
{Create a Memory stream, set its size, write out the bitmap header, and finally write out the Bitmap } Stream := TMemoryStream.Create; ResSize := SizeofResource(HInstance, HResInfo); Stream.SetSize(ResSize + SizeOf(BMF)); Stream.Write(BMF, SizeOf(BMF)); Stream.Write(ResPtr^, ResSize);
{Free the resource and reset the stream to offset 0} FreeResource(MemHandle); Stream.Seek(0, 0);
{Create the TBitmap and load the image from the MemoryStream} Bmp := TBitmap.Create; Bmp.LoadFromStream(Stream); Canvas.Draw(0, 0, Bmp); Bmp.Free; Stream.Free; end;
Lendo Cursores --------------
const crMyCursor = 5; {Outras units poderão usar esta const}
procedure TForm1.FormCreate(Sender: TObject); begin Screen.Cursors[crMyCursor] := LoadCursor(HInstance, 'CURSOR_1'); Cursor := crMyCursor; end;
Mudar os cursores padrão ------------------------
procedure TForm1.FormCreate(Sender: TObject); begin Screen.Cursors[crSQLWait] := LoadCursor(HInstance, 'CURSOR_1'); end; |