[Prev][Next][Index][Thread]

Re: win32 bitmaps question



kachinadtm@my-deja.com writes:

> I would like to arbitrary sized bitmaps in my application but larger
> than the examples shown.

Harlequin Dylan 1.2 and versions prior to that had problems dealing
with images and not all the functionality worked. Things like the
macros for doing double buffering, etc would draw the images
incorrectly.

The HD 2.0 beta fixed those problems and for the cases where I was
using the standard image functionality, things worked fine. I haevn't
used the win32 image stuff though. What version of HD are you using?

> Also it seems kind of awkward to have all the bitmaps referenced in
> the project sources.  I would like to grab them at runtime, like
> looking up a file.

I think you'll probably need to write the bitmap reading functions
yourself, or use a C library and use the c-ffi to access it. You can
load the image and manipulate it using the Dylan image functions, or
work with the Win32 API. If you can find something that loads a bitmap
and gives you an HBITMAP to it, something like the functions below may
allow you to blit it to Dylan panes (code copied, pasted and modified
from a pre HD 1.2 application so it may not be needed with HD 2.0):

---------------------8<--------------------
define C-variable application-module-handle :: <HMODULE>
  import: #f,
  setter: #f,
  c-name: "module_hInstance"; // in the Dylan pentium runtime
end;

define class <win32-bitmap> (<image>)
  constant slot bitmap-handle :: <HBITMAP>, 
    required-init-keyword: handle:;
end class <win32-bitmap>;

define method initialize( image :: <win32-bitmap>, #key)
  unless(automatic-finalization-enabled?())
    automatic-finalization-enabled?-setter( #t );
  end;
  finalize-when-unreachable( image );
end method initialize;

define method finalize( image :: <win32-bitmap> ) => ()
  DeleteObject(image.bitmap-handle);
  next-method();
end method finalize;

define method image-dimensions( image :: <win32-bitmap> ) 
  => (height :: <integer>, width :: <integer> )
  with-stack-structure( b :: <LPBITMAP> )
    GetObject( image.bitmap-handle, size-of(<BITMAP>), b );
    values( b.bmHeight-value, b.bmWidth-value );
  end with-stack-structure;
end method image-dimensions;

define method image-width ( image :: <win32-bitmap> ) 
 => (width :: <integer>)
  let (h, w) = image-dimensions( image );
  w;
end method image-width;

define method image-height ( image :: <win32-bitmap> ) 
 => (height :: <integer>)
  let (h, w) = image-dimensions(image);
  h;
end method image-height;

// Loads from a resource
define method read-image-as( class == <win32-bitmap>, 
  locator, 
  image-type, #key, #all-keys)
 => (image :: false-or(<image>))
  make(<win32-bitmap>, 
    handle: LoadBitmap(application-module-handle(), locator));
end method read-image-as;

// Blit to a pane
define method draw-image( m :: <drawing-pane>, 
  image :: <win32-bitmap>, x, y) 
  => (record)
  let m = m.sheet-medium;
  let hdc = m.medium-drawable.get-dc;
  let newdbc = CreateCompatibleDC(hdc);
  let old = SelectObject(newdbc, image.bitmap-handle);
  let (height, width) = image-dimensions( image );
  BitBlt(hdc, x, y, width, height, newdbc, 0, 0, $SRCCOPY);
  SelectObject(newdbc, old);
  DeleteDC(newdbc);
end method draw-image;

---------------------8<--------------------

You'll need to include the module win32-duim to get access to some of
the duim internal stuff. If you need more info I can pop a toy project
up for download if it would be useful.


Chris.
-- 
http://www.double.co.nz/dylan



References: