BOOL  COBSButton::ChangeSubPic(STATE index, LPCTSTR lpszImage)
{
	if (m_hWnd == NULL || lpszImage == NULL)
	{
		return FALSE;
	}
	Gdiplus::Image* pImage = Gdiplus::Image::FromFile(lpszImage);
	if ((pImage == NULL) || (pImage->GetLastStatus() != Gdiplus::Ok))
	{
		if (pImage)
		{
			delete pImage;
			pImage = NULL;
		}
		return FALSE;
	}
	
	int nPos = pImage->GetWidth()*index;//¼ÆËã4ÕÅͼƬÐèÒª¶àÉÙÏñËØ
	
	Gdiplus::Graphics graph(m_hdcMemory);
	graph.SetSmoothingMode(Gdiplus::SmoothingModeNone);
	graph.DrawImage(pImage, nPos, 0, pImage->GetWidth(), pImage->GetHeight());

	return TRUE;
}
Beispiel #2
0
static Gdiplus::Image* bkimg(int rcid) {
   HRSRC hrsc = ::FindResource(hInst, MAKEINTRESOURCE(rcid), TEXT("PNG"));
   DWORD size = ::SizeofResource(hInst, hrsc);
   LPVOID hg = ::LoadResource(hInst, hrsc);
   HGLOBAL mem = ::GlobalAlloc(GMEM_MOVEABLE, size);
   Gdiplus::Image* img = 0;
   if (mem) {
      LPVOID pmem = ::GlobalLock(mem);
      if (pmem) {
         ::CopyMemory(pmem, hg, size);
         LPSTREAM is;
         if (::CreateStreamOnHGlobal(pmem, FALSE, &is) == S_OK) {
            Gdiplus::Image* m = new Gdiplus::Image(is);
            is->Release();
            if (m->GetLastStatus() != Gdiplus::Ok) {
               delete m;
               return img;
            }
            img = m;
         }
         ::GlobalUnlock(mem);
      }
      ::GlobalFree(mem);
   }
   return img;
}
Beispiel #3
0
	void OnCmdFileOpen(HWND hWnd)
	{
		winx::OpenFileDialog dlg(
			_T("Images Files(*.jpg;*.png;*.tif;*.bmp;*.gif)\0*.jpg;*.png;*.tif;*.bmp;*.gif\0All Files(*.*)\0*.*\0")
			);
		if (IDOK == dlg.DoModal())
		{
 			USES_CONVERSION;
 			Gdiplus::Image* image = new Gdiplus::Image(T2CW(dlg.lpstrFile));
 			if (image->GetLastStatus() != Gdiplus::Ok)
			{
				delete image;
				winx::ExMsgBoxTrace(hWnd, _T("Error"), _T("Can't load image from %s"), dlg.lpstrFile);
 			}
 			else
 			{
 				SetImage(image);
 			}
		}
	}
