|
Ok, I figured it out by myself. Finally.
Ward
|
|
|
|
|
Hello,
Would like to know how the contents of a control (say edit control / text box) can be sent to a printer. I am having a text box which is in a dialog. Normally print is supported for a view. But my requirement is to extract the contents of the control, which is in a VC++ 6.0 dialog and has to be printed.
Will help a lot, if a sample code is supported.
Regards,
Vairamuthu.G.
|
|
|
|
|
Hi,
Use following code:
DOCINFO di = { sizeof (DOCINFO) } ;<br />
PRINTDLG pd ;<br />
int yChar, iCharsPerLine, iLinesPerPage, iTotalLines, iTotalPages, iPage, iLine, iLineNum ;<br />
PTSTR pstrBuffer ;<br />
<br />
TCHAR szJobName [64 + MAX_PATH] ;<br />
TEXTMETRIC tm ;<br />
WORD iColCopy, iNoiColCopy ;<br />
<br />
pd.lStructSize = sizeof (PRINTDLG) ;<br />
pd.hwndOwner = hwnd ;<br />
pd.hDevMode = NULL ;<br />
pd.hDevNames = NULL ;<br />
pd.hDC = NULL ;<br />
pd.Flags = PD_ALLPAGES | PD_COLLATE | PD_RETURNDC | PD_NOSELECTION ;<br />
pd.nFromPage = 0 ;<br />
pd.nToPage = 0 ;<br />
pd.nMinPage = 0 ;<br />
pd.nMaxPage = 0 ;<br />
pd.nCopies = 1 ;<br />
pd.hInstance = NULL ;<br />
pd.lCustData = 0L ;<br />
pd.lpfnPrintHook = NULL ;<br />
pd.lpfnSetupHook = NULL ;<br />
pd.lpPrintTemplateName = NULL ;<br />
pd.lpSetupTemplateName = NULL ;<br />
pd.hPrintTemplate = NULL ;<br />
pd.hSetupTemplate = NULL ;<br />
<br />
if (!PrintDlg (&pd))
return TRUE ;<br />
<br />
if (0 == (iTotalLines = SendDlgItemMessage (hwnd,IDC_TEKSTVELD, EM_GETLINECOUNT, 0, 0)))<br />
return TRUE ;<br />
<br />
GetTextMetrics (pd.hDC, &tm) ;<br />
yChar = tm.tmHeight + tm.tmExternalLeading ;<br />
<br />
iCharsPerLine = GetDeviceCaps (pd.hDC, HORZRES) / tm.tmAveCharWidth ;<br />
iLinesPerPage = GetDeviceCaps (pd.hDC, VERTRES) / yChar ;<br />
iTotalPages = (iTotalLines + iLinesPerPage - 1) / iLinesPerPage ;<br />
<br />
pstrBuffer = (PTSTR)malloc (sizeof (TCHAR) * (iCharsPerLine + 1)) ;<br />
<br />
<br />
di.lpszDocName =
<br />
if (StartDoc (pd.hDC, &di) > 0)<br />
{<br />
for (iColCopy = 0 ;<br />
iColCopy < ((WORD) pd.Flags & PD_COLLATE ? pd.nCopies : 1) ;<br />
iColCopy++)<br />
{<br />
for (iPage = 0 ; iPage < iTotalPages ; iPage++)<br />
{<br />
for (iNoiColCopy = 0 ;<br />
iNoiColCopy < (pd.Flags & PD_COLLATE ? 1 : pd.nCopies);<br />
iNoiColCopy++)<br />
{<br />
if (StartPage (pd.hDC) < 0)<br />
{<br />
bSuccess = FALSE ;<br />
break ;<br />
}<br />
for (iLine = 0 ; iLine < iLinesPerPage ; iLine++)<br />
{<br />
iLineNum = iLinesPerPage * iPage + iLine ;<br />
<br />
if (iLineNum > iTotalLines)<br />
break ;<br />
<br />
*(int *) pstrBuffer = iCharsPerLine ;<br />
<br />
int iAantalChars = (int) SendDlgItemMessage (hwnd,IDC_TEKSTVELD, EM_GETLINE,<br />
(WPARAM) iLineNum, (LPARAM) pstrBuffer);<br />
<br />
<br />
TextOut (pd.hDC, 0, yChar * iLine, pstrBuffer, iAantalChars);<br />
<br />
if (EndPage (pd.hDC) < 0)<br />
{<br />
break ;<br />
}<br />
<br />
<br />
}
<br />
}<br />
<br />
free (pstrBuffer) ;<br />
DeleteDC (pd.hDC) ;
This will surely help you.;)
kind regards,
Ward
|
|
|
|
|
I have function in a class called LoadFile
BOOL Bitmap::LoadFile(const char *FileName)<br />
{<br />
<br />
CFileException e;<br />
<br />
strcpy(m_FileName,FileName);<br />
<br />
}
to which i pass string during the call
const char *FileName= _T("c:\\1.bmp");<br />
BMP.LoadFile (FileName);
there is an error
error: unhandled exception , 0x0000000005 access violation
whats wrong
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
What is m_FileName ?
It seems to be something like:
char* m_FileName; //This should produce the error.
However,
char m_FileName[MAX_PATH];//This should not result in an error.
It is unclear from your post; it could be something else also.
this is this.
|
|
|
|
|
What is m_FileName declared as?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for - in order to get to the job you need to pay for the clothes and the car, and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
|
|
|
|
|
It depends on what data type m_Filename is.
If it is of type CString, then I think this function will not work without first exposing the memory buffer (GetBuffer(0) ??).
If the variable is an array of characters, then it should work (unless the destination size is less than the source string).
I Dream of Absolute Zero
|
|
|
|
|
vikas amin wrote: strcpy(m_FileName,FileName);
change to
if ((!m_FileName) && (size_allocated_to(m_FileName) > ::strlen(FileName))) {
::strcpy(m_FileName, FileName);
}
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
|
|
|
|
|
Ok
I think i got the point
i need to allocate the space for
the destination .
thank you
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
see if u have initialized it first. like khan said
regards,
Rookie
Installing MFC...2% complete
|
|
|
|
|
Hello,
You should beware of the UNICODE problems that your code have when you compile with UNICODE defined. See the following where your problems are:
const char* FileName
= _T("C:\\1.bmp");
To solve this problem, use TCHAR* instead of char* where you want to use the _T macro.
[EDIT]
You should also use the macros from tchar.h[^] so that you use UNICODE functions when you build with UNICODE defined.
[/EDIT]
Hope this helps.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
-- modified at 9:43 Tuesday 20th December, 2005
|
|
|
|
|
Hey. If m_FileName happens to be a CString, then just do this instead:
mFileName = FileName
instead of using anything like strcpy.
You are LUCKY you got the access violation now and not 10 months from now with 10 million copies of your app in the field
No shirt, no shoes, no brains, no service.
|
|
|
|
|
|
Show me EXACTLY here the m_FileName is defined or declared in his original post?
No shirt, no shoes, no brains, no service.
|
|
|
|
|
Since you are using mfc why not use CString and let all this memory allocation for strings automatically be handled for you??
John
|
|
|
|
|
vikas amin wrote: strcpy(m_FileName,FileName);
Why are you not using CString ?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
vikas amin wrote: strcpy(m_FileName,FileName);
Hai Vikas,
what type of variable is m_FileName
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
I have a class in which there is a structe
i want to initialize the structre through the constructer .
class xyz{
struct tagBITMAPFILEHEADER
{
WORD bfType; // must be 'BM'
DWORD bfSize; // size of the whole .bmp file
WORD bfReserved1; // must be 0
WORD bfReserved2; // must be 0
DWORD bfOffBits;
}m_BITMAPFILEHEADER ;
xyz()
{
BITMAPFILEHEADER ={0,0,0,0,0};
}
}
I am getting an error
error C2059: syntax error : '{'
error C2143: syntax error : missing ';' before '{'
am i wrong someware
}
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
If the code that you post is the real code there is a little error:
vikas amin wrote: xyz()
{
BITMAPFILEHEADER ={0,0,0,0,0};
}
xyz()
{
m_BITMAPFILEHEADER ={0,0,0,0,0};
}
Have a nice code day
|
|
|
|
|
|
Sorry that was not the real code it is not copy pasted
i typed it again .
The real problem is how to initialise the structure .
Can anyone tell me
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
|
Why don't use
xyz()
{
m_BITMAPFILEHEADER.bfType=0;
m_BITMAPFILEHEADER.bfSize=0;
m_BITMAPFILEHEADER.bfReserved1=0;
m_BITMAPFILEHEADER.bfReserved2=0;
m_BITMAPFILEHEADER.bfOffBits=0;
}
Because, I don't remember if you could use ={0,0,0,0,0} in that point
Have a nice code day
|
|
|
|
|
My favorite,
ZeroMemory(m_BITMAPFILEHEADER, sizeof(m_BITMAPFILEHEADER));
if you want to set everything to 0.
Does not work if a class with complex objects is embedded wihtin the structure, such as a CString, however.
I can't believe how many times I have seen code setting data structure's fields to all zeroes, when there are several dozen fields, instead of block setting the entire element. If I only had a dollar...
No shirt, no shoes, no brains, no service.
|
|
|
|
|
I understand you!!!
This happens, really, too many times.
Have a nice code day
|
|
|
|