Click here to Skip to main content
15,916,945 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CMap restricted use? Pin
Nuno Tavares3-Jul-00 0:56
Nuno Tavares3-Jul-00 0:56 
GeneralRe: CMap restricted use? Pin
Blake Miller3-Jul-00 7:01
Blake Miller3-Jul-00 7:01 
GeneralRe: CMap restricted use? Pin
Sam Hobbs3-Jul-00 8:17
Sam Hobbs3-Jul-00 8:17 
GeneralRe: CMap restricted use? Pin
Nuno Tavares9-Jul-00 5:41
Nuno Tavares9-Jul-00 5:41 
GeneralCool Menu Bar Pin
Member 39871-Jul-00 7:40
Member 39871-Jul-00 7:40 
GeneralRe: Cool Menu Bar Pin
Erich2-Jul-00 9:50
Erich2-Jul-00 9:50 
GeneralPrinting Dialog Box Pin
MFCDude1-Jul-00 4:09
sussMFCDude1-Jul-00 4:09 
GeneralRe: Printing Dialog Box Pin
Jeremy Davis2-Jul-00 22:23
Jeremy Davis2-Jul-00 22:23 
Best thing to do is a screen grab.

void CMachine::PrintWindow()
{
// show options

CMyPrintDialog PrintDlg(
FALSE,
PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_NOSELECTION |
PD_DISABLEPRINTTOFILE,
this);

int Response = 0;
Response = PrintDlg.DoModal();

if (Response == IDOK)
{
// get printer dc

HDC hPrinterDC =(HDC) 0;
hPrinterDC = PrintDlg.m_pd.hDC;
ASSERT(hPrinterDC != NULL);

CDC PrinterDC;
BOOL IsAttached = FALSE;
IsAttached = PrinterDC.Attach(hPrinterDC);
ASSERT(IsAttached);

// Set landscape
LPDEVMODE pDevMode = PrintDlg.GetDevMode();
pDevMode->dmFields |= DM_ORIENTATION;
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
PrinterDC.ResetDC(pDevMode);

// attempt to set abort procedure

int SetAbortProcStatus = 0;
// SetAbortProcStatus = PrinterDC.SetAbortProc( &AbortProc );

// attempt to start print job

DOCINFO DocInfo;
DocInfo.cbSize = sizeof(DOCINFO);
DocInfo.lpszOutput = NULL;
DocInfo.lpszDocName = "PDMW Windows Screen Print";

int StartDocStatus = 0;
StartDocStatus = PrinterDC.StartDoc(&DocInfo);

// if abort procedure set and print job started

if (SetAbortProcStatus >= 0 && StartDocStatus >= 0)
{
// start page

VERIFY(PrinterDC.StartPage() > 0);

// get the screen dc

HDC hScreenDC =(HDC) 0;
hScreenDC = ::GetDC(NULL);// CDC
ASSERT(hScreenDC != NULL);

CDC ScreenDC;
VERIFY(ScreenDC.Attach(hScreenDC));

// create screen device dependent (dd) bitmap

CRect tmp;
GetWindowRect(tmp);
// ClientToScreen(tmp);
// tmp.top -= ::GetSystemMetrics(SM_CYCAPTION);

int ScreenWidth = tmp.Width();// - ::GetSystemMetrics(SM_CXEDGE) * 4;// 0;

// ScreenWidth = ScreenDC.GetDeviceCaps( HORZRES );

int ScreenHeight = tmp.Height();// + ::GetSystemMetrics(SM_CYCAPTION);// - ::GetSystemMetrics(SM_CYEDGE) * 4;
//- ::GetSystemMetrics(SM_CYCAPTION);// 0;
// ScreenHeight = ScreenDC.GetDeviceCaps( VERTRES );

CBitmap ScreenBitmap;
VERIFY(ScreenBitmap.CreateCompatibleBitmap(
&ScreenDC,
ScreenWidth,
ScreenHeight
));

// copy image to screen dd bitmap

CDC MemDC;
VERIFY(MemDC.CreateCompatibleDC(&ScreenDC));

CBitmap* pOldBitmap = NULL;
pOldBitmap = MemDC.SelectObject(&ScreenBitmap);
ASSERT(pOldBitmap != NULL);

VERIFY(MemDC.BitBlt(
0,
0,
ScreenWidth,
ScreenHeight,
&ScreenDC,
tmp.left,
tmp.top,
SRCCOPY
));

// create device independent (di) bitmap

const int BitCount = 24;
long ImageSize = 0;
ImageSize =((((ScreenWidth * BitCount) + 31) & ~31) >> 3)
* ScreenHeight;

BYTE* pBitmapBits = NULL;
pBitmapBits = new BYTE[ImageSize];
ASSERT(pBitmapBits != NULL);

// copy image from screen dd bitmap to di bitmap

BITMAPINFO BitmapInfo;
BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BitmapInfo.bmiHeader.biWidth = ScreenWidth;
BitmapInfo.bmiHeader.biHeight = ScreenHeight;
BitmapInfo.bmiHeader.biPlanes = 1;
BitmapInfo.bmiHeader.biBitCount = BitCount;
BitmapInfo.bmiHeader.biCompression = BI_RGB;
BitmapInfo.bmiHeader.biSizeImage = ImageSize;
BitmapInfo.bmiHeader.biXPelsPerMeter = 0;
BitmapInfo.bmiHeader.biYPelsPerMeter = 0;
BitmapInfo.bmiHeader.biClrUsed = 0;
BitmapInfo.bmiHeader.biClrImportant = 0;
memset(&BitmapInfo.bmiColors[0], 0, sizeof(RGBQUAD));

VERIFY(GetDIBits(
ScreenDC.m_hDC,
(HBITMAP) ScreenBitmap,
0,
ScreenHeight,
(LPVOID) pBitmapBits,
&BitmapInfo,
DIB_RGB_COLORS
));

VERIFY(ScreenBitmap.DeleteObject());
VERIFY(MemDC.DeleteDC());
ScreenDC.Detach();

// if bitmap selection succeeded

if (pOldBitmap != NULL)
{
// copy di bitmap to printer

int PrinterWidth = 0;
PrinterWidth = PrinterDC.GetDeviceCaps(HORZRES);

int PrinterHeight = 0;
PrinterHeight = PrinterDC.GetDeviceCaps(VERTRES);

if (PrintDlg.m_bCheckFullPage)
{
VERIFY(StretchDIBits(
PrinterDC.m_hDC,
0,
0,
PrinterWidth,
PrinterHeight,
0,
0,
ScreenWidth,
ScreenHeight,
(LPVOID) pBitmapBits,
&BitmapInfo,
DIB_RGB_COLORS,
SRCCOPY
) != GDI_ERROR);
}
else
{
CString strFactor;
int dFactor;
// PrintDlg.m_EditMagnifyCtrl.GetWindowText(strFactor);
strFactor = PrintDlg.GetFactorText();
if (strFactor.IsEmpty())
dFactor = 1;
else
{
dFactor = atoi(strFactor);
if (dFactor < 1)
dFactor = 1;
}
VERIFY(StretchDIBits(
PrinterDC.m_hDC,
(PrinterWidth - ScreenWidth * dFactor) / 2,
(PrinterHeight - ScreenHeight * dFactor) / 2,
ScreenWidth * dFactor,
ScreenHeight * dFactor,
0,
0,
ScreenWidth,
ScreenHeight,
(LPVOID) pBitmapBits,
&BitmapInfo,
DIB_RGB_COLORS,
SRCCOPY
) != GDI_ERROR);
}

// finish the print job

VERIFY(PrinterDC.EndPage() >= 0);
VERIFY(PrinterDC.EndDoc() >= 0);
}

// else could not select bitmap

else
{
// abort job

VERIFY(PrinterDC.AbortDoc() >= 0);
AfxMessageBox("Could Not Print--Memory Error Possible.");
}

// clean up

delete pBitmapBits;
}

// else job cannot be started

else
{
// attempt to abort job

PrinterDC.AbortDoc();
AfxMessageBox("Cannot Start Print Job.");
}

// clean up

PrinterDC.Detach();
VERIFY(DeleteDC(hPrinterDC));
}
}

