MFC 화면 프린트 출력
윈도우 프로그래밍/C, C++, MFC2021. 10. 12. 17:19
300x250
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
void CPrintTestDlg::PrintOutImage(CString file_name)
{
int nWidth, nHeight;
CClientDC dc(this);//this->pImgWnd
CDC MemDC;
MemDC.CreateCompatibleDC(&dc);
CRect rect;
GetClientRect(rect);
nWidth = rect.Width();
nHeight = rect.Height();
CBitmap BMP;
CImage image;
image.Load(file_name);
if (image.IsNull() == false)
{
int si = image.GetWidth();
int sih = image.GetHeight();
BMP.Attach(image.Detach());
HANDLE hDib;
LPSTR pDib;
LPBITMAPINFO lpBitInfo;
HANDLE hlpBitInfo;
hDib = GlobalAlloc(GHND, nWidth*nHeight * 3);
pDib = (LPSTR)GlobalLock(hDib);
hlpBitInfo = GlobalAlloc(GHND, sizeof(BITMAPINFOHEADER) + sizeof(BITMAPINFO));
lpBitInfo = (LPBITMAPINFO)GlobalLock(hlpBitInfo);
lpBitInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
lpBitInfo->bmiHeader.biWidth = nWidth;
lpBitInfo->bmiHeader.biHeight = nHeight;
lpBitInfo->bmiHeader.biPlanes = 1;
lpBitInfo->bmiHeader.biBitCount = 24;
lpBitInfo->bmiHeader.biCompression = BI_RGB;
lpBitInfo->bmiHeader.biSizeImage = nWidth * nHeight * 3;
lpBitInfo->bmiHeader.biXPelsPerMeter = 0;
lpBitInfo->bmiHeader.biYPelsPerMeter = 0;
lpBitInfo->bmiHeader.biClrUsed = 0;
lpBitInfo->bmiHeader.biClrImportant = 0;
HDC hdc = ::GetDC(this->m_hWnd);
GetDIBits(hdc, (HBITMAP)BMP, 0, nHeight, pDib, lpBitInfo, DIB_RGB_COLORS);
::ReleaseDC(this->m_hWnd, hdc);
static DOCINFO docinfo = { sizeof(DOCINFO), _T("프린트"), NULL };
//팝업창 안띠우고 기본 설정 프린터로 인쇄
CPrintDialog dlg(TRUE, PD_RETURNDEFAULT);
dlg.DoModal();
//팝업창 뛰우고 프린터 선택해서 인쇄
/*CPrintDialog dlg(FALSE);
if (dlg.DoModal() == IDCANCEL)
{
GlobalUnlock(hDib);
GlobalFree(hDib);
GlobalUnlock(hlpBitInfo);
GlobalFree(hDib);
DeleteObject(BMP.m_hObject);
DeleteDC(MemDC.m_hDC);
DeleteDC(dc.m_hDC);
return;
}*/
DEVMODE *pDevmode = (DEVMODE*)dlg.GetDevMode();
pDevmode->dmOrientation = 2;
HDC hpdc = dlg.CreatePrinterDC();
int cy = GetDeviceCaps(hpdc, VERTRES);
int cx = GetDeviceCaps(hpdc, HORZRES);
if (StartDoc(hpdc, &docinfo))
{
if (StartPage(hpdc))
{
StretchDIBits(hpdc,
0, 0, cx, cy, 0, nHeight - sih, si, sih, pDib, lpBitInfo, DIB_RGB_COLORS, SRCCOPY);
//image.StretchBlt(image.GetDC(), 0, 0, nWidth, nHeight, SRCCOPY);
EndPage(hpdc);
}
EndDoc(hpdc);
}
GlobalUnlock(hDib);
GlobalFree(hDib);
GlobalUnlock(hlpBitInfo);
GlobalFree(hlpBitInfo);
DeleteObject(BMP.m_hObject);
DeleteDC(dc.m_hDC);
DeleteDC(MemDC.m_hDC);
::RestoreDC(hpdc, -1);
}
}
|
cs |
300x250
'윈도우 프로그래밍 > C, C++, MFC' 카테고리의 다른 글
c++ 함수 const 위치별 차이 (0) | 2021.12.25 |
---|---|
MFC CImage 이미지를 사용한 화면 이미지 저장 (0) | 2021.10.12 |
std::string <-> CString 변환 (0) | 2021.07.06 |
UDP Multicast 테스트 프로그램 및 코드 (30) | 2021.03.04 |
BlueScreen 블루스크린 만들기 SW (1) | 2021.03.04 |
댓글()