您现在的位置:首页 >> 界面报表 >> 界面报表 >> 内容

Delphi中如何不使用VCL来显示图片

时间:2011/9/3 15:24:09 点击:

  核心提示:Delphi2007下调试通过program NoVCLPic;uses Windows,Messages,ActiveX;function OleLoadPictureFile(varFileNam...

Delphi2007下调试通过

program NoVCLPic;

uses
  Windows,Messages,ActiveX;

function OleLoadPictureFile(varFileName:OleVariant;var lplpdispPicture:IDispatch):HResult;stdcall;external 'OleAut32.dll' index 422;

type
  PRect=^TRect;
 
var
  hwndMain:HWND;
  msg :TMSG;
  wc:TWNDCLASS;
  DispPic:IDispatch;
  aPic:IPicture;
  PicW,PicH:LongInt;

const
  PicFile='D:\radiogroupbutton.gif';

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(PicFile,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);
    end;
    WM_DESTROY:
        PostQuitMessage(0);
    WM_LBUTTONDOWN:
    begin
      WinExec(PChar('C:\Windows\explorer.exe'),SW_NORMAL);
    end;
  end;
  Result:= DefWindowProc(hwndMe,uMsg,wParam,lParam);
end;

begin
  CoInitialize(nil);
  try
    wc.style := CS_VREDRAW or CS_HREDRAW;
    wc.lpfnWndProc := @MainProc;
    wc.cbClsExtra := 0;
    wc.cbWndExtra := 0;
    wc.hInstance := hInstance;
    wc.hIcon := LoadIcon(0,IDI_APPLICATION);
    wc.hCursor := LoadCursor(0,IDC_ARROW);
    wc.hbrBackground := 0;//GetStockObject(GRAY_BRUSH);
    wc.lpszMenuName := nil;
    wc.lpszClassName := 'MainWndClass';
    if (RegisterClass(wc)= 0) then Exit;
    hwndMain := CreateWindow('MainWndClass','NoVCLLoadPic',
        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);
    while (GetMessage(msg,0, 0,0)) do
    begin
      TranslateMessage(msg);
      DispatchMessage(msg);
    end;
  finally
   CoUninitialize;
  end;
end.



迅雷专用高速下载

作者:网络 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号