Home > Software engineering >  Small white help, urgent! MFC, set the paper size to get the printer.
Small white help, urgent! MFC, set the paper size to get the printer.

Time:10-15

In Microsoft's website to find a function

 BOOL CPrintView: : GetPageSize (CSize & amp; NRetVal)//CPrintView is create your own class 
{
PRINTDLG FAR * pPrintDlg=new PRINTDLG;
BOOL bRet=FALSE;

//Get the current printer 's Settings.

If (AfxGetApp () - & gt; GetPrinterDeviceDefaults (pPrintDlg))
{

//Get Pointers to the two setting structures.

DEVNAMES FAR * lpDevNames=
(DEVNAMES FAR *) : : GlobalLock (pPrintDlg - & gt; HDevNames);

The DEVMODE FAR * lpDevMode=
(the DEVMODE FAR *) : : GlobalLock (pPrintDlg - & gt; HDevMode);

//Get the specific driver information.

Cstrings szDriver ((LPTSTR) lpDevNames +
LpDevNames - & gt; WDriverOffset);
Cstrings szDevice ((LPTSTR) lpDevNames +
LpDevNames - & gt; WDeviceOffset);
Cstrings szOutput ((LPTSTR) lpDevNames +
LpDevNames - & gt; WOutputOffset);

//Create a CDC object "according to the current Settings.

The 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 - & gt; HDevNames);
: : GlobalUnlock (pPrintDlg - & gt; HDevMode);

BRet=TRUE;
}
The delete pPrintDlg;
Return bRet.
}


////////////////////////////////////////////////////////////this function is to get the printer related Settings (including size) of paper function

I declare it again in other functions
 CSize CS; 
GetPageSize (CS);
Cx; long nWidthMM=CS.////////get paper width
Long nHeightMM=CS. Cy;//////paper long


But the question now is whether I adjust the Settings before printing paper size (A4, A5, B5, etc.)
Access is, the size of the nWidthMM=202; NHeightMM=289;

A great god, please help!!!!!

CodePudding user response:

Seems to be problems with system refresh the printer


You in the first set the size, weight, and then start the program and see what is

CodePudding user response:

reference 1st floor boylafong response:
seems to be problems with system refresh the printer


You in the first set the size, weight, and then start the program and see how much


I am in a piece of software, there is a print button, button each time point, will be called to print window, set the paper size,
Whether to reset the program or return the same value,

CodePudding user response:

I generally don't query, directly according to the need to set the paper size width (DC)

CodePudding user response:

refer to the second floor sona1116 response:
Quote: refer to 1st floor boylafong response:

Seems to be problems with system refresh the printer


You in the first set the size, weight, and then start the program and see how much


I am in a piece of software, there is a print button, button each time point, will be called to print window, set the paper size,
Returned to the same values, regardless of whether to reset the program


Lz can invoke the call window set the paper size, to use the same DC , paper size, and see if it is the same as setting

CodePudding user response:

reference worldy reply: 3/f
I generally don't query, directly according to the need to set the paper size width (DC)


Because of party a's requirements, in the users, users have to choose how much of a paper to print the size of the corresponding, so program must have access to a user to print, select the paper size of corresponding code?

CodePudding user response:

reference 5 floor sona1116 reply:
Quote: refer to the third floor worldy response:

I generally don't query, directly according to the need to set the paper size width (DC)


Because of party a's requirements, in the users, users have to choose how much of a paper to print the size of the corresponding, so program must have access to a user to print, select the paper size of corresponding code?


Also don't have to actually get, directly use your Settings as paper size, not with respect to OK

CodePudding user response:

refer to 6th floor worldy response:
Quote: refer to the fifth floor sona1116 reply:

Quote: refer to the third floor worldy response:

I generally don't query, directly according to the need to set the paper size width (DC)


Because of party a's requirements, in the users, users have to choose how much of a paper to print the size of the corresponding, so program must have access to a user to print, select the paper size of corresponding code?


Actually don't have to go to get, directly using the set values as paper size, don't you with respect to OK

I want to print this form too much trouble, but also to display various data printing in this form, so, I was using a device coordinates (absolute coordinates), use relative coordinates, cause now I print size is fixed, I can use a function to put what I print, now is according to the user to select the size of the printing paper, let me adjust my zoom ratio, don't know you Ming didn't know what I mean?

CodePudding user response:

The user to select the paper size must be through your program into effect, in this way, you can get the paper size directly, isn't it?

CodePudding user response:

Retrieves a handle to the printer device context.


HDC GetPrinterDC () const;


The Collapse imageReturn Value
A handle to the printer device context if successful; Otherwise a NULL.

The 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.

CodePudding user response:

Use absolute coordinates, certainly is not a good idea, set the page size didn't do it, but did set the direction of the paper, the period of routine don't know whether you can help,
 
//change the direction of printing paper
LPDEVMODE pDevMode;
PDevMode=(LPDEVMODE) GlobalLock (pInfo - & gt; M_pPD - & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related