我在做一个不使用VCL的程序,有没有简单的办法在我的窗口里显示图片?
program NoVCL2;0D
uses
windows,Messages,Activex;
{$R *.RES}
function OleLoadPictureFile(varFileName:OleVariant;
var lplpdispPicture:IDispatch):HResult;stdcall;external OleAut32.dll index 422;
//ActiveX单元中的声明有错误,这里要自己声明一个。
type
PRect=^TRect;
var
hwndMain: HWND ;
msg : TMSG ;
wc: TWNDCLASS ;
i:Integer;
DispPic:IDispatch;
aPic:IPicture;
PicW,PicH:LongInt;
function MainProc( hwndMe:HWND;uMsg,wParam,lParam:Integer):LongInt;stdcall;
var
aDC:HDC;
ps:TPaintStruct;
ClientRect:TRect;
begin
case uMsg of
WM_CREATE:
begin
if OleLoadPictureFile(e:\test1.gif,DispPic) < 0 then
MessageBox(hwndMe,Load Picture Error!,nil,MB_OK)
else
begin
aPic := DispPic as IPicture;
aPic.get_Width(PicW);
aPic.get_Height(PicH);
end;
end;
WM_PAINT:
begin
GetClientRect(hwndMe,ClientRect);
aDC := BeginPaint(hwndMe,ps);
aPic.Render(adc,0,0,ClientRect.Right,ClientRect.Bottom,0,PicH-1,PicW,-PicH,PRect(Nil)^);
EndPaint(hwndMe,ps);0D
end;
WM_DESTROY:
PostQuitMessage(0);
WM_LBUTTONDOWN:
begin
WinExec(PChar(C:\WINNT\explorer.exe),SW_NORMAL);0D
end;
end;
Result := DefWindowProc(hwndMe,uMsg,wParam,lParam);
end;
begin
CoInitialize(nil);
wc.style := CS_VREDRAW or CS_HREDRAW;
0A wc.lpfnWndProc := @MainProc;
wc.cbClsExtra := 0;
wc.cbWndExtra := 0;
wc.hInstance := hInstance;
wc.hIcon := LoadIcon(0, IDI_APPLICATION);
wc.hCursor := LoadCursor(0, IDC_ARROW);
0A wc.hbrBackground := 0;//GetStockObject(GRAY_BRUSH);
wc.lpszMenuName := nil;
wc.lpszClassName := MainWndClass;
if (RegisterClass(wc) = 0) then
exit;
hwndMain := CreateWindow(MainWndClass, Sample,
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, 0,
0, HInstance, nil);
if (hwndMain =0) then
exit;
ShowWindow(hwndMain, SW_NORMAL);
UpdateWindow(hwndMain);
0A
while (GetMessage(msg, 0, 0, 0)) do
begin
TranslateMessage(msg);
0A DispatchMessage(msg);
0A end;
CoUninitialize;
end.
轻风又伤心了:2002-06-04
____ ____
\ p \ / g /
\ l \_/ n /
\ a o /
\ i s /
\ n /
\_/