BOOL COBSButton::Create(LPCTSTR lpszCaption, const RECT& rect, HWND hParentWnd, \
	UINT nID, LPCTSTR lpszImage,int nSubPic)
{
	if (m_hWnd)
		return FALSE;
	if (nSubPic>4||nSubPic<=0)
	{
		return FALSE;
	}
	m_hWnd = CreateWindow(TEXT("BUTTON"), lpszCaption, \
		WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_OWNERDRAW, \
		rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, \
		hParentWnd, (HMENU)nID, NULL, NULL);

	if (NULL == m_hWnd)
	{
		goto CREATE_FAIL;
	}
	SendMessage(m_hWnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
	m_OldProc = (WNDPROC)SetWindowLong(m_hWnd, GWLP_WNDPROC /*GWL_WNDPROC*/, (LONG)ButtonProc);
	SetWindowLong(m_hWnd, GWLP_USERDATA, (LONG)this);

	m_hFont = CreateFont(16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, 0, DEFAULT_CHARSET, \
		OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, TEXT("Arial"));

	Gdiplus::Image* pImage = NULL;
	//¼ÓÔØͼƬ
	if (lpszImage != NULL)
	{

		
		pImage = Gdiplus::Image::FromFile(lpszImage);
		if ((pImage == NULL) || (pImage->GetLastStatus() != Gdiplus::Ok))
		{
			if (pImage)
			{
				delete pImage;
				pImage = NULL;
			}
			return FALSE;
		}
		RECT windowRect;
		GetWindowRect(m_hWnd, &windowRect);
		SIZE sizeWindow;
		sizeWindow.cx = (pImage->GetWidth() / nSubPic)*4;//¼ÆËã4ÕÅͼƬÐèÒª¶àÉÙÏñËØ
	    sizeWindow.cy = pImage->GetHeight();
		
		HDC hDC = GetDC(m_hWnd);
		m_hdcMemory = CreateCompatibleDC(hDC);
		if (m_hdcMemory == NULL) return FALSE;
		m_hFourStateBitmap = CreateCompatibleBitmap(hDC, sizeWindow.cx, sizeWindow.cy);
		if (m_hFourStateBitmap == NULL) return FALSE;
		m_hOldBmp = (HBITMAP)::SelectObject(m_hdcMemory, m_hFourStateBitmap);
		if (m_hOldBmp == NULL) return FALSE;
		Gdiplus::Graphics graph(m_hdcMemory);
		graph.SetSmoothingMode(Gdiplus::SmoothingModeNone);
		graph.DrawImage(pImage, 0, 0, sizeWindow.cx, sizeWindow.cy);

		if (NULL == m_hFourStateBitmap)
		{
			goto CREATE_FAIL;
		}
	}




	if (pImage)
	{
		delete pImage;
		pImage = NULL;
	}

	return TRUE;

CREATE_FAIL:
	if (m_hFourStateBitmap)
	{
		DeleteObject(m_hFourStateBitmap);
	}
	return FALSE;
}
Beispiel #5
0
LRESULT
BlobMgmt::ShowImage()
{
#ifndef VC6
	HDC             hdc;
	RECT			rectwin;
	wyInt32         renderwidth, renderheight;
	PAINTSTRUCT     ps;
	LPSTREAM        stream = NULL;
	HGLOBAL         glbmem;
	void            *glbbuffer;
    wyWChar         tempfilename[MAX_PATH+1] = {0}, path[MAX_PATH + 1] = {0};
	wyString		tempstr;
	HANDLE          hfile = INVALID_HANDLE_VALUE;
	DWORD           byteswritten = 0;

	if(!m_piub->m_data || m_piub->m_datasize == 0)
	{
		VERIFY(hdc = BeginPaint(m_hwndimage, &ps));
		VERIFY(EndPaint(m_hwndimage, &ps));
		return 0;
	}
	/* allocate global memory and copy image data in it*/
	VERIFY(glbmem = GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD, m_piub->m_datasize));
	if(!glbmem)
        return 0;

	/* lock the global memory and get a pointer */
	glbbuffer = GlobalLock(glbmem);
	/* copy the memory to buffer */
	CopyMemory(glbbuffer, m_piub->m_data, m_piub->m_datasize);
	/* unlock it */
	VERIFY(GlobalUnlock(glbmem)== NO_ERROR);
	/* create the stream */
	VERIFY(CreateStreamOnHGlobal(glbmem, FALSE, &stream)== S_OK);
	/* prepare window for painting */
	VERIFY(hdc = BeginPaint(m_hwndimage, &ps));
	/* clear the window */
	PrepareScreen(ps.hdc);

    if(pGlobals->m_configdirpath.GetLength() || SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, (LPWSTR)path)))
    {
		if(pGlobals->m_configdirpath.GetLength())
		{
			//wcscpy(path, pGlobals->m_configdirpath.GetAsWideChar());			
			wcsncpy(path, pGlobals->m_configdirpath.GetAsWideChar(), MAX_PATH);			
			path[MAX_PATH] = '\0';
		}
		
		else
		{
			wcscat(path, L"\\");
			wcscat(path, L"SQLyog");
		}
        
        VERIFY(GetTempFileName(path, L"img", 0, tempfilename));
 	    hfile = CreateFile(tempfilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
								   NULL, NULL);
	    VERIFY(hfile != INVALID_HANDLE_VALUE);
	    VERIFY(WriteFile(hfile, m_piub->m_data, m_piub->m_datasize, &byteswritten, NULL));
	    VERIFY(CloseHandle(hfile));
    }
	tempstr.SetAs(tempfilename);
	
	WCHAR *wpath = GetWideString(tempstr.GetString());
	
	Gdiplus::Graphics	graphics(hdc);
	Gdiplus::Image		*image = new Gdiplus::Image(wpath);

	HeapFree(GetProcessHeap(), 0, wpath);
	/* in win95 image will be null so we exit */
	if(!image)
		goto ExitPara;

	/* the binary data might not be image so image.getlastatus will not return Ok */
	if(image->GetLastStatus()!= Gdiplus::Ok)
    {
		delete image;
		goto ExitPara;
	}

	/* get the window width and calculate the correct render stats */
	VERIFY(GetClientRect(m_hwndimage, &rectwin));

	renderheight =(((LONG)image->GetHeight())> rectwin.bottom)?(rectwin.bottom):(image->GetHeight());
	renderwidth  =(((LONG)image->GetWidth())> rectwin.right)?(rectwin.right):(image->GetWidth());

	graphics.DrawImage(image, 0, 0, renderwidth, renderheight);
	delete image;
	EndPaint(m_hwndimage, &ps);

