Minigui学习--icon

icon类型:HICON

定义在/minigui/gdi.h文件中

1.创建icon

/**
 * \fn HICON GUIAPI CreateIconEx (HDC hdc, int w, int h, \
                const BYTE* AndBits, const BYTE* XorBits, int colornum, \
                const RGB* pal)
 * \brief Creates an icon object from the memory.
 *
 * This function creates an icon from memory data rather than icon file.
 * \a w and \a h are the width and the height of the icon respectively.
 * \a pANDBits and \a pXORBits are AND bitmask and XOR bitmask of the icon.
 * MiniGUI currently support mono-color cursor 256-color icon and 16-color icon,
 * \a colornum specifies the cursor's color depth. For mono-color, it should
 * be 1, and for 16-color cursor, it should be 4.
 *
 * \param hdc The device context.
 * \param w The width of the icon.
 * \param h The height of the icon.
 * \param AndBits The pointer to the AND bits of the icon.
 * \param XorBits The pointer to the XOR bits of the icon.
 * \param colornum The bit-per-pixel of XOR bits.
 * \param pal The palette of icon.
 * \return The handle to the icon object, zero means error occurred.
 *
 * \sa LoadIconFromFile
 */
MG_EXPORT HICON GUIAPI CreateIconEx (HDC hdc, int w, int h,
                const BYTE* AndBits, const BYTE* XorBits, int colornum,
                const RGB* pal);
/**
 * \def CreateIcon
 * \sa CreateIconEx
 */
#define CreateIcon(hdc, w, h, AndBits, XorBits, colornum) \
        CreateIconEx(hdc, w, h, AndBits, XorBits, colornum, NULL)

2.从文件中加载icon

/**
 * \fn HICON GUIAPI LoadIconFromFile (HDC hdc, const char* filename, int which)
 * \brief Loads an icon from a Windows ICO file.
 *
 * This function loads an icon from a Windows ICO file named \a filename
 * and creates an icon object. This function can load mono-,16-color and
 * 256-color icons.Some Windows ICO file contain two icons in different
 * sizes. You can tell this function to load which icon though \a which,
 * 0 for the first icon, and 1 for the second icon. Generally, the later
 * icon is the larger icon.
 * \param hdc The device context.
 * \param filename The file name of the ICO file.
 * \param which Tell the function to load which icon.
 * \return The handle to the icon object, zero means error occurred.
 *
 * \sa CreateIconEx
 */
MG_EXPORT HICON GUIAPI LoadIconFromFile (HDC hdc, const char* filename,
                int which);

 

3.绘制icon

/**
 * \fn void GUIAPI DrawIcon (HDC hdc, \
                int x, int y, int w, int h, HICON hicon)
 * \brief Draws an icon into a box.
 *
 * This function draws an icon object \a hicon into a box specified by
 * \a (x,y,w,h).
 *
 * \param hdc The device context.
 * \param x The x coordinate of the upper-left corner of the box.
 * \param y The y coordinate of the upper-left corner of the box.
 * \param w The width of the box.
 * \param h The height of the box.
 * \param hicon The icon object.
 *
 * \sa CreateIconEx, LoadIconFromFile
 */
MG_EXPORT void GUIAPI DrawIcon (HDC hdc,
                int x, int y, int w, int h, HICON hicon);

 

4.销毁icon

/**
 * \fn BOOL GUIAPI DestroyIcon (HICON hicon)
 * \brief Destroys an icon object.
 *
 * This function destroys the icon object \a hicon.
 *
 * \param hicon The icon object.
 * \return TRUE on success, otherwise FALSE.
 *
 * \sa CreateIconEx, LoadIconFromFile
 */
MG_EXPORT BOOL GUIAPI DestroyIcon (HICON hicon);

你可能感兴趣的:(minigui学习)