您的位置: tenysw的博客——
« 据说不伤眼睛的文字背景色

不使用VCL来显示图片

分类: 技术文章 发布: tenysw 浏览: 日期: 2010年1月31日


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.

相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-Blog 1.8 Walle Build 91204

Copyright www.Pckno.Com. Some Rights Reserved.   鲁ICP 备:07504114号