BOOL CALLBACK CMachine::AbortProc(HDC hdc, int iCode)
{
MSG msg;
while (!bUserAbort && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (!hDlgPrint || !::IsDialogMessage(hDlgPrint, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
if (iCode > 0)
bUserAbort = 1;
return !bUserAbort;
}
GeneralDialog in ATL object Pin
Magesh K.1-Jul-00 3:30
sussMagesh K.1-Jul-00 3:30 
GeneralRe: Dialog in ATL object Pin
Mike Dunn1-Jul-00 9:18
Mike Dunn1-Jul-00 9:18 
GeneralRe: Dialog in ATL object Pin
Magesh K.2-Jul-00 2:05
sussMagesh K.2-Jul-00 2:05 
GeneralRe: Dialog in ATL object Pin
Mike Dunn2-Jul-00 9:22
Mike Dunn2-Jul-00 9:22 
GeneralKey strokes Pin
Member 37471-Jul-00 1:28
Member 37471-Jul-00 1:28 
GeneralRe: Key strokes Pin
Mike Dunn1-Jul-00 9:22
Mike Dunn1-Jul-00 9:22 
GeneralInteresting Dialog problem Pin
Member 238630-Jun-00 17:13
Member 238630-Jun-00 17:13 
GeneralRe: Interesting Dialog problem Pin
Blake Miller30-Jun-00 18:09
Blake Miller30-Jun-00 18:09 
GeneralRe: Interesting Dialog problem Pin
Member 238630-Jun-00 18:53
Member 238630-Jun-00 18:53 
GeneralRe: Interesting Dialog problem Pin
Magesh K.2-Jul-00 2:11
sussMagesh K.2-Jul-00 2:11 
GeneralProblem solved Pin
Member 23862-Jul-00 6:21
Member 23862-Jul-00 6:21 
Questionhow to set font (ATL) Pin
Chris30-Jun-00 10:38
Chris30-Jun-00 10:38 
AnswerRe: how to set font (ATL) Pin
Alex Gorev30-Jun-00 11:40
Alex Gorev30-Jun-00 11:40 
GeneralNew Project Wizard Pin
David Leikis30-Jun-00 10:22
David Leikis30-Jun-00 10:22 
GeneralA simple template question Pin
juskett30-Jun-00 4:53
juskett30-Jun-00 4:53 
GeneralRe: A simple template question Pin
Mike Dunn1-Jul-00 19:02
Mike Dunn1-Jul-00 19:02 
GeneralRe: A simple template question Pin
Mike Dunn3-Jul-00 8:25
Mike Dunn3-Jul-00 8:25 

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.