Click here to Skip to main content
15,905,068 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How can print Dialog Box Screen? Pin
Le@rner26-Aug-10 0:45
Le@rner26-Aug-10 0:45 
GeneralRe: How can print Dialog Box Screen? Pin
Nuri Ismail26-Aug-10 2:01
Nuri Ismail26-Aug-10 2:01 
GeneralRe: How can print Dialog Box Screen? Pin
Le@rner26-Aug-10 2:08
Le@rner26-Aug-10 2:08 
AnswerRe: How can print Dialog Box Screen? Pin
Nuri Ismail26-Aug-10 2:23
Nuri Ismail26-Aug-10 2:23 
GeneralRe: How can print Dialog Box Screen? Pin
Le@rner26-Aug-10 2:42
Le@rner26-Aug-10 2:42 
GeneralRe: How can print Dialog Box Screen? Pin
Nuri Ismail26-Aug-10 2:47
Nuri Ismail26-Aug-10 2:47 
GeneralRe: How can print Dialog Box Screen? Pin
Le@rner26-Aug-10 2:56
Le@rner26-Aug-10 2:56 
AnswerRe: How can print Dialog Box Screen? Pin
Nuri Ismail26-Aug-10 3:40
Nuri Ismail26-Aug-10 3:40 
This happens because the viewport of the bitmap dc is not synchronized with the client rect of the dialog.
Try something like that:
void CDlgTestDlg::OnPrint(CDC *pDC, CPrintInfo* pInfo)
{
	// Get the bitmap of our dialog 
	HBITMAP hWndBmp = GetWndBmp(GetSafeHwnd());

	RECT rect;
	GetWindowRect(&rect);
	int nWidth = rect.right - rect.left;
	int nHeight = rect.bottom - rect.top;
	
	CDC dcSrc;
	dcSrc.CreateCompatibleDC(NULL);
	const int nRestorePoint = dcSrc.SaveDC();
	dcSrc.SelectObject(hWndBmp);

	// Preparation before paint:
        CRect rcClient, rcWindow;
	GetWindowRect(rcWindow);
	GetClientRect(rcClient);

	CRect rcClientMoved(rcClient);
	rcClientMoved.MoveToXY((rcWindow.Width() - rcClient.Width()) / 2, 
		               (rcWindow.Height() - rcClient.Height() - GetSystemMetrics(SM_CYBORDER)));
	
	CPoint ptViewPortOrg = dcSrc.GetViewportOrg();
	dcSrc.SetViewportOrg(rcClientMoved.TopLeft());

        // !!! Paint here !!!!

        // Restore the old viewport
        dcSrc.SetViewportOrg(ptViewPortOrg);

	// Blit the bitmap on the printer DC, you could also use StrechBlt
	pDC->BitBlt(0, 0, nWidth, nHeight, &dcSrc, 0, 0, SRCCOPY);

	dcSrc.RestoreDC(nRestorePoint);
	dcSrc.DeleteDC();
	DeleteObject(hWndBmp);
}


This should do the job! Smile | :)
Questionfiles stream & iterators Pin
ganesh_IT25-Aug-10 3:54
ganesh_IT25-Aug-10 3:54 
AnswerRe: files stream & iterators Pin
Cedric Moonen25-Aug-10 4:12
Cedric Moonen25-Aug-10 4:12 
GeneralRe: files stream & iterators Pin
Rob Grainger25-Aug-10 5:35
Rob Grainger25-Aug-10 5:35 
GeneralRe: files stream & iterators Pin
Cedric Moonen25-Aug-10 7:08
Cedric Moonen25-Aug-10 7:08 
AnswerRe: files stream & iterators Pin
Maximilien25-Aug-10 4:24
Maximilien25-Aug-10 4:24 
AnswerRe: files stream & iterators Pin
prasad_som26-Aug-10 2:42
prasad_som26-Aug-10 2:42 
AnswerRe: files stream & iterators Pin
Sauro Viti25-Aug-10 4:34
professionalSauro Viti25-Aug-10 4:34 
AnswerRe: files stream & iterators PinPopular
Aescleal25-Aug-10 8:31
Aescleal25-Aug-10 8:31 
AnswerRe: files stream & iterators Pin
Niklas L25-Aug-10 20:34
Niklas L25-Aug-10 20:34 
QuestionGLFW Across multiple files Pin
Chris Copeland25-Aug-10 3:31
mveChris Copeland25-Aug-10 3:31 
AnswerRe: GLFW Across multiple files Pin
Chris Copeland25-Aug-10 3:34
mveChris Copeland25-Aug-10 3:34 
QuestionHelp with Standard Input Pin
Danzy8325-Aug-10 1:13
Danzy8325-Aug-10 1:13 
AnswerRe: Help with Standard Input Pin
CPallini25-Aug-10 1:36
mveCPallini25-Aug-10 1:36 
AnswerRe: Help with Standard Input Pin
carter200025-Aug-10 3:05
carter200025-Aug-10 3:05 
GeneralRe: Help with Standard Input Pin
CPallini25-Aug-10 3:23
mveCPallini25-Aug-10 3:23 
QuestionHide TilteBar CMFCToolBar window Pin
Benjamin Bruno25-Aug-10 0:42
Benjamin Bruno25-Aug-10 0:42 
AnswerRe: Hide TilteBar CMFCToolBar window Pin
Sauro Viti25-Aug-10 1:15
professionalSauro Viti25-Aug-10 1:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.