|
hi,
Im developing a VC++ application in which one requirement is to print the dialog with its control(basically edit box and static text).
Im using the followinf code for this purpose.
CPrintDialog printDlg(FALSE, PD_ALLPAGES | PD_RETURNDC, NULL);<br />
printDlg.m_pd.nMinPage = printDlg.m_pd.nMaxPage = 1;<br />
printDlg.m_pd.nFromPage = printDlg.m_pd.nToPage = 1;<br />
printDlg.DoModal();<br />
HDC hdcPrn = printDlg.GetPrinterDC();<br />
if (hdcPrn != NULL) {<br />
CDC *pDC = new CDC;<br />
pDC->Attach (hdcPrn);
pDC->StartDoc("job");
pDC->StartPage();
Print(pDC,PRF_CHILDREN|PRF_CLIENT|PRF_ERASEBKGND);<br />
pDC->EndPage();
pDC->EndDoc();
pDC->Detach();
delete pDC;<br />
}
The problem im facing is that the content of the print is very small.Any idea where im wrong.I need help to print in a enlarged mode(i.e)bigger print
|
|
|
|
|
the program segment below show pOldFont,why to use it ,i often see it?
font.CreateFont(-200,0,0,0,400,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,DEFAULT_PITCH|FF_ROMAN,"Times New Roman");
CFont*pOldFont=(CFont*)pDC->SelectObject(&font); //作用是什么?
//pDC->GetTextMetrics(&tm);
nHeight=tm.tmHeight+tm.tmExternalLeading;
j=pDoc->m_stringArray.GetSize();
for(i=0;i<j;i++)
{pdc-="">TextOut(720,-i*nHeight-720,pDoc->m_stringArray[i]);
}
pDC->SelectObject(pOldFont);
|
|
|
|
|
You want to ensure that a device context always contains valid data. So when you select a specific handle into a dc for the first time, the original handle is returned. Before exiting, you then put that original back. Otherwise, when, using your example, "font" is deleted, the handle in pDC would be invalid.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Not quite right. Drawing objects are reference counted; a DC holds a reference to any objects selected into it, so those objects aren't actually deleted. DeleteObject only reduces the reference count by one - the object gets deleted when the reference count drops to zero.
However, some parts of Windows pass you a DC expecting to receive it back in the same state as it was when you received it; if you don't follow this rule, the drawing of some standard components can get screwed up.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
You are correct. After posting my response I weighed revising it, but I'd already shut down my computer.
The problem arises that if you create an object, assign it to the DC and don't delete it, the next time around, you create a new object, assign it to the DC and throw away the return value, you can easily create a resource leak.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
i want to develope some software which must use sdk,exactly the tapi in sdk.i just find find the online setup on microsoft.com,but my net speed is slow,it wouldn't complete!so,is there other place that i can get it??
who can give me some address? thanks very much!
|
|
|
|
|
|
for some reason this call crashes my app on some machines.
When I set a breakpoint at the point where this function is called and attempt to step into it I end up in CEnumArray::XEnumVOID::Skip(ULONG celt) which I cant explane. First line of this function is the COM method prolog macro which causes an access violation.
Can anyone explain why this is happening?
Thanks
Josh
|
|
|
|
|
Hi,
My code in OnInitialUpdate is
sizeTotal.cx = 1000;
sizeTotal.cy = 300;
// TODO: calculate the total size of this view
SetScrollSizes(MM_TEXT,sizeTotal);
Instead of passing the hardcoded values 1000,300 i want them to change them dynamically. eg:
sizeTotal.cx = m_nHeight;
sizeTotal.cy = m_nWidth;
This gives me an assertion error.
How can this be achieved.
Thanks and regards,
Salil.
|
|
|
|
|
I can only remember an assertion error occuring when some thing other than MM_TEXT is passed as the first argument. The following is from a small paint program I wrote:
void CSPaintView::UpdateScrollSizes()
{
CSize sizeTotal = m_Grid.GetDrawSize();
CSize sizePage(sizeTotal.cx >> 1, sizeTotal.cy >> 1);
sizeTotal.cx += sizeTotal.cx >> 1;
sizeTotal.cy += sizeTotal.cy >> 1;
CSize sizeLine(10 * m_Grid.GetMag(), 10 * m_Grid.GetMag());
SetScrollSizes(MM_TEXT, sizeTotal, sizeDefault, sizeLine);
}
This function is called from multiple locations in my view class functions and has always worked fine. Just single step into the SetScrollSizes function and look at the place where the assertion occurs (assuming CScrollView derive class).
INTP
|
|
|
|
|
I don't quite know how to communicate to a USB device. Can anyone help me please.
|
|
|
|
|
Anyone know how to get the creation date of a Directory? I need the information for backing up of files in a process.
For example a week backup, so after a week, the previous backup shall be erased off
Thanx
|
|
|
|
|
One possible solution is GetFileAttributes().
Kuphryn
|
|
|
|
|
This API only tells me if it is a directory or not. what i need is the date the directory is created etc...like File attributes.. is it possible on directory as well?
Thanx
|
|
|
|
|
Try GetFileAttributesEx()
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I import msdxm.ocx in my porject .it can play avi file in xp os.
but not play avi file in windows98 os
why ?
|
|
|
|
|
Hi
Just a question regarding the performance of CreateFile using Handler (APIs) Vs C Runtime function FILE *fp and fopen
Anyone know which is faster in reading and writing text files and whether any of them has limitations or problems in usage in WinCE environment?
Thank you
|
|
|
|
|
Reading/writing text files using asynchronous handlers is complex and problematic and likely to be slower than buffered i/o. fopen() eventually uses CreateFile, etc., and now offers [nonportable] access to many of the parameters of CreateFile. My only suggestion is to wrap the FILE* in a class, or use a simple Ptr<> template.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
A bit Deep for me..
Are you saying that fread, fwrite is asynchronous handling? or is it WriteFile, ReadFile??
Maybe you could quote an example
Thanx
|
|
|
|
|
You stated "CreateFile using Handler" which I interpreted as meaning using asynchronous i/o since CreateFile/ReadFile/WriteFile... is used by fopen/fread/fwrite.... The latter simply buffers the i/o, which for reading and writing strings will give you better performance.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
So u are saying using fread and fwrite is faster in performance as compared to WriteFile, ReadFile??
Sorry, i am evaluating which is better as i more used to fread and fwrite but now i exposed to another APIs WriteFile, ReadFile...The only gd thing about ReadFile is that the Handler obtained from CreateFile can be used for getting File Attributes..
Anyway, thanx for taking the time to answer my doubts
|
|
|
|
|
WriteFile is a low level call. It simply writes data to the disk. (The OS actually does some minor caching, but it's not significant.)
fwrite() writes data to an intermediate buffer (4k by default, I believe) when the buffer fills, the buffer is written to disk using a single call to WriteFile.
The same thing goes for reading data, only in reverse.
So, if you are reading/writing lots of smaller strings, you will get better performance with fread/fwrite unless you implement your own caching algorithm.
Note that you can get the original file handle by calling _fileno() with the proper FILE* and use that to call other functions directly (though doing any call that affects the file pointer (i.e. ReadFile, SetFilePointer, etc.) withough calling fflush first, will totally mess up the stream buffers.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
In a SDI program, when the user clicked the Open File Button and the standard File Open Dialog pops up I want to filter what type of file extensions the user can select.
J Guds
Masters Student
Kansas University
|
|
|
|
|
One solution is to instantiate a CFileDialog object and pass in a custom file-filter string.
Kuphryn
|
|
|
|
|
The following code opens files with .wav extension
Modify it as per ur need.
void CMyProjectView::OnFileOpen()
{
CFileDialog cfd(TRUE,".wav",NULL,OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST,"WAV File(*.wav)|*.wav||",this);
cfd.DoModal();
}
...Avenger
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|