调用 PageSetupDlg() 函数后打印机的 CreateDC 出现问题
Problem with CreateDC of printer after call PageSetupDlg() function
我正在为 WindowsCE 2013 使用 C++ WinAPI 项目。
IDE 我用的是 Visual Studio 2013
我首先在我的应用程序中初始化一个 PageSetupDialog ..
屏幕如下:
不幸的是,我仍然无法开始打印。
我假设问题出在 CreateDC 中,即 DialogBox 中的值未转发到 CreateDC 函数。
我在该文档中读到 PageSetupDlg 函数 return DEVMODE 结构,但我不知道如何将其转发给 Create DC 函数。感谢您在这件事上的帮助。
我把负责功能的定义:
BOOL OknoDrukowania(HWND hWnd)
{
PAGESETUPDLG psd;
DEVMODE dm;// common dialog box structure
// Initialize PAGESETUPDLG
ZeroMemory(&psd, sizeof(psd));
psd.lStructSize = sizeof(psd);
psd.hwndOwner = hWnd;
psd.hDevMode = NULL; // Don't forget to free or store hDevMode.
psd.hDevNames = NULL; // Don't forget to free or store hDevNames.
psd.Flags = PSD_INTHOUSANDTHSOFINCHES | PSD_MARGINS ;
psd.rtMargin.top = 1000;
psd.rtMargin.left = 1250;
psd.rtMargin.right = 1250;
psd.rtMargin.bottom = 1000;
//psd.lpfnPagePaintHook = PaintHook;
if (PageSetupDlg(&psd) == TRUE)
{
HDC hDC;
hDC = CreateDC(NULL, dm.dmDeviceName, NULL, NULL);
StartDoc(hDC, NULL);
StartPage(hDC);
Ellipse(hDC, 500, 500, 1000, 1000);
Ellipse(hDC, 1000, 800, 1500, 1300);
Ellipse(hDC, 800, 1000, 1800, 2000);
EndPage(hDC);
EndDoc(hDC);
DeleteDC(hDC); // check paper size and margin values here.
}
return TRUE;
}
问题已被这段代码解决:
memcpy(&dm, (DEVMODE *)(psd.hDevMode), sizeof(DEVMODE));
lstrcpy(DriverName, ((TCHAR *)((BYTE *)psd.hDevNames + ((DEVNAMES *)psd.hDevNames)->wDriverOffset)));
lstrcpy(DeviceName, ((TCHAR *)((BYTE *)psd.hDevNames + ((DEVNAMES *)psd.hDevNames)->wDeviceOffset)));
lstrcpy(OutputName, ((TCHAR *)((BYTE *)psd.hDevNames + ((DEVNAMES *)psd.hDevNames)->wOutputOffset)));
HDC hDC;
hDC = CreateDC(DriverName, DeviceName, OutputName, &dm);
我正在为 WindowsCE 2013 使用 C++ WinAPI 项目。
IDE 我用的是 Visual Studio 2013
我首先在我的应用程序中初始化一个 PageSetupDialog ..
屏幕如下:
不幸的是,我仍然无法开始打印。 我假设问题出在 CreateDC 中,即 DialogBox 中的值未转发到 CreateDC 函数。 我在该文档中读到 PageSetupDlg 函数 return DEVMODE 结构,但我不知道如何将其转发给 Create DC 函数。感谢您在这件事上的帮助。 我把负责功能的定义:
BOOL OknoDrukowania(HWND hWnd) { PAGESETUPDLG psd; DEVMODE dm;// common dialog box structure // Initialize PAGESETUPDLG ZeroMemory(&psd, sizeof(psd)); psd.lStructSize = sizeof(psd); psd.hwndOwner = hWnd; psd.hDevMode = NULL; // Don't forget to free or store hDevMode. psd.hDevNames = NULL; // Don't forget to free or store hDevNames. psd.Flags = PSD_INTHOUSANDTHSOFINCHES | PSD_MARGINS ; psd.rtMargin.top = 1000; psd.rtMargin.left = 1250; psd.rtMargin.right = 1250; psd.rtMargin.bottom = 1000; //psd.lpfnPagePaintHook = PaintHook; if (PageSetupDlg(&psd) == TRUE) { HDC hDC; hDC = CreateDC(NULL, dm.dmDeviceName, NULL, NULL); StartDoc(hDC, NULL); StartPage(hDC); Ellipse(hDC, 500, 500, 1000, 1000); Ellipse(hDC, 1000, 800, 1500, 1300); Ellipse(hDC, 800, 1000, 1800, 2000); EndPage(hDC); EndDoc(hDC); DeleteDC(hDC); // check paper size and margin values here. } return TRUE; }
问题已被这段代码解决:
memcpy(&dm, (DEVMODE *)(psd.hDevMode), sizeof(DEVMODE));
lstrcpy(DriverName, ((TCHAR *)((BYTE *)psd.hDevNames + ((DEVNAMES *)psd.hDevNames)->wDriverOffset)));
lstrcpy(DeviceName, ((TCHAR *)((BYTE *)psd.hDevNames + ((DEVNAMES *)psd.hDevNames)->wDeviceOffset)));
lstrcpy(OutputName, ((TCHAR *)((BYTE *)psd.hDevNames + ((DEVNAMES *)psd.hDevNames)->wOutputOffset)));
HDC hDC;
hDC = CreateDC(DriverName, DeviceName, OutputName, &dm);