Thanks Richard for the suggestion, I have done it. Here I am posting mine worked code.
I took my printers DC and drawn image on that DC.
void CPrint_JpegDlg::PrintJpegImage()
{
TCHAR szPrinter[_MAX_PATH];
DWORD cntChars = _MAX_PATH;
GetDefaultPrinter(szPrinter, &cntChars);
SetDefaultPrinter(L"\\printer name");
CPrintDialog printDlg(FALSE);
printDlg.GetDefaults();
CDC prtrDC;
if (!prtrDC.Attach(printDlg.GetPrinterDC()))
{
AfxMessageBox(_T("No printer found!"));
return;
}
prtrDC.m_bPrinting = TRUE;
DOCINFO imageInfo;
::ZeroMemory (&imageInfo, sizeof (DOCINFO));
imageInfo.cbSize = sizeof (DOCINFO);
imageInfo.lpszDocName = L"C:\\test.jpg";
BOOL bPrintingOK = prtrDC.StartDoc(&imageInfo);
CPrintInfo oInfo;
oInfo.SetMaxPage(1); int nMaxWidth = prtrDC.GetDeviceCaps(HORZRES);
int nMaxHeight = prtrDC.GetDeviceCaps(VERTRES);
oInfo.m_rectDraw.SetRect(0, 0, nMaxWidth, nMaxHeight);
for (UINT page = oInfo.GetMinPage(); page <= oInfo.GetMaxPage() && bPrintingOK; page++)
{
prtrDC.StartPage(); oInfo.m_nCurPage = page;
CBitmap bitmap;
if(!bitmap.Attach(::LoadImage( ::GetModuleHandle(NULL), L"C:\\test.jpg", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE)))
{
AfxMessageBox(_T("Error loading bitmap!"));
return;
}
BITMAP bm;
bitmap.GetBitmap(&bm);
int nWidth = bm.bmWidth;
int nHeight = bm.bmHeight;
CDC memDC;
memDC.CreateCompatibleDC(&prtrDC);
CBitmap *pBmp = memDC.SelectObject(&bitmap);
memDC.SetMapMode(prtrDC.GetMapMode());
prtrDC.SetStretchBltMode(HALFTONE);
prtrDC.StretchBlt(0, 0, nMaxWidth, nMaxHeight, &memDC, 0, 0, nWidth, nHeight, SRCCOPY);
memDC.SelectObject(pBmp);
bPrintingOK = (prtrDC.EndPage() > 0); }
if (bPrintingOK)
prtrDC.EndDoc(); else
prtrDC.AbortDoc();
SetDefaultPrinter(szPrinter);
}