Code:
class image
{
private:
ULONG_PTR m_gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
BitmapDC HBitmap;
Image *img=NULL;
bool isimgused=false;
bool isGDIPLUSIniciated=false;
int imageheight=0;
int imageweight=0;
int framecount=0;
int intSelectFrame=0;
int framedelay=0;
string strfilename="";
Gdiplus::Color clrBackColor=Gdiplus::Color::Blue;
bool blnTransparent=true;
HPEN imgPen;
HBRUSH imgBrush;
CHOOSEFONT chFont;
void readimagefile(string filename)
{
if (isimgused==true)
delete img;
strfilename=filename;
if(toupper(filename[filename.size()-3])=='C' && toupper(filename[filename.size()-2])=='U' && toupper(filename[filename.size()-1])=='R')
{
isimgused=false;
//create the transparent icon handle
HCURSOR hicon = (HCURSOR)LoadImage(NULL, filename.c_str(), IMAGE_CURSOR, imageweight, imageheight, LR_LOADFROMFILE|LR_SHARED|LR_DEFAULTSIZE|LR_LOADTRANSPARENT);
ICONINFO ii;
BOOL fResult = GetIconInfo(hicon, &ii);
if (fResult)
{
BITMAP bm;
fResult = GetObject(ii.hbmMask, sizeof(bm), &bm) == sizeof(bm);
if (fResult)
{
imageweight= bm.bmWidth;
imageheight= ii.hbmColor ? bm.bmHeight : bm.bmHeight / 2;
}
if (ii.hbmMask)
DeleteObject(ii.hbmMask);
if (ii.hbmColor)
DeleteObject(ii.hbmColor);
}
HBitmap.size(imageweight,imageheight);
DrawIconEx(HBitmap,0,0,hicon,imageweight,imageheight,0,0,DI_NORMAL);
framecount=1;
DestroyCursor(hicon);
}
else
{
isimgused=true;
Gdiplus::Image img2(towstring(filename).c_str());
imageweight=img2.GetWidth();
imageheight=img2.GetHeight();
HBitmap.size(imageweight,imageheight);
Gdiplus::Graphics graphics(HBitmap);
graphics.DrawImage(&img2, 0,0,imageweight,imageheight);
UINT count = 0;
count = img2.GetFrameDimensionsCount();
GUID* pDimensionIDs = (GUID*)malloc(sizeof(GUID)*count);
img2.GetFrameDimensionsList(pDimensionIDs, count);
framecount=img2.GetFrameCount(&pDimensionIDs[0]);
framedelay =img2.GetPropertyItemSize(PropertyTagFrameDelay);
img=new Image(towstring(filename).c_str());
isimgused=true;
free(pDimensionIDs);
}
}
HICON HICONFromHBITMAP(HBITMAP bitmap)
{
BITMAP bmp;
GetObject(bitmap, sizeof(BITMAP), &bmp);
HBITMAP hbmMask = CreateCompatibleBitmap(HBitmap, bmp.bmWidth, bmp.bmHeight);
ICONINFO ii = {0};
ii.fIcon = TRUE;
ii.hbmColor = bitmap;
ii.hbmMask = hbmMask;
HICON hIcon = CreateIconIndirect(&ii);
DeleteObject(ii.hbmColor);
DeleteObject(ii.hbmMask);
return hIcon;
}
public:
void resize(const int width, const int height)
{
imageheight=height;
imageweight=width;
HBitmap.size(imageweight,imageheight);
}
image()
{
if (isimgused==true)
delete img;
isimgused=false;
if(isGDIPLUSIniciated==false)
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
isGDIPLUSIniciated=true;
}
imageheight=1;
imageweight=1;
HBitmap.size(imageweight,imageheight);
}
image(const int width, const int height)
{
if (isimgused==true)
delete img;
isimgused=false;
if(isGDIPLUSIniciated==false)
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
isGDIPLUSIniciated=true;
}
framecount=1;
imageheight=height;
imageweight=width;
HBitmap.size(imageweight,imageheight);
}
image( const string & filename)
{
if(isGDIPLUSIniciated==false)
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
isGDIPLUSIniciated=true;
}
readimagefile(filename);
}
image (const image &cSource)
{
if(isGDIPLUSIniciated==false)
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
isGDIPLUSIniciated=true;
}
readimagefile(cSource.strfilename);
BitBlt(HBitmap,0,0,imageweight,imageheight,cSource.HBitmap,0,0,SRCCOPY);
}
image& operator= (const image &cSource)
{
if (this == &cSource) // Same object?
return *this;
if(isGDIPLUSIniciated==false)
{
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
isGDIPLUSIniciated=true;
}
readimagefile(cSource.strfilename);
BitBlt(HBitmap,0,0,imageweight,imageheight,cSource.HBitmap,0,0,SRCCOPY);
return *this;
}
operator HICON()//these is returned
{
return HICONFromHBITMAP(HBitmap);
}
operator HBITMAP()//these isn't returned
{
return HBitmap;
}
////..............
and now my class Menu:
Code:
class Menu
{
private:
static int intID;
boolean blncheck=false;
int ID=0;
HMENU mnuBar=NULL;
HMENU MenuHandle=NULL;//i must correct these ;)
HMENU MenuPopup=NULL;
HWND Mainwindow=NULL;
bool ispopup=false;
bool primeiromenu=false;
int menuposition=0;
string strCaption="";
image imgMenu;
void bitmap(image imgImage)
{
imgMenu=imgImage;
imgMenu.Backcolor=GetSysColor(COLOR_MENU);
HMENU hMenu = NULL;
if(primeiromenu)
hMenu = mnuBar;
else
hMenu = MenuHandle;
SetMenuItemBitmaps(hMenu,ID,MF_BYCOMMAND,(HBITMAP)imgMenu ,(HBITMAP)imgMenu);
}
my problem is that i don't recive the HBITMAP image. only the size