Windows - cards.dll como carregar as imagens desta dll do windows |
Top Previous Next |
|
// carregando imagens do CARDS.DLL
procedure TMatForm.LoadDLLBmp(const BmpId:Integer; Dest:TBitmap); var Lib,rInfo,hMemory: THandle; rSize: Longint; pData: PByte; BmpHdr: TBitmapFileHeader; stream: TMemoryStream; begin Lib := LoadLibrary('CARDS.DLL'); if Lib < HINSTANCE_ERROR then raise Exception.CreateFmt('Erro falta dll %s',['Cards.DLL']); rInfo := FindResource(Lib, MakeIntResource(BmpId), rt_Bitmap); if rInfo = 0 then raise Exception.CreateFmt('Erro %d %s',[BmpId,'FindResource']); hMemory := LoadResource(Lib,rInfo); try if hMemory = 0 then raise Exception.CreateFmt('Erro %d %s',[BmpId,'LoadResource']); pData := LockResource(hMemory); try rSize := SizeofResource(Lib,rInfo); if rSize = 0 then raise Exception.CreateFmt('Erro %d',[BmpId]); stream := TMemoryStream.Create; try BmpHdr.bfType := $4D42; stream.SetSize(sizeof(BmpHdr)+rSize); stream.Write(BmpHdr,sizeof(BmpHdr)); stream.Write(pData^,rSize); stream.Seek(0,0); Dest.LoadFromStream(stream); finally stream.Free; end; finally UnlockResource(hMemory); end; finally FreeResource(hMemory); end; end;
// crie 52 TImages para este teste... // renomeios para Paus1, Paus2... Paus13; Ouros1, Ouros2... Espadas e Copas
procedure TMatForm.FormCreate(Sender: TObject); var I: Integer; begin Randomize; // carrega imagens de todo o baralho no rodapé da tela for I := 1 to 13 do begin LoadDLLBmp(I , TImage(FindComponent('Paus' + IntToStr(I))).Picture.Bitmap); LoadDLLBmp(I + 13, TImage(FindComponent('Ouros' + IntToStr(I))).Picture.Bitmap); LoadDLLBmp(I + 39, TImage(FindComponent('Espadas' + IntToStr(I))).Picture.Bitmap); LoadDLLBmp(I + 26, TImage(FindComponent('Copas' + IntToStr(I))).Picture.Bitmap); end;
// para carregar a carta virada de costas: LoadDLLBmp(53, Image.Picture.Bitmap); [53..6x] end; . |