I want to display Logo on my document like other data which I retrieve from database are store into variable and then those are passes to print on document. I am storing path of related bitmap in database and it is also retrieve into variable I know following:
hbit = (HBITMAP) LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_BITMAPNAME),
IMAGE_BITMAP,
0,
0,
LR_CREATEDIBSECTION); SRCCOPY);
IDB_BITMAPNAME is a BITMAP which File Name Property set to the logo's path.
This is a static way to do means I already set FileName Property of BITMAP. I want to set it at runtime. please help
I tried as follows but not work,
hbit = (HBITMAP) LoadImage(NULL,
sLogopath,
IMAGE_BITMAP,
0,
0,
LR_LOADFROMFILE);
sLogoPath is CString type variable which contain C:\Users\Administrator\Desktop\cg_logoa.bmp path of bitmap
I also tried for dilectly mention path instead of variable "C:\\Users\\Administrator\\Desktop\\cg_logoa.bmp"
Also tried for this
L"C:\\Users\\Administrator\\Desktop\\cg_logoa.bmp" but it gives following error
error C2664: 'LoadImageA' : cannot convert parameter 2 from 'unsigned short [44]' to 'const char *'
I am trying to write bitmap on document. and it is not happing this is my problem. blank document display.
My code is:
pDC->SetMapMode(MM_TEXT);
LPBITMAPINFO info;
HBITMAP hbit;
BITMAP bm;
int nColors = 0;
int sizeinfo = 0;
RGBQUAD rgb[256];
hbit = (HBITMAP) LoadImage(NULL,
zakas,
IMAGE_BITMAP,
0,
0,
LR_LOADFROMFILE);
GetObject(hbit, sizeof(BITMAP), (LPVOID) &bm);
nColors = (1 << bm.bmBitsPixel);
if(nColors > 256)
nColors=0; /
sizeinfo = sizeof(BITMAPINFO) + (nColors * sizeof(RGBQUAD));
info = (LPBITMAPINFO) malloc(sizeinfo);
info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info->bmiHeader.biWidth = bm.bmWidth;
info->bmiHeader.biHeight = bm.bmHeight;
info->bmiHeader.biPlanes = 1;
info->bmiHeader.biBitCount = bm.bmBitsPixel * bm.bmPlanes;
info->bmiHeader.biCompression = BI_RGB;
info->bmiHeader.biSizeImage = bm.bmWidthBytes * bm.bmHeight;
info->bmiHeader.biXPelsPerMeter = 0;
info->bmiHeader.biYPelsPerMeter = 0;
info->bmiHeader.biClrUsed = 0;
info->bmiHeader.biClrImportant = 0;
if(nColors <= 256)
{
HBITMAP hOldBitmap;
HDC hMemDC = CreateCompatibleDC(NULL);
hOldBitmap = (HBITMAP) SelectObject(hMemDC, hbit);
GetDIBColorTable(hMemDC, 0, nColors, rgb);
for(int iCnt = 0; iCnt < nColors; ++iCnt)
{
info->bmiColors[iCnt].rgbRed = rgb[iCnt].rgbRed;
info->bmiColors[iCnt].rgbGreen = rgb[iCnt].rgbGreen;
info->bmiColors[iCnt].rgbBlue = rgb[iCnt].rgbBlue;
}
SelectObject(hMemDC, hOldBitmap);
DeleteDC(hMemDC);
}
HDC hdc = pDC->GetSafeHdc();
StretchDIBits(hdc,
3480,
250,
384*3,
160*3,
0,
0,
bm.bmWidth,
bm.bmHeight,
bm.bmBits,
info,
DIB_RGB_COLORS,
SRCCOPY);
DeleteObject(hbit);
free(info);
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowExt(827,-1169*2);
int xlogpix=pDC->GetDeviceCaps(LOGPIXELSX);
int ylogpix=pDC->GetDeviceCaps(LOGPIXELSY);
int xextent=827*xlogpix/100;
int yextent=1169*2*ylogpix/100;
pDC->SetViewportExt(xextent,yextent);
HeadeMultiple(pDC,pInfo,pDoc->flag_serial);
}