Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

## resource_painter

resource_painter lets you load resources from a module (exe or dll) and draws them. Supported resources are bitmaps, icons and cursors. If the resource is larger than the drawing-rectangle of the painter the resource will be clipped.

    namespace win32 { namespace gui {

         namespace bg_wnd {

              struct res_info
              {
                   static HINSTANCE module_handle();

                   res_info(unsigned nResource, unsigned uType, int cx = 0, int cy = 0, unsigned fuLoad = LR_DEFAULTCOLOR | LR_DEFAULTSIZE, HINSTANCE hInst = module_handle());
                   res_info(const char* pchResource, unsigned uType, int cx = 0, int cy = 0, unsigned fuLoad = LR_DEFAULTCOLOR | LR_DEFAULTSIZE, HINSTANCE hInst = module_handle());

                   const char* pchResource_;
                   unsigned    uType_;
                   int         cx_;
                   int         cy_;
                   unsigned    fuLoad_;
                   HINSTANCE   hInst_;
              };

         }    // namespace bg_wnd

         // ========================================================================================================= //

         namespace detail {

              struct resource_painter_base : painter_base
              {
                   typedef const bg_wnd::res_info& param0;

                   void load_resource(const bg_wnd::res_info& info);
                   SIZE resource_size() const;
              };

         }    // namespace detail

         // ========================================================================================================= //

         class resource_painter : public detail::resource_painter_base
         {
         public:
              // c'tor
              resource_painter(const bg_wnd::res_info& info);

              // virtual functions of painter_base
              resource_painter* clone() const;
              void draw(HDC hDC, int cx, int cy);
         };

    } }  // namespace win32::gui

Note:
  - `get_resource_size()` returns the size of the currently loaded resource or SIZE(0, 0) if there is no resource
  - bg_wnd::res_info stores information about the resource to be loaded. For a detailed description of the parameters view `LoadImage()` in your MSDN

Example:

    add_painter<resource_painter> (bg_wnd::res_info(IDI_BACKGROUND_WND, IMAGE_ICON));

The result is as follows

## tile_resource_painter

The tile_resource_painter does the same as the resource_painter with the difference that the resource will be displayed in tiles. You can optionally set the size of the tiles.

    namespace win32 { namespace gui {

         class tile_resource_painter : public detail::resource_painter_base
         {
         public:
              typedef SIZE param1;

              // c'tor
              tile_resource_painter(const bg_wnd::res_info& info);
              tile_resource_painter(const bg_wnd::res_info& info, SIZE tile_size);

              // virtual functions of painter_base
              tile_resource_painter* clone() const;
              void draw(HDC hDC, int cx, int cy);

              // own functions
              void tile_size(SIZE tile_size);
              SIZE tile_size() const;
         };

    } }  // namespace win32::gui

Note:
  - The same as for resource_painter applies to this class
  - `tile_size()` sets and returns the current tile size. If the image is larger it will be clipped. By default the tile size is cx = 0, cy = 0 which means the painter shall determine the size of the image and use that size

Example:

    const SIZE tile_size = ...;
    add_painter<tile_resource_painter> (bg_wnd::res_info(IDI_BACKGROUND_WND, IMAGE_ICON), tile_size);

The result is as follows

tile_size = { 16, 16 } | tile_size = { 0, 0 } (determine resource size) | tile_size = { 45, 45 }

| by Steven Weiss. You can contact me at steven11@gmx.de.