SOL9 2.0 Class: Icon

 SOL9 C++ Class Library  SOL9 Samples  SOL9 Tutorial  SOL9 FAQ  SOL9 ClassTree 

Source code

/*
 * Icon.h 
 * Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL++2000
#pragma once

#include <sol\Resource.h>

//2009/10/13
#include <sol/MessageFont.h>

namespace SOL {

class Icon :public Resource {
private:
    int x;
    int y;
    int width;
    int height;
    BOOL destructable;
    MessageFont mfont;

public:

    Icon(const TCHAR* name, HICON hicon)
    :Resource(name, hicon)
    {
        x       = 0; 
        y       = 0;
        width   = ::GetSystemMetrics(SM_CXICON);
        height  = ::GetSystemMetrics(SM_CYICON);
        destructable = FALSE;

        mfont.create(9);
    }

public:
    ~Icon() { 
        if(destructable) {
            ::DestroyIcon((HICON)get());
        }
    }

public:
    void draw(HDC hdc, int x1, int y1) 
    {
        TCHAR* name = getName();
        SIZE size;
        ::GetTextExtentPoint(hdc, name, strlen(name), &size);
        int   w    = size.cx;
        HGDIOBJ prev = SelectObject(hdc, mfont.getFont());
        ::DrawIcon(hdc, x+x1, y+y1, (HICON)get());
        ::TextOut(hdc, x+x1-(w-width)/2,
             y+y1+ height + 4 , 
             name, strlen(name));
        SelectObject(hdc, prev);
    }

public:
    void draw(HDC hdc, int x1, int y1, int cx, int cy,
                UINT index, HBRUSH hbrSrc,
                UINT flags) 
    {
        TCHAR* name = getName();
        SIZE size;
        ::GetTextExtentPoint(hdc, name, strlen(name), &size);
        int   w    = size.cx;
        HGDIOBJ prev = SelectObject(hdc, mfont.getFont());
        ::DrawIconEx(hdc, x+x1, y+y1, (HICON)get(),
            cx, cy, index, hbrSrc, flags);
        ::TextOut(hdc, x+x1-(w-width)/2,
             y+y1+ height + 4 , 
             name, strlen(name));
        SelectObject(hdc, prev);

    }

public:
    BOOL    getIconInfo(ICONINFO* info) {
        return ::GetIconInfo((HICON)get(), info);
    }

public:
    void    move(int x1, int y1) {
        x = x1;    
        y = y1;
    }

    void    setFlag(int flag) {
        destructable = flag;
    }
    void    getSize(int* w, int* h) {
            *w = width; *h = height;
    }
};

}



Last modified: 1 Feb 2012

Copyright (c) 2009-2012 Antillia.com ALL RIGHTS RESERVED.