🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.delphi.components
Article #1

DESPERATE - WinG in Delphi

#1
From: Peter Hawkins
Date: Fri, 20 Oct 1995 00:00
128 lines
3790 bytes
Hello! PLEASE help!
Can anyone provide me with source code to blt a TBitmap to the screen
using WinG? All  I can get is a multicoloured blur of random pixels.
My code is as follows:
unit Unit1;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, WinG;

CONST
  ImageX = 320;
  ImageY = 200;



type
  TImg=record
  bi:TBitmapInfoHeader;
  bmp:TBitmap;
  end;

    pScreen = ^TScreen; {Bitmap access table}
  TScreen = RECORD
    CASE Integer OF
      0 : (ptb : ARRAY[-(ImageY-1)..0, 0..ImageX-1] OF Byte);
          {ptb = byte coord [y, x]}
      1 : (ptw : ARRAY[-(ImageY-1)..0, 0..(ImageX DIV 2)-1] OF Word);
          {ptw = word coord [y, x div 2]}
      2 : (pta : ARRAY[0..(ImageY*ImageX)-1] OF Byte);
          {pta = byte array [(y*320)+x]}
  END; {REC TScreen}

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure Formpaint(Sender: TObject);
  private
    { Private declarations }
    hWinGDC:hDC;
    hOldBitmap:HBitmap;
    Orientation:Integer;
    Image:TImg;
    bmp:PScreen;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
InitWinG;
image.bmp:=TBitmap.create;
image.bmp.loadfromfile('C:\WINDOWS\ARCHES.BMP');
hWinGDC:=0;
hOldBitmap:=0;
Orientation:=1;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var hbm:hBitmap;
begin
hbm:=SelectObject(hWinGDC,hOldBitmap);
DeleteObject(hbm);
DeleteDC(hWinGDC);
image.bmp.free;
DeInitWinG;
end;

procedure TForm1.FormShow(Sender: TObject);
var hBM:hBitmap;
    p:pointer;
begin
if WinGRecommendDIBFormat(pBitmapInfo(@Image.bi)) then begin
 Image.Bi.biBitCount:=8;
 Image.Bi.bicompression:=bi_RGB;
 Orientation:=Image.bi.biheight;
 end
 else
 with image.bi do
 begin
 bisize:=Sizeof(image.bi);
 biplanes:=1;
 biBitcount:=8;
 biCompression:=Bi_RGB;
 biSizeImage:=0;
 biClrUsed:=0;
 biClrImportant:=0;
 Orientation:=1;
 end;
 {end;}
image.bi.biwidth:=Image.bmp.width;
Image.bi.biheight:=image.bmp.height*orientation;
image.bi.bisizeimage:=(image.bi.biwidth*image.bi.biHeight)*Orientation;
hWinGDC:=WinGCreateDC;
p:=nil;
hBM:=WinGCreateBitmap(hWinGDC,pBitmapInfo(@Image.bi),p{@bmp});
hOldBitmap:=SelectObject(HWinGDC,hBM);
bitblt(hWinGDC,0,0,Image.bmp.width,Image.bmp.height,Image.bmp.canvas.handle,
0,0,SRCCOPY);
{PatBlt(hWinGDC,0,0,Image.bmp.width,Image.bmp.height, BLACKNESS);}
end;

procedure TForm1.Formpaint(Sender: TObject);
begin
selectpalette(canvas.handle,image.bmp.palette,false);
realizepalette(canvas.handle);
WinGBitBlt(canvas.handle,0,0,image.bmp.width,image.bmp.height,hWinGDC,0,0);
end;

end.

I imagine I have to use GetDIBits to copy the bitmap from the TBitmap
to the WinG bitmap, but I have absolutely no idea how to do it. I have
the Borland Pascal WinG demo (flames), but that dosen't help me, as I
don't understand how it works, and it creates the bitmap as it runs.

Thanks,
Peter
Technical Details
Message-ID: <467itd$amr@supreme.pcug.org.au>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 108890,bd51c915c4fe8031,start
X-Google-Attributes: gid108890,public
X-Google-Thread: 10cc59,bd51c915c4fe8031,start
X-Google-Attributes: gid10cc59,public
X-Google-Thread: 108c83,bd51c915c4fe8031,start
X-Google-Attributes: gid108c83,public
From: std213@freenet.actein.edu.au (Peter Hawkins)
Subject: DESPERATE - WinG in Delphi
Date: 1995/10/20
Message-ID: <467itd$amr@supreme.pcug.org.au>
X-Deja-AN: 117842421
organization: LXiV Software
newsgroups: comp.lang.pascal.delphi.components,comp.lang.pascal,aus.computers