在微軟官網找了一個函式
BOOL CPrintView::GetPageSize(CSize &nRetVal) // CPrintView 是自己創建的類
{
PRINTDLG FAR * pPrintDlg = new PRINTDLG;
BOOL bRet = FALSE;
// Get the current printer's settings.
if(AfxGetApp()->GetPrinterDeviceDefaults(pPrintDlg))
{
// Get pointers to the two setting structures.
DEVNAMES FAR *lpDevNames =
(DEVNAMES FAR *)::GlobalLock(pPrintDlg->hDevNames);
DEVMODE FAR *lpDevMode =
(DEVMODE FAR *)::GlobalLock(pPrintDlg->hDevMode);
// Get the specific driver information.
CString szDriver((LPTSTR)lpDevNames +
lpDevNames->wDriverOffset);
CString szDevice((LPTSTR)lpDevNames +
lpDevNames->wDeviceOffset);
CString szOutput((LPTSTR)lpDevNames +
lpDevNames->wOutputOffset);
// Create a CDC object according to the current settings.
CDC pDC;
pDC.CreateDC(szDriver, szDevice, szOutput, lpDevMode);
// Query this CDC object for the width and height of the current
// page.
/*static int*/ nRetVal.cx = pDC.GetDeviceCaps(HORZSIZE);
/* static int*/ nRetVal.cy = pDC.GetDeviceCaps(VERTSIZE);
// Get rid of the CDC object.
pDC.DeleteDC();
// Unlock the pointers to the setting structures.
::GlobalUnlock(pPrintDlg->hDevNames);
::GlobalUnlock(pPrintDlg->hDevMode);
bRet = TRUE;
}
delete pPrintDlg;
return bRet;
}
////////////////////////////////////////////////////////////上面這個函式就是獲取列印機相關設定(包括紙大小)的函式
我在其它函式中再宣告一下
CSize CS;
GetPageSize(CS);
long nWidthMM = CS.cx;////////獲取紙寬
long nHeightMM = CS.cy; //////紙長
但是現在的問題是 無論我在列印前調整 設定紙大小(A4,A5,B5等)
獲取的大小都是,nWidthMM =202; nHeightMM = 289;
請大神幫忙!!
uj5u.com熱心網友回復:
好像是列印機跟系統重繪問題你先設定好大小,重進,再啟動程式看看是多少
uj5u.com熱心網友回復:
我是在弄一個軟體,有個列印按鈕,每次點按鈕后,都會呼叫列印視窗,設定一下所需列印紙大小。
無論是否重啟動程式都回傳同一個值。
uj5u.com熱心網友回復:
我一般都是不查詢,直接根據需要設定紙張大小(DC的長寬)uj5u.com熱心網友回復:
lz可以在呼叫呼叫視窗設定紙張大小后,使用同一個DC,獲取紙張大小,看看是不是和設定的一樣
uj5u.com熱心網友回復:
我一般都是不查詢,直接根據需要設定紙張大小(DC的長寬)
因為甲方要求,在用戶使用時,用戶選擇多大的紙就得列印相應大小的。所以程式里得有獲取用戶列印時,選擇的紙張大小的相應代碼吧?
uj5u.com熱心網友回復:
我一般都是不查詢,直接根據需要設定紙張大小(DC的長寬)
因為甲方要求,在用戶使用時,用戶選擇多大的紙就得列印相應大小的。所以程式里得有獲取用戶列印時,選擇的紙張大小的相應代碼吧?
其實也不用去獲取,直接使用你設定值作為紙張大小,不就OK了
uj5u.com熱心網友回復:
我一般都是不查詢,直接根據需要設定紙張大小(DC的長寬)
因為甲方要求,在用戶使用時,用戶選擇多大的紙就得列印相應大小的。所以程式里得有獲取用戶列印時,選擇的紙張大小的相應代碼吧?
其實也不用去獲取,直接使用你設定值作為紙張大小,不就OK了
我要列印的這個表格太麻煩,還要把各個資料列印顯示在這個表格里。所以,我用的是設備坐標(絕對坐標),沒有用相對坐標。導致我現在列印的大小是固定的。我用了一個函式可以放縮我所列印的東西。現在就是要根據用戶選擇列印紙的大小,我來調整我放縮的比例。不知道您明沒明白我的意思?
uj5u.com熱心網友回復:
用戶選擇紙張大小肯定要通過你的程式生效的,這樣,你就直接可以獲得紙張大小了,不是嗎?uj5u.com熱心網友回復:
Retrieves a handle to the printer device context.HDC GetPrinterDC( ) const;
Collapse imageReturn Value
A handle to the printer device context if successful; otherwise NULL.
Collapse imageRemarks
If the bPrintSetupOnly parameter of the CPrintDialog constructor was FALSE (indicating that the Print dialog box is displayed), then GetPrinterDC returns a handle to the printer device context. You must call the Windows DeleteDC function to delete the device context when you are done using it.
uj5u.com熱心網友回復:
使用絕對坐標肯定不是好主意。設定紙張大小沒做過,但做過設定紙的方向,此段例程不知是否你有助。
// 改變列印紙方向
LPDEVMODE pDevMode;
pDevMode=(LPDEVMODE)GlobalLock(pInfo->m_pPD->m_pd.hDevMode); // 鎖定公共變數
if(pDevMode) // 設備存在
{
pDevMode->dmOrientation=DMORIENT_LANDSCAPE; // 設定橫向列印
}
GlobalUnlock(pInfo->m_pPD->m_pd.hDevMode); // 解鎖公共變數
pDC->ResetDCW(pDevMode); // 更新設備
uj5u.com熱心網友回復:
沒人知道嗎?我也想要這樣的功能uj5u.com熱心網友回復:
http://bbs.csdn.net/topics/320121851轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/131326.html
標籤:基礎類
下一篇:opengl根據串口繪圖代碼
