Gdiplus code to load the bitmap on the specified HWND of the control
#include
using namespace Gdiplus;
ULONG_PTR gdiplusToken;
// Function LoadAnImage: accepts a file name and returns a HBITMAP.
// On error, it returns 0.
void InitGdiPlus()
{
GdiplusStartupInput gdiplusStartupInput;
gdiplusStartupInput.GdiplusVersion = 1;
// Initialize GDI+.
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
}
void CloseGdiPlus()
{
GdiplusShutdown(gdiplusToken);
}
bool DLLDIR LoadImageOnCtrl(HWND hwnd,char* filename,char* szText)
{
WCHAR wcsFileName[MAX_PATH];
WCHAR wcsString[MAX_PATH];
RECT rect;
// Convert ANSI to WCHAR*
MultiByteToWideChar(0,0,filename,-1,wcsFileName,MAX_PATH);
MultiByteToWideChar(0,0,szText,-1,wcsString,MAX_PATH);
OutputDebugStringW(wcsFileName);
OutputDebugString("\n");
OutputDebugStringW(wcsString);
GetWindowRect(hwnd,&rect);
Gdiplus::Image* img = Gdiplus::Image::FromFile(wcsFileName);
if( img == NULL)
{
return false;
}
Graphics g(hwnd);
FontFamily fontFamily(L"Arial");
Font font(&fontFamily,8.0);
Gdiplus::PointF pointF(0, 0);
//graphics.DrawString(szPath, -1, &font, pointF, &solidBrush);
Gdiplus::SolidBrush solidBrush(Gdiplus::Color(255,0,0,0));
g.DrawImage(img,0,0,(rect.right - rect.left), (rect.bottom - rect.top));
g.DrawString(wcsString,-1,&font,pointF,&solidBrush);
return true;
}
using namespace Gdiplus;
ULONG_PTR gdiplusToken;
// Function LoadAnImage: accepts a file name and returns a HBITMAP.
// On error, it returns 0.
void InitGdiPlus()
{
GdiplusStartupInput gdiplusStartupInput;
gdiplusStartupInput.GdiplusVersion = 1;
// Initialize GDI+.
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
}
void CloseGdiPlus()
{
GdiplusShutdown(gdiplusToken);
}
bool DLLDIR LoadImageOnCtrl(HWND hwnd,char* filename,char* szText)
{
WCHAR wcsFileName[MAX_PATH];
WCHAR wcsString[MAX_PATH];
RECT rect;
// Convert ANSI to WCHAR*
MultiByteToWideChar(0,0,filename,-1,wcsFileName,MAX_PATH);
MultiByteToWideChar(0,0,szText,-1,wcsString,MAX_PATH);
OutputDebugStringW(wcsFileName);
OutputDebugString("\n");
OutputDebugStringW(wcsString);
GetWindowRect(hwnd,&rect);
Gdiplus::Image* img = Gdiplus::Image::FromFile(wcsFileName);
if( img == NULL)
{
return false;
}
Graphics g(hwnd);
FontFamily fontFamily(L"Arial");
Font font(&fontFamily,8.0);
Gdiplus::PointF pointF(0, 0);
//graphics.DrawString(szPath, -1, &font, pointF, &solidBrush);
Gdiplus::SolidBrush solidBrush(Gdiplus::Color(255,0,0,0));
g.DrawImage(img,0,0,(rect.right - rect.left), (rect.bottom - rect.top));
g.DrawString(wcsString,-1,&font,pointF,&solidBrush);
return true;
}
Labels: Gdi+
0 Comments:
Post a Comment
<< Home