|
Hi,
I have been struggling for some time with a problem experienced by a customer of our product. We have a reporting facility, which allows users to output information to a printer. We have found, on Windows 98, that when a block of text goes over a page, we are losing some text down the gap.
To print the text across pages we are using DrawTextEx, and getting the returned uiLengthDrawn to see how much fitted up to the bottom of a page, so we can continue the text from where we left off. This works perfectly on the screen, and also on NT/XP, but the uiLengthDrawn value is always wrong when going to any printer on Windows 98.
Has anyone else experienced this problem, and if so, do you know of any solution?
Paul.
P.S. It's my birthday today!
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
-- modified at 7:26 Friday 7th October, 2005
|
|
|
|
|
! Happy Birthday!
do you use MFC? If so, maybe you could use CDC::GetTextExtent(...) to know the size of the text to draw/print? To output text I generally use CDC::TextOut(...) and don't recall having any clipping problem with this method.
(the corresponding win32 api are ::GetTextExtentPoint32 and ::TextOut )
HTH,
K.
The great error of nearly all studies of war has been to consider war as an episode in foreign policies, when it is an act of interior politics - Simone Weil
Fold with us! ¤ flickr
|
|
|
|
|
Thanks!
Using GetTextExtent/TextOut is all very well, but that doesn't tell me how much of my text will fit into a given rectangle. Once I've drawn my clipped text onto the bottom of my page, I need to know where in my text string I need to start drawing on the next page.
(I do use MFC BTW, but I don't think that's relevant.)
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|
|
Paul S. Vickery wrote:
GetTextExtent/TextOut is all very well, but that doesn't tell me how much of my text will fit into a given rectangle
Yes, but not directly. GetTextExtent will give you the size required to draw the given text. Knowing where you begin to write the text, you should then be able to say if the text will go outside a given rectangle or not.
IMO? you should use it before drawing. Here's a sample how I use it:
CClientDC dc(this);
CFont *pFont = CFont::FromHandle((HFONT)::GetStockObject(DEFAULT_GUI_FONT));
CFont *pOldFont = dc.SelectObject(pFont);
CRect clientRect;
CSize textSize = dc.GetTextExtent(sTitle);
GetClientRect(&clientRect);
int iWidth = clientRect.Width() - 12;
CString strNewTitle(sTitle);
while(textSize.cx > iWidth){
sTitle = sTitle.Left(sTitle.GetLength() - 1);
strNewTitle = sTitle + _T("...");
textSize = dc.GetTextExtent(strNewTitle);
}
The great error of nearly all studies of war has been to consider war as an episode in foreign policies, when it is an act of interior politics - Simone Weil
Fold with us! ¤ flickr
|
|
|
|
|
Mmmm. That's what I was afraid I may have to resort to. It's not very efficient for huge chunks of text, which is why I didn't really want to do it this way in the first place (our reports are often very long, with large chunks of text), but I guess I can optimise it by splitting the string up and testing it using a binary method if it's over a certain length. I guess as it's only a problem on Windows 98, I'll just do it this way for that - maybe that'll teach them to use a real(-ish) OS!
Thanks for your time looking at this!
Paul.
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|
|
Yes, it is probably not very efficient, even if is it plausible it can be improved (using dichotomy seems good, making assumption on font width then on likely text length could perhaps also help).
Limiting this solution to Win98 users, by detecting the OS, could also limit the damage.
Paul S. Vickery wrote:
I guess as it's only a problem on Windows 98,
Is the problem not occuring on Win95? (I have to deal with this sh*tty OS, some of our customers still use this big bag of #$ù*#.
Also, the problem may come from the implementation of the printer driver on Win9x. Maybe an update of them, with a lot of luck...
The great error of nearly all studies of war has been to consider war as an episode in foreign policies, when it is an act of interior politics - Simone Weil
Fold with us! ¤ flickr
|
|
|
|
|
Just looked at source for CEditView printing, as suggested by Jack Squirrel in his reply[^], and it seems that MFC uses a similar method, by having a guess, and then adjusting the string until it best fits. They do that for all platforms (MFC doesn't use DrawTextEx anywhere as MFC pre-dates the function). Looks like that's what I'm going to have to do after all , but at least our customer will be happy!
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
-- modified at 5:05 Monday 10th October, 2005
|
|
|
|
|
Yep, avoiding DrawTextEx seems the good thing to do, jack's advice is the good one. I just have a look to CEditView printing too, very interesting. I learned something, there is an undocumented fucntion _AfxClipLine which may be useful sometimes.
Thanks for the feedback!
The great error of nearly all studies of war has been to consider war as an episode in foreign policies, when it is an act of interior politics - Simone Weil
Fold with us! ¤ flickr
|
|
|
|
|
There's code in the CEditView class that clips/fits text based on a rectangular boundary. Should be a primary function and a couple of helpers - just copy it to your project, tweak it if need be, and away you go.
"When you know you're going to eat crow, it's best to eat it while it's still warm." - Reader's Digest
|
|
|
|
|
Mmm. Just looked at that. It uses a method similar to the one I was avoiding by guessing how many might fit, then decreasing/increasing the length of the string until it fits best. Oh well, looks like that's the way to go.
"The way of a fool seems right to him, but a wise man listens to advice" - Proverbs 12:15 (NIV)
|
|
|
|
|
how do i get the font name used by the system ,or more precisely i need to fill the LOGFONT structure how do i do.
thanx in advance
Farpointer
|
|
|
|
|
You can use the ::GetStockObject function.
If using MFC, the code would be
LOGFONT logFont;
CFont *pFont = CFont::FromHandle((HFONT)::GetStockObject(SYSTEM_FONT));
pFont->GetLogFont(&logFont);
HTH,
K.
The great error of nearly all studies of war has been to consider war as an episode in foreign policies, when it is an act of interior politics - Simone Weil
Fold with us! ¤ flickr
|
|
|
|
|
thanx man i will see to it
farpointer
|
|
|
|
|
Hello , I am new to MFC.
I am using MS Access database .
I want to get tables list using CDatabase.
Is there ant SQL Query for getting table names from Access database.
I used this code but I am getting errors.
CDatabase db;
CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)";
CString sFile= "c:\\mydabase.mdb";
sDsn.Format("ODBC;DRIVER={%s};DSN='MyDsnName';DBQ=%s",sDriver,sFile);
db.Open(NULL,false,false,sDsn);
CRecordset recset(&db);
recset.Open(CRecordset::forwardOnly,sql,CRecordset::dynaset);
CString s=recset.GetTableName();
//int n=recset.GetRecordCount();
MessageBox(s);
========
Here I am not getting table name
Plz Give reply soon .
Praveen.
Praveen
|
|
|
|
|
Does the database and the DSN exist?
parims wrote:
I used this code but I am getting errors.
And what would those errors be?
parims wrote:
sDsn.Format("ODBC;DRIVER={%s};DSN='MyDsnName';DBQ=%s",sDriver,sFile);
It looks like you are trying to create both a DSN and a DSN-less connection. Why?
parims wrote:
recset.Open(CRecordset::forwardOnly,sql,CRecordset::dynaset);
What is the value of sql ?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hello Friends
Can anybody help me out in knowning how to configure Windows Update.
I want that at a stipulated time the Automatic Update should start on its own
On a fixed time
With Rgds
VC++
|
|
|
|
|
vcforums wrote:
Can anybody help me out in knowning how to configure Windows Update.
You mean by using the Control Panel applet:
rundll32.exe shell32.dll,Control_RunDLL wuaucpl.cpl
Or something else?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
yes Mr.David
I mean by going through wuaucpl.cpl
I am setting a option for the specified time to get the updates started
but it fails to do the same
Any help on this.
With Rgds
VC++
|
|
|
|
|
Wuauclt.exe operates on the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
hi
Thanks very much for been so patient for my so small query thanks once again,
but could u tell me what could be the reason if even setting these registry values,the update fails to occur,
Any suggesstion are welcome sir
With Rgds.
VC++
|
|
|
|
|
Could it be that no updates are available?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Thanks very much for ur reply at lightning speed,thanks for lthat
If u don't mind can i have ur mail id,
bcoz i have seen most of my reply from code project have come from u
If u remeber i have posted previously and got reply from u on questions such as
how to detect os remotely
Trapping system idle time in mfc
and now windows update
i can have ur id i will be obliged,
With Rgd
[VC++]
vcforums@gmail.com
|
|
|
|
|
I am a newbie to vc++. I did some C 15 years ago... but, normally, I'm a vb.net guy. However, my current job is VC++ and my boss wants me to place a class inside a .h and .cpp file that already has an existing class. I did this fine but when trying to define an instance of this class from another class, it seems invisible even though I have included the .h file.
Here's my code:
file1.h
class Class1
{
// definitions here
};
class Class2
{
// definitions here
};
File1.cpp:
#include "file1.h"
Class1::SomeFunction()
{
}
Class2::AnotherFunction()
{
}
File 2.h
#include "File1.h"
class Class3
{
Class2 cClass2; // not visible.
};
Any ideas?
Bill Dennis
Orlando, FL
|
|
|
|
|
Are you using namespaces in file1.h ?
What extactly do you mean by 'not visible' ?
Are there some compiler errors ?
Horror and moral terror are your friends. If they are not then they are enemies to be feared.
|
|
|
|
|
No, no namespaces. Boss doesn;t want to use namespaces.
Getting undefined class error when compiling on the line where I am insantiating a new class variable:
Class2 cClass2;
Bill Dennis
Orlando, FL
|
|
|
|