home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
DRAWBMP
/
DRAWBITS.PAS
next >
Wrap
Pascal/Delphi Source File
|
1991-12-31
|
3KB
|
128 lines
library DrawBits;
{$X+,W+}
uses WinProcs, WinTypes, LoadBmps;
const
HWindow: HWnd = 0;
Bitmap: HBitmap = 0;
{ DrawBitmap ------------------------------------------------------- }
procedure DrawBitmap(DC: HDC; X, Y: Integer; Bitmap: HBitmap);
var
MemDC: HDC;
BitmapRec: TBitmap;
begin
MemDC := CreateCompatibleDC(DC);
SelectObject(MemDC, Bitmap);
GetObject(Bitmap, SizeOf(BitmapRec), @BitmapRec);
BitBlt(DC, X, Y, BitmapRec.bmWidth, BitmapRec.bmHeight, MemDC,
0, 0, srcCopy);
DeleteDC(MemDC);
end;
{ WndProc ---------------------------------------------------------- }
function WndProc(HWindow: HWnd; Message: Word; wParam: Word;
lParam: LongInt): LongInt; export;
var
DC: HDC;
Rect: TRect;
PS: TPaintStruct;
I: Integer;
begin
WndProc := 0;
case Message of
wm_Destroy:
begin
HWindow := 0;
if Bitmap <> 0 then DeleteObject(Bitmap);
Bitmap := 0;
end;
wm_Paint:
if Bitmap <> 0 then begin
DC := BeginPaint(HWindow, PS);
DrawBitmap(DC, 0, 0, Bitmap);
EndPaint(HWindow, PS);
Exit;
end;
end;
WndProc := DefWindowProc(HWindow, Message, wParam, lParam);
end;
{ RegisterClass ---------------------------------------------------- }
procedure RegisterClasses;
var
Class: TWndClass;
begin
with Class do
begin
lpszClassName := 'DrawBits';
hCursor := LoadCursor(0, IDC_ARROW);
lpszMenuName := nil;
style := cs_HRedraw or cs_VRedraw;
lpfnWndProc := @WndProc;
hInstance := System.hInstance;
hIcon := 0;
cbWndExtra := 0;
cbClsExtra := 0;
hbrBackground := color_AppWorkSpace + 1;
end;
RegisterClass(Class);
end;
{ CreateWindow ----------------------------------------------------- }
procedure CreateWindows;
begin
HWindow := CreateWindow('DrawBits', 'Bitmap Viewer', ws_OverlappedWindow,
0, 0, 250, 200, 0, 0,
hInstance, nil);
if HWindow <> 0 then begin
ShowWindow(hWindow, sw_Minimize);
UpdateWindow(hWindow);
end;
end;
{ ShowBitmap ------------------------------------------------------- }
procedure ShowBitmap(Filename: PChar); export;
var
Pal: Word;
Height, Width: LongInt;
Pos: TRect;
Focus: HWnd;
begin
if HWindow <> 0 then begin
if Bitmap <> 0 then DeleteObject(Bitmap);
Bitmap := LoadBMP(Filename, 0, Pal, Width, Height);
Focus := GetFocus;
ShowWindow(hWindow, sw_Normal);
SetFocus(Focus);
GetWindowRect(HWindow, Pos);
SetWindowPos(HWindow, 0, Pos.left, Pos.top, Width + 8, Height + 24,
swp_NoActivate or swp_DrawFrame);
InvalidateRect(HWindow, nil, False);
end;
end;
{ EndSession ------------------------------------------------------- }
procedure EndSession; export;
begin
if IsWindow(HWindow) then DestroyWindow(HWindow);
end;
exports
SHOWBITMAP,
ENDSESSION;
{ ------------------------------------------------------------------ }
begin
RegisterClasses;
CreateWindows;
end.