コード例 #1
0
ファイル: ToolbarControl.cpp プロジェクト: GDXN/fitsliberator
/**
 * Creates an image list.
 * @param id Bitmap resource id.
 * @remark This method assumes that id+1 is the 32-bit toolbar image. Further images
 * can be added to support different color depths.
 * @return A handle to the imagelist or NULL on failure.
 */
HIMAGELIST ToolbarControl::CreateImageList( Int id ) {
    HIMAGELIST imageList = NULL;

    OSVERSIONINFO ovi;
    ovi.dwOSVersionInfoSize = sizeof(ovi);
    ::GetVersionEx( &ovi );

    if( ovi.dwMajorVersion >= 5 && ovi.dwMinorVersion >= 1 ) {
        // Windows XP or above
        Gdiplus::Bitmap* bitmap = ResourceManager::LoadImage( MAKEINTRESOURCE(id), "PNG" );
        if( bitmap != NULL ) {
            HBITMAP hBitmap;
            bitmap->GetHBITMAP(Gdiplus::Color(0xFFFFFFFF), &hBitmap);
            
            imageList = ImageList_Create( imageWidth, imageHeight, ILC_COLOR32, 6, 1 );
            ImageList_Add( imageList, hBitmap, NULL );

            ::DeleteObject( hBitmap );
            delete bitmap;
        }
    }
    else {
        HBITMAP hBitmap = (HBITMAP)::LoadImageA( g_hInstance, MAKEINTRESOURCE( id ), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );

        imageList = ImageList_Create( imageWidth, imageHeight, ILC_MASK | ILC_COLOR24, 6, 1 );
        ImageList_AddMasked( imageList, hBitmap, RGB(255, 0, 255) );

        ::DeleteObject( hBitmap );
    }

    IMAGEINFO ii;
    ImageList_GetImageInfo( imageList, 0, &ii );

    return imageList;
}
コード例 #2
0
bool CTuoImage::LoadFromFile(bool bPNG)
{
	std::wstring strPath;
	if (bPNG)
		strPath = g_strSkinDir + _T("\\") + m_strFileName + _T(".png");
	else
		strPath = g_strSkinDir + _T("\\") + m_strFileName + _T(".ico");

	Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromFile(strPath.c_str());
	if (pBitmap)
	{
		if (pBitmap->GetLastStatus() == Gdiplus::Ok)
		{
			if (m_hBitmap)
				::DeleteObject(m_hBitmap);
			pBitmap->GetHBITMAP(NULL, &m_hBitmap);
		}

		BITMAP bmpData;
		::GetObject(m_hBitmap, sizeof(BITMAP), &bmpData);
		m_iWidth = bmpData.bmWidth;
		m_iHeight = bmpData.bmHeight;
		m_bUseBitblt = bmpData.bmBitsPixel < 32;

		delete pBitmap;

		return true;
	}
	return false;
}
コード例 #3
0
ファイル: NaImage.cpp プロジェクト: neoarc/NaMacroJS
// description: load image from file using gdi+
NaImage * NaImage::Load(const wchar_t * filename)
{
	NaImage *pImage = new NaImage;
	HDC hDC = NaScreenModule::GetDesktopDC();
	pImage->m_hMemoryDC = ::CreateCompatibleDC(hDC);

	// initialize gdi+
	Gdiplus::GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR gdiplusToken;
	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	// load image
	Gdiplus::Image* pGdiImage = new Gdiplus::Image(filename);

	// converting to bitmap
	Gdiplus::Bitmap* pGdiBitmap = static_cast<Gdiplus::Bitmap*>(pGdiImage);
	pGdiBitmap->GetHBITMAP(Gdiplus::Color(0, 0, 0), &pImage->m_hBitmap);

	pImage->m_rc.left = 0;
	pImage->m_rc.top = 0;
	pImage->m_rc.right = pGdiImage->GetWidth();
	pImage->m_rc.bottom = pGdiImage->GetHeight();

	// shutdown gdi+
	delete pGdiImage;
	Gdiplus::GdiplusShutdown(gdiplusToken);

	return pImage;
}
コード例 #4
0
ファイル: native_menu_win.cpp プロジェクト: 276361270/appjs
int NativeMenu::AddSubMenu(HMENU& menu,Settings* settings){
  int length = settings->getInteger("length",0);

  Settings* item;
  TCHAR* label;
  TCHAR* icon;
  appjs_action_callback* actionCb;

  for( int i = 0; i < length; i++ ) {

    item = new Settings( settings->getObject( i ) );
    label  = item->getString("label",TEXT(""));
    icon   = item->getString("icon",TEXT(""));
    actionCb = new appjs_action_callback();
    actionCb->action = Persistent<Object>::New( item->getObject("action") );
    actionCb->item = Persistent<Object>::New( settings->getObject( i ) );
    actionCb->menu = this;

    Settings* subsettings = new Settings(item->getObject("submenu"));
    HMENU submenu = CreateMenu();
    if(AddSubMenu(submenu,subsettings)) { // has submenu
      MENUINFO menuInfo;
      memset(&menuInfo, 0, sizeof(menuInfo));
      menuInfo.cbSize = sizeof(menuInfo);
      menuInfo.fMask = MIM_STYLE;
      menuInfo.dwStyle = MNS_NOTIFYBYPOS;
      SetMenuInfo(submenu,&menuInfo);
      AppendMenu(menu,MF_POPUP,(UINT)submenu,label);
    } else { // does not have submenu
      MENUITEMINFO menuItemInfo;
      menuItemInfo.cbSize = sizeof(MENUITEMINFO);
      menuItemInfo.fMask = MIIM_DATA;
      menuItemInfo.dwTypeData = label;
      menuItemInfo.dwItemData =(ULONG_PTR) actionCb;
      menuItemInfo.cch = wcslen(label);

      if( wcslen(label) == 0 ) {
        menuItemInfo.fMask |= MIIM_TYPE;
        menuItemInfo.fType = MF_SEPARATOR;
      } else {
        menuItemInfo.fMask |= MIIM_STRING;
        if(item->has("icon")) {
          menuItemInfo.fMask |= MIIM_BITMAP;
          HBITMAP bitmap;
          Gdiplus::Color color;
          Gdiplus::Bitmap* img = Gdiplus::Bitmap::FromFile(icon);
          img->GetHBITMAP(color, &bitmap);
          menuItemInfo.hbmpItem = bitmap;
        }
      }
      InsertMenuItem(menu,i,false,&menuItemInfo);
    }
  }

  return length;
}
コード例 #5
0
bool CTuoImage::LoadFromFile(LPCTSTR lpszFileName, bool bShortName)
{
	std::wstring strFileName = lpszFileName;

	if (bShortName)
	{
		if (g_strSkinDir.size() == 0)
		{
			TCHAR szPath[MAX_PATH] = { 0 };
			::GetModuleFileName(NULL, szPath, _countof(szPath));
			TCHAR *p = _tcsrchr(szPath, '\\');
			if (p) *p = 0;

			g_strSkinDir = szPath;
			g_strSkinDir += _T("\\Skin\\");
		}

	}

	strFileName = g_strSkinDir + strFileName;
	//Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromFile(lpszFileName);
	Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromFile(strFileName.c_str());
	if (pBitmap)
	{
		if (pBitmap->GetLastStatus() == Gdiplus::Ok)
		{
			if (m_hBitmap)
				::DeleteObject(m_hBitmap);
			pBitmap->GetHBITMAP(NULL, &m_hBitmap);
		}

		BITMAP bmpData;
		::GetObject(m_hBitmap, sizeof(BITMAP), &bmpData);
		m_iWidth = bmpData.bmWidth;
		m_iHeight = bmpData.bmHeight;
		m_bUseBitblt = bmpData.bmBitsPixel < 32;

		delete pBitmap;

		return true;
	}
	return false;
}
コード例 #6
0
ファイル: util.cpp プロジェクト: weimingtom/sls
HBITMAP GXLoadFile(LPCTSTR lpszBitmapName)
{
	WCHAR szBuff[MAX_PATH];
	memset(szBuff, 0, MAX_PATH*sizeof(WCHAR));
	atow(lpszBitmapName, szBuff, MAX_PATH);
	Gdiplus::Bitmap *pImg = new Gdiplus::Bitmap(szBuff);
	if(!pImg)
	{
		printlog("Load %s failed!\n", lpszBitmapName);
		return NULL;
	}
	
	HBITMAP hBMP = NULL;
	Gdiplus::Color cr(255, 0, 255);
	pImg->GetHBITMAP(cr, &hBMP);
	
	HBITMAP hRet = (HBITMAP)CopyImage(hBMP, IMAGE_BITMAP, 0, 0, LR_COPYDELETEORG);
	delete pImg;
	
	return hRet;
}
コード例 #7
0
xMacPictureHandle	VPictureData_MacPicture::CreatePicHandle(VPictureDrawSettings* inSet, bool& outCanAddPicEnd) const
{
	void* result = NULL;
	VPictureDrawSettings set(inSet);
	outCanAddPicEnd = true;
	set.SetBackgroundColor(VColor(0xff, 0xff, 0xff));// pp no alpha
	if (set.IsIdentityMatrix())
	{
		result = _BuildPicHandle();
	}
	if (sQDBridge)
	{
		if (!result) // YT & PP - 24-Nov-2008 - ACI0059927 & ACI0059923
#if VERSIONWIN
		{
			Gdiplus::Bitmap* bm = CreateGDIPlus_Bitmap(&set);
			if (bm)
			{
				HBITMAP hbm;
				bm->GetHBITMAP(Gdiplus::Color(0xff, 0xff, 0xff), &hbm);
				if (hbm)
				{
					result = sQDBridge->HBitmapToPicHandle(hbm);
					DeleteObject(hbm);
				}
				delete bm;
			}
		}
#elif VERSIONMAC
		{
			result = sQDBridge->VPictureDataToPicHandle(*this, inSet);
		}
#endif
	}
	return (xMacPictureHandle) result;
}
コード例 #8
0
//// CMarkerStyle
bool CMarkerStyle::Init(const CString& fileName)
{
	if (fileName.Compare(L"") != 0)
		m_ImageFileName_ = fileName;
	if(m_ImageFileName_.Compare(L"") == 0)
		return false;
	// Read the texture bits
	//构建位图对象
	Gdiplus::Bitmap* bmp = Gdiplus::Bitmap::FromFile(m_ImageFileName_);
	m_ImageWidth_ = bmp->GetWidth();
	m_ImageHeight_ = bmp->GetHeight();

	//创建图片内容
	if(m_pdata_ != NULL)
	{
		delete[] m_pdata_;
		m_pdata_ = NULL;
	}
	m_pdata_ = new BYTE[m_ImageWidth_ * m_ImageHeight_ * 4];
	
	//根据位图对象创建GDI位图对象
	HBITMAP hBitMap;
	bmp->GetHBITMAP(Gdiplus::Color::White, &hBitMap);
	
	//根据GDI位图获取句柄给CBitmao
	CBitmap* cbmp = CBitmap::FromHandle(hBitMap);
	if (cbmp == NULL)
		return false;

	//获取图像数据
	DWORD size = cbmp->GetBitmapBits(m_ImageWidth_ * m_ImageHeight_ * 4, m_pdata_);
	for (int i = 0; i < m_ImageWidth_ * m_ImageHeight_; i++)
	{
		BYTE tmp = (m_pdata_[i * 4]);
		m_pdata_[i * 4 + 0] = (m_pdata_[i * 4 + 2]); //r
		m_pdata_[i * 4 + 2] = tmp;//b
	}

	cbmp->DeleteObject();
	DeleteObject(hBitMap);
	DeleteObject(bmp);


	//创建纹理
	if(m_texttureID_ > 0)
	{
		glDeleteTextures(1, &m_texttureID_);
		m_texttureID_ = -1;
	}
	//创建贴图对象
	glGenTextures(1, &m_texttureID_);
	//绑定贴图对象
	//glPixelStorei(GL_UNPACK_ALIGNMENT, 1); //按照一位对齐
	glBindTexture(GL_TEXTURE_2D, m_texttureID_);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_ImageWidth_, m_ImageHeight_, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_pdata_);
	//跟新部分区域
	//glTexSubImage2D(GL_TEXTURE_2D, 0, 100, 100, 56, 56, GL_RGBA, GL_UNSIGNED_BYTE, m_pdata_);
	//过滤模式
	//放大过滤
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);	
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	
	//超过TS坐标时候的采样
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);	
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	return true;
}
コード例 #9
0
ファイル: image_win.cpp プロジェクト: Ambrevar/fr_public
sImage *sLoadImageWin32(sFile *file)
{
  sImage *img=0;

  Gdiplus::Status st;
  Gdiplus::Color background(0,0,0,0);
  Gdiplus::Bitmap *gdibitmap = Gdiplus::Bitmap::FromStream(&sIStreamWrapper(file),TRUE);

  HBITMAP hbmp=0;
  st = gdibitmap->GetHBITMAP(background,&hbmp);

  if (!st) 
  {
    BITMAP    bmp;
    GetObject(hbmp,sizeof(bmp),&bmp);
    sVERIFY(bmp.bmType==0 && bmp.bmPlanes==1);

    if (bmp.bmType==0 && bmp.bmPlanes==1)
    {
    
      sBool topdown=sFALSE;
      if (bmp.bmHeight<0)
      {
        bmp.bmHeight*=-1;
        topdown=sTRUE;
      }

      img = new sImage(bmp.bmWidth,bmp.bmHeight);

      sU8 *s = (sU8*)bmp.bmBits;
      switch(bmp.bmBitsPixel)
      {
      case 24:
        for(sInt y=0;y<img->SizeY;y++)
        {
          sU32 *d;
          if (topdown)
            d = img->Data + y*img->SizeX;
          else
            d = img->Data + (img->SizeY-1-y)*img->SizeX;

          for(sInt x=0;x<img->SizeX;x++,s+=3)
            *d++ = 0xff000000|(s[0])|(s[1]<<8)|(s[2]<<16);
        }
        break;

      case 32:
        for(sInt y=0;y<img->SizeY;y++)
        {
          sU32 *d;
          if (topdown)
            d = img->Data + y*img->SizeX;
          else
            d = img->Data + (img->SizeY-1-y)*img->SizeX;

          for(sInt x=0;x<img->SizeX;x++,s+=4)
            *d++ = *(sU32*)s;
        }
        break;

      default:
        sLogF(L"ERROR",L"can't load bmp with %d bits per pixel\n",bmp.bmBitsPixel);
        sDelete(img);
      }
    }

    DeleteObject(hbmp);
  }

  delete gdibitmap;
  return img;
}
コード例 #10
0
ファイル: zipk.cpp プロジェクト: wangch/zipk
static int add_items1() {
   LVITEM lvi;
   lvi.pszText   = L"";
   lvi.mask      = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
   lvi.stateMask = 0;
   lvi.iSubItem  = 0;
   lvi.state     = 0;
   node* n = g_lv.n;
   ::ImageList_Destroy(g_lv.il);
   OSVERSIONINFO os;
   os.dwOSVersionInfoSize=sizeof(os);
   ::GetVersionEx(&os);

   if (os.dwMajorVersion > 5) { 
      g_lv.il = ::ImageList_Create(92, 70, ILC_COLOR32|ILC_MIRROR|ILC_ORIGINALSIZE|ILC_HIGHQUALITYSCALE, 1, 1);
   } else {
      g_lv.il = ::ImageList_Create(92, 70, ILC_COLOR32|ILC_MIRROR, 1, 1);
   }
   HIMAGELIST il = g_lv.il;
   ListView_SetImageList(g_lv.lv, il, LVSIL_NORMAL);

   std::vector<node*>::iterator it = n->childs.begin();
   for (int i = 0; it != n->childs.end(); ++it, ++i) {
      node* c = *it;
      lvi.iItem = i;
      if (c->type == 1) {
         image img = unzip_img(c, g_lv.unz);
         if (img.img) {
            Gdiplus::Image* pm;
            if (os.dwMajorVersion > 5) {
               Gdiplus::Rect rc = fit_rc(92, 70, img.img);
               pm = img.img->GetThumbnailImage(rc.Width, rc.Height);
            } else { 
               pm = img.img->GetThumbnailImage(92, 70);
            }
            Gdiplus::Bitmap* bmp = static_cast<Gdiplus::Bitmap*>(pm);
            if (bmp) {
               HBITMAP hbmp;
               bmp->GetHBITMAP(Gdiplus::Color(0,0,0), &hbmp);
               ::ImageList_Add(il, hbmp, NULL);
               ::DeleteObject((HGDIOBJ)hbmp);
               delete pm;
            }
            delete img.img;
            ::GlobalFree(img.hg);
         }
      } else {        
         SHFILEINFO si;
         if (c->type == 0) {
            SHGetFileInfo(L"folder", FILE_ATTRIBUTE_DIRECTORY, &si, sizeof(si),
               SHGFI_USEFILEATTRIBUTES|SHGFI_SMALLICON|SHGFI_LARGEICON|SHGFI_SYSICONINDEX);
         } else {
            int pos = c->name.find(L'.');
            if (pos != std::wstring::npos) {
               std::wstring sf = c->name.substr(pos);
               SHGetFileInfo(sf.c_str(), FILE_ATTRIBUTE_NORMAL, &si, sizeof(si),
                  SHGFI_USEFILEATTRIBUTES|SHGFI_SMALLICON|SHGFI_LARGEICON|SHGFI_SYSICONINDEX);
            } else {
               SHGetFileInfo(L"file", FILE_ATTRIBUTE_NORMAL, &si, sizeof(si),
                  SHGFI_USEFILEATTRIBUTES|SHGFI_SMALLICON|SHGFI_LARGEICON|SHGFI_SYSICONINDEX);
            }
         }
         HIMAGELIST* himglst;
         HRESULT r = ::SHGetImageList(SHIL_EXTRALARGE, IID_IImageList, (void**)&himglst);
         if (r == S_OK) {
            HICON hIcon;
            r = ((IImageList*)himglst)->GetIcon(si.iIcon, ILD_TRANSPARENT, &hIcon);
            if (r == S_OK) {    
               ImageList_AddIcon(il, hIcon);
            }
         }
      }
      lvi.iImage = i;
      lvi.lParam = (LPARAM)c;
      ListView_InsertItem(g_lv.lv, &lvi);
      add_subtxt(i, c);
   }
   return 0;
}