主题:[原创]页面设置和打印对话框的联合使用
//zlhex@163.com
#include <windows.h>
#include <commctrl.h>
#include <tchar.h>
#include "resource.h"
BOOL CALLBACK DlgProc(HWND,UINT,WPARAM,LPARAM);
HDC GetPrinterDC(HWND hwnd, DEVMODE *lpDevMode);
BOOL GetPageInfo(HWND hwnd, DEVMODE *lpDevMode, LPRECT lprtMargin);
BOOL SetPageInfo(HWND hwnd, DEVMODE *lpDevMode, LPRECT lprtMargin);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
DialogBoxParam(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,DlgProc,(LPARAM)NULL);
return 0;
}
BOOL CALLBACK DlgProc(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
{
static DEVMODE DevMode;
static RECT rtMargin;
DOCINFO di;
HDC hDC;
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BUTTON1:
SetPageInfo(hDlg,&DevMode,&rtMargin);
return TRUE;
case IDC_BUTTON2:
hDC = GetPrinterDC(NULL,&DevMode);
if(hDC)
{
di.cbSize = sizeof(di);
di.lpszDocName = TEXT("abc");
di.lpszOutput = NULL;
di.lpszDatatype =NULL;
di.fwType = 0;
if(StartDoc(hDC,&di)>0)
{
StartPage(hDC);
MoveToEx(hDC,0,0,NULL);
LineTo(hDC,1000,1000);
EndPage(hDC);
EndDoc(hDC);
}
DeleteDC(hDC);
}
return TRUE;
case IDCANCEL:
EndDialog(hDlg,FALSE);
return TRUE;
}
break;
case WM_INITDIALOG:
GetPageInfo(hDlg,&DevMode,&rtMargin);
return FALSE;
}
return FALSE;
}
#include <windows.h>
#include <commctrl.h>
#include <tchar.h>
#include "resource.h"
BOOL CALLBACK DlgProc(HWND,UINT,WPARAM,LPARAM);
HDC GetPrinterDC(HWND hwnd, DEVMODE *lpDevMode);
BOOL GetPageInfo(HWND hwnd, DEVMODE *lpDevMode, LPRECT lprtMargin);
BOOL SetPageInfo(HWND hwnd, DEVMODE *lpDevMode, LPRECT lprtMargin);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
DialogBoxParam(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,DlgProc,(LPARAM)NULL);
return 0;
}
BOOL CALLBACK DlgProc(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
{
static DEVMODE DevMode;
static RECT rtMargin;
DOCINFO di;
HDC hDC;
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BUTTON1:
SetPageInfo(hDlg,&DevMode,&rtMargin);
return TRUE;
case IDC_BUTTON2:
hDC = GetPrinterDC(NULL,&DevMode);
if(hDC)
{
di.cbSize = sizeof(di);
di.lpszDocName = TEXT("abc");
di.lpszOutput = NULL;
di.lpszDatatype =NULL;
di.fwType = 0;
if(StartDoc(hDC,&di)>0)
{
StartPage(hDC);
MoveToEx(hDC,0,0,NULL);
LineTo(hDC,1000,1000);
EndPage(hDC);
EndDoc(hDC);
}
DeleteDC(hDC);
}
return TRUE;
case IDCANCEL:
EndDialog(hDlg,FALSE);
return TRUE;
}
break;
case WM_INITDIALOG:
GetPageInfo(hDlg,&DevMode,&rtMargin);
return FALSE;
}
return FALSE;
}