|
Here is some code I used for printing multi-page documents. It doesn't use the m_rectDraw for calculating the number of pages. It gets a printer device context from the current selected printer. Then calls GetDeviceCaps(HORZRES) and GetDeviceCaps(VERTRES) to get the printer page size.
BOOL CInfoWindowView::OnPreparePrinting(CPrintInfo* pInfo)
{
pInfo->SetMaxPage(GetNumberOfPrintPages(pInfo));
// default preparation
return DoPreparePrinting(pInfo);
}
WORD CInfoWindowView::GetNumberOfPrintPages(CPrintInfo* /*pInfo*/)
{
PRINTDLG PrtDlg;
HDC hDC;
//// Create a printer DC
if(!AfxGetApp()->GetPrinterDeviceDefaults(&PrtDlg))
{
TRACE("No default printer.\n");
// use screen DC for calculations
// It's OK to do this because this CDC will not be used for any
// output.
hDC = ::CreateDC("display",NULL,NULL,NULL);
}
else
{
CPrintDialog dlg(FALSE);
dlg.m_pd.hDevMode = PrtDlg.hDevMode;
dlg.m_pd.hDevNames = PrtDlg.hDevNames;
hDC = dlg.CreatePrinterDC();
}
CDC* pDC = CDC::FromHandle(hDC);
// This is a printer DC, so set m_bPrinting
// this is necessary so CScrollView::OnPrepareDC won't modify the
// ViewportOrg, and cause LPtoDP to return an inappropriate result.
pDC->m_bPrinting = TRUE;
//// Calculate print stuff.
CFont font;
CFont *pOldFont;
CSize size;
CInfoWindowDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
//Setup the font.
font.CreatePointFont(INFO_WINDOW_FONT_SIZE, INFO_WINDOW_FONT_FACE, pDC);
pOldFont = pDC->SelectObject(&font);
size = pDC->GetTextExtent("X");
//// Get the printer page sizeS.
LONG lHeaderHeight;
LONG lFooterHeight;
LONG lPageWidth, lPageHeight;
lPageWidth = pDC->GetDeviceCaps(HORZRES);
lPageHeight = pDC->GetDeviceCaps(VERTRES);
//Header height is 4 lines.
lHeaderHeight = size.cy * 4;
//Footer height is 2 lines.
lFooterHeight = size.cy * 2;
//Set header, page, and footer rects.
m_rectPrintHeader.SetRect(0, 0, lPageWidth, lHeaderHeight);
//Print area for info.
m_rectPrintPage.SetRect(0, m_rectPrintHeader.bottom,
lPageWidth, m_rectPrintHeader.bottom +
(lPageHeight - (lHeaderHeight + lFooterHeight)));
//Footer area.
m_rectPrintFooter.SetRect(0, m_rectPrintPage.bottom,
lPageWidth, lPageHeight);
(size.cy * 1));
//Calculate other stuff.
m_wLinesPerPrinterPage = WORD(m_rectPrintPage.Height() / size.cy);
m_wPrinterPages = (WORD)ceil((double)pDoc->GetNumberOfTextLines() / m_wLinesPerPrinterPage);
m_wPrinterPages = (WORD)__max(m_wPrinterPages, 1);
//// Clean up.
pDC->SelectObject(pOldFont);
pDC->DeleteDC();
return m_wPrinterPages;
}
I hope this helps.
Jonathan Craig
|
|
|
|
|
Here you will find how I finally solved the problem. I thank Jonathan for his kind suggestion not to rely on the m_rectDraw in the CInfo structure. But even this does not solve the problem but it helps to have more consistent printwork between different printers.
I found a go around the problem by splitting the document in a view with, in my case, three sections as to keep the total number of pages under 8 pages for wich the standard MFC print functions work fine.
|
|
|
|
|
I have an application with more then 400 strings in the string table. Every time the string table grows over a certain number of strings, one of the strings of the string table appears in the alert message boxes instead of the system string to prompt when you have to save to file on closing a window or other error message box. Unwanted parts of a string from the string table apperas as caption in buttons on the print preview window. It seems that something goes wrong in the text segment and the string table overwrites some system strings. How can this be avoided or what I am doing wrong ?
|
|
|
|
|
So far I did'nt receive any reaction on my question. Are you all developing applications with low number of strings in the string table or are you not using the string table at all? I try to explain my problem on another way. What could be the reason when a string or parts from a string from the string table appears unwanted in a message box in stead of a system string, or on a static control or in a button caption as in the print preview ?
|
|
|
|
|
Hi all,
I would like to handle hardware events other than mouse or clipboard events by using a hook (WH_HARDWARE). Do anyone ever used the WH_HARDWARE.
If yes can I have an example.
Thanks.
Thanks, Alain-Serge.
|
|
|
|
|
|
Is there any way to create and show a dialog in a C console program?
Thanks in advance.
Erik Hammar
|
|
|
|
|
Hi Erik,
You should be able to show a dialog from a console application just the same way as in a GUI application.
Create a dialog resource and implement a dialog procedure, then call one of the CreateDialogXXX (for a modeless dialog) or DialogBoxXXX (for a modal dialog).
Cheers,
Paolo.
|
|
|
|
|
Can I make the modeless dialog stay on top, and have the console drawing something in the dialog, too?
Could you show me an example?
Thanks.
|
|
|
|
|
Hi Erik,
I think you can do that. To have the dialog always on top try:
SetWindowPos(hWndDialog, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
To draw on the client area of the dialog, first get a device context then just draw in it:
HDC hDC;
hDC = GetDC(hWndDialog);
TextOut(hDC, 10, 10, TEXT("Hello World!"), 12);
ReleaseDC(hWndDialog, hDC);
Hope this helps,
Paolo.
|
|
|
|
|
i have problem in list box for particular condition i should display the text in the different color anybody suggest what to do
|
|
|
|
|
You'll need to owner-draw the text. List boxes are ooooold and don't have many features.
Is it possible for you to switch to a list view control? It's trivial to change text color in such a control. I have written a tutorial on using custom draw that explains how to do it.
|
|
|
|
|
Try
http://codeguru.earthweb.com/listbox/colorlb.shtml
Mike's right List Boxes are pretty ooooollllldd
But in some scenarios they can be more useful than
List Controls
Regardz
Colin Davies
|
|
|
|
|
I sent you a class via email that does the following things:
1) Calculate horizontal scroll distance based on longest string in the listbox
2) Add or Insert strings with a specified color
3) Increase distance between listbox items
|
|
|
|
|
When ICQ approaches the screen edges, it docks there.
Other windows will have their maximum window size reduced (e.g. maximum width=screenwidth-icqwidth, maximum height=screenheight-icqheight)
How can I change the maximum size of all windows in the desktop? Are there any methods that I can change the windows in desktop environments?
Thanks all!
|
|
|
|
|
Unsure How ICQ works,
Generally this sort of feature is done by creating an "appbar"
Like the windows bar or office bar, and a few ticker tape controls,
Search out "AppBar"
Regardz
Colin Davies
|
|
|
|
|
I have an ATL control with a contained TreeView (using CContainedWindow).
The treeview flickers like you wouldn't believe when resized dynamically (the user can stretch its size in the container I am using). I have determined that the flicker is not due to the parent window of the tree.
Any ideas? I'm fresh out... To witness this phenomenon, use the ATL wizard to generate a control based on a treeview. Populate the tree with some items. Place the control on a VB form, and dynamically resize the control in the form's Resize event. Flicker city.
Nick Hodapp
|
|
|
|
|
Create the Treeview without the WS_HSCROLL and WS_VSCROLL styles. There is a KB article on the subject but I don't have the number. MS states that the complete redraw is intended when these styles are active.
|
|
|
|
|
How can I make it so a utility is automatically loaded when windows starts? (without putting it in the startup folder).
I am sure this has simple, but I have had a look round and can't find any info.
Thanks for any help you can give,
David Wulff
|
|
|
|
|
Hi David,
You may write a value in the registry under the key *ROOT*\Software\Microsoft\Windows\Current Version\Run, where *ROOT* can be HKEY_LOCAL_MACHINE (all users, if you have enough rights) or HKEY_CURRENT_USER (only current user).
I don't know or can't remember if that can be done with an API call, maybe one of the Setup API.
Paolo.
|
|
|
|
|
I am now adding an entry to the ..\Run key with the utility path, and it is running fine each time I log in.
Is it possible though to do it another way. So long as the product is installed, this uitility must be present when the user is logged in (it's a kind of auto-change detect / restore utility very simialr to SourceSafe(r)). If it isn't loaded then the user will be able to get around password protected files and folders using this system.
I doubt many people will edit the registy to get rid of it, but some people might, and I need to gt around this.
I have tried creating the entry in the rgistry as read only, but it doesn't work.
Thanks in advance for any help, and excuse my bad spelling,
David Wulff
|
|
|
|
|
Hi David,
Don't worry for the spelling, many people here hasn't got English as mother tongue. I'm Italian...
The problem is: every user can terminate the utility at any time, with TaskManager on NT/2000 or by pressing CTRL+ALT+DEL on Win9x.
You can't safely protect the files this way, but really solving this problem involves the creation of a Service (only on WinNT/2K) or maybe a Device Driver.
You may have a program act as a service on Win9x by calling RegisterServiceProcess(), but I can't tell you more, this goes far beyond my knowledge...
I don't know if there's a simpler way...
Maybe you could consider writing a shell extension, which is loaded by Explorer and, running in a DLL, can't be terminated without terminating Explorer. Restarting Explorer after such an operation would reload your DLL too.
Manually removing a Shell Extension from registry is not a simple operation, and most users and even programmers are not able to do it.
I can't tell you which type of extension to implement and exactly when your DLL gets loaded by Explorer, but you may start reading the articles you find on CodeProject about Shell Extensions (there are some tutorials too).
You also have to pay attention to the fact that your code would run in a DLL, that is in the process space of Explorer, so an unexpected condition could crash Explorer too.
I don't know if this is the right approach to the problem...
You should ask someone else, or someone else should reply to you
Paolo.
|
|
|
|
|
----
Don't worry for the spelling, many people here hasn't got English as mother tongue. I'm Italian...
----
That's just it though, i'm British!
Thanks for the reply. I'll have a look using the approaches you mentioned, they cerainly sound doable.
|
|
|
|
|
Our entire development team here has been suffering from a strange VC IDE problem. I was wondering if any of you have come across this.
Our project is pretty big. 10 dsp files around 4000 files and 3.5 million lines of code.
Often during development, the IDE stops responding, the CPU gets pegged at 100 (or near there) and no redraws happen in the IDE. On my 650MHz machine (with 256MB of RAM) this state lasts 10-15 minutes and then all resumes. It got better when I added tons of header files to the MSVCINCL.DAT files is used to exclude files from the file dependencies. I talked to MS tech support and they said that it seems to be a dependency update pause (!). They said the file limit is around 9600 files so that isn't it.
One of my co-workers got a GHz machine and the pause is barely perceptable.
I was wondering if there are any work-arounds any of you know about?
TIA
Woolie
|
|
|
|
|
Often the workspace .ncb file will become corrupt, and this can cause a lag. Also, best of luck to you if you are using VSS...
You can safely delete the workspace .ncb file. It will get regenerated. If you find this fixes your problem, you may wish to write or find a utility to delete the file automatically. Several exist, though I will shamelessly plug one I wrote called NukeNCB.
Best of luck,
Nick Hodapp
|
|
|
|