ExitPara:
	/* free up stuff */
	VERIFY(DeleteFile(tempfilename));
	if(stream)
		stream->Release();

	VERIFY(GlobalFree(glbmem)== NULL);
#endif
	
	return 0;
}
Beispiel #6
0
BOOL ReadImageProperty(const TCHAR *lpszImage, PROPID propId, TCHAR *szProperty, int cchMax)
{
    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR token;
    Gdiplus::Status status = GdiplusStartup(&token, &gdiplusStartupInput, NULL);

    if(status != Gdiplus::Ok)
    {
        return FALSE;
    }

    BOOL bSuccess = FALSE;

    /* This object needs to be
    deleted before GdiplusShutdown
    is called. If it were stack
    allocated, it would go out of
    scope _after_ the call to
    GdiplusShutdown. By allocating
    it on the heap, the lifetime
    can be directly controlled. */
    Gdiplus::Image *image = new Gdiplus::Image(lpszImage, FALSE);

    if(image->GetLastStatus() == Gdiplus::Ok)
    {
        if(propId == PropertyTagImageWidth)
        {
            bSuccess = TRUE;
            StringCchPrintf(szProperty, cchMax, _T("%u pixels"), image->GetWidth());
        }
        else if(propId == PropertyTagImageHeight)
        {
            bSuccess = TRUE;
            StringCchPrintf(szProperty, cchMax, _T("%u pixels"), image->GetHeight());
        }
        else
        {
            UINT size = image->GetPropertyItemSize(propId);

            if(size != 0)
            {
                Gdiplus::PropertyItem *propertyItem = reinterpret_cast<Gdiplus::PropertyItem *>(malloc(size));

                if(propertyItem != NULL)
                {
                    status = image->GetPropertyItem(propId, size, propertyItem);

                    if(status == Gdiplus::Ok)
                    {
                        if(propertyItem->type == PropertyTagTypeASCII)
                        {
                            int iRes = MultiByteToWideChar(CP_ACP, 0, reinterpret_cast<LPCSTR>(propertyItem->value), -1,
                                                           szProperty, cchMax);

                            if(iRes != 0)
                            {
                                bSuccess = TRUE;
                            }
                        }
                    }

                    free(propertyItem);
                }
            }
        }
    }

    delete image;
    Gdiplus::GdiplusShutdown(token);

    return bSuccess;
}