Retrieve CPrintInfo - windows

Is there a way to retrieve CPrintInfo, not only when application do print or print preview (for instance, when I click on some dummy button or something) ? If yes, how can I achieve that ?

No you can't. Maybe with a lot of plumbing you can reuse the MFC print preview stuff, but honestly it's easier to drop down to GDI level printing and do your own print preview. See http://msdn.microsoft.com/en-us/library/windows/desktop/ff819270%28v=vs.85%29.aspx . You need to calculate your own amount of pages etc yourself anyway depending on the printer your print preview should 'emulate'.

Related

Need to print only the frame and not the whole page using Google Chrome

When I try to print the webpage, only the frame appears in the print when using IE or other browsers. However, through the google chrome, the whole page gets printed.
I have done a little research and found out that adding the OpenFrame plugin would do the trick. However, I am looking for the solution without the plugins. Our product is used by a number of customers and we can't ask them to install any plugins.
Can we fix this by making CSS changes or scripts.
Using JavaScript you can print frames independently, e.g.
top.frames[1].print()
If you include a print button or listen to print events, you can call your print function that prints only the frame you want.
Or you can use CSS #media print to set what gets printed
Highlight (select) what you want to print, right-click over the selected area and hit print.
p.s.: No other option worked. The add-on (Chrome app) doesn't have a print option, only open in new window and by doing so it sends a new page request and for many sites it won't work.
The best way is to use this "Chrome App" to add a Context sub-menu to your Chrome.
After the installation right click on the frame you want to print, select [This Frame] and the select the option that fits the best with your situation, usually [Open Frame in New tab].
Once you have the frame in a new tab you simply print it with CTRL-P or Right-Click [Print].
#media print { .div-to-not-print {display:none}}
is problematic because
It's not an end-user solution; it has to be done by the page
developer, and
We're talking about frames, which are actually independent pages.
That sort of solution wouldn't allow a user to print two
frames independently.
The suggestion
Click on the File > Print , then use the option Simplify Page
may work in some circumstances, but, for me, it just removes all frames and reverts to the <noframe> content in the frameset page.
As far as I can tell, there is no decent way to print just one frame in a frameset that is already loaded. A Chrome plugin that I haven't tried called "Print This Frame" really just re-loads the frame in a new tab (with a round-trip to the server).
But, without that plugin, if the frame you want to print was created from a hyperlink within the frameset, you can usually load the frame in a separate tab or window just by right-clicking on that link and selecting "Open link in new tab" or "Open link in new window"
Well the only workaround I could suggest is to open the source of the page and find the section
clink on the link and print it.
You should be using CSS:
#media print { .div-to-not-print {display: none} }
In the print version the blocks with class div-to-not-print will be hidden.
I found one another option useful.
Click on the File > Print , then use the option Simplify Page , that does removes useless things from page.
It might not be relevant to specific page you are printing. But i use it often.
Facing the same problem, I found that the most convenient way to control exactly what I wanted to print, thus remove the adds and various elements that just waste paper was to edit the page source directly:
Inspect the page : Ctrl-Shift-I -> this opens a pane with the source code of the page and the layout
By hover'ing over the source code it is really quick to identify the interesting elements that you are interested in, just remove the other ones:
it is a hierarchical representation of the page layout so you can expand the and elements to have more granularity when hover'ing
you may need to change or remove the class of the elements to change the internal layout if you have removed internal columns for example
Here is an example:
Click on the frame of interest
press CTRL+A (on Windows or equivalent on Mac) to select all content of the frame
press CTRL+P or choose print from the context menu
This should show a preview with everything in the frame ready to be saved as PDF or printed to the printer.

Is it possible to "trick" PrintScreen, swap out the contents of my form with something else before capture?

I have a bit of a challenge.
In an earlier version of our product, we had an error message window (last resort, unhandled exception) that showed the exception message, type, stack trace + various bits and pieces of information.
This window was printscreen-friendly, in that if the user simply did a printscreen-capture, and emailed us the screenshot, we had almost everything we needed to start diagnosing the problem.
However, the form was deemed too technical and "scary" for normal users, so it was toned down to a more friendly one, still showing the error message, but not the stack trace and some of the more gory details that I'd still like to get. In addition, the form was added the capabilities of emailing us a text file containing everything we had before + lots of other technical details as well, basically everything we need.
However, users still use PrintScreen to capture the contents of the form and email that back to us, which means I now have a less than optimal amount of information to go on.
So I was wondering. Would it be possible for me to pre-render a bitmap the same size as my form, with everything I need on it, detect that PrintScreen was hit and quickly swap out the form contents with my bitmap before capture, and then back again afterwards?
And before you say "just educate the users", yes, that's not going to work. These are not out users, they're users at our customers place, so we really cannot tell them to wisen up all that much.
Or, barring this, is there a way for me to detect PrintScreen, tell Windows to ignore it, and instead react to it, by dumping the aformentioned prerendered bitmap onto the clipboard ready for placing into an email?
The code is C# 3.0 in .NET 3.5, if it matters, but pointers for something to look at/for is good enough.
Our error-reporting window has these capabilities:
Show a screenshot that was taken when the error occured (contains all the open windows of the program at the time, before the error dialog was shown)
Show a text file containing every gory detail we can think of (but no sensitive stuff)
Save the above two files to disk, for latter attaching to an email or whatnot by the user
Sending the above two files to us by email, either by opening a new support case, or entering an existing support case number to add more information to it
Ignore the problem and hope it goes away (return to app)
Exit the application (last resort)
We still get screenshots from some users. Not all, mind you, so my question is basically how I can make the PrintScreen button help us a bit more for those users that still use it.
One option: Put the stack trace and other scary stuff into the error screen using small, low-contrast type -- e.g. dark gray on light gray -- so that the user doesn't really even see it, but the Print Screen captures it.
But if you want to detect the PrintScreen and do your own thing, this looks like an example of what you want.
Wouldn't it be possible to disable the Print Screen button altogether when the error popup is active? Have it display a message along the lines of "Please use the clearly visible button in the middle of your screen to report the error" I agree it breaks expected functionality, but if your users are really that stupid, what can you do...
Alternatively, have it report errors automatically (or store the data locally, to be fetched later, if you can't send without asking for some reason), without asking the user. If you want to be able to connect print screened screenshots with detailed error data, have it send a unique ID with the data that's also displayed in the corner of the popup.
What about offering them a "Print Screen" button that performs these actions as well as performing the print screen? If you're locked into this method of having your customers send error details, this may be an easier route to take.
Lifted from my comment below for easier reference (looks helpful, perhaps):
codeproject.com/KB/cs/PrintScreen.aspx
This is in theory...the best way to deal with it I would think
Intercept a WM_PRINT message or inject one into your process... see this article here
Install a system-wide keyboard hook and intercept the print-screen key and swap it around with your contents prior to the capture. Now, I can point you to several places for this, here on CodeProject, and here also, keyboard spy, and finally, global Mouse and keyboard hook on CodeProject.
Now, once you intercept the print screen, invoke the WM_PRINT message by capturing the contents that you want to capture.
I know this is brief and short, but I hope this should get you going.
The only solution i came up with was to offer big, large, easy to read toolbar buttons that give the user every opportunity to save the contents of the error dialog:
Save
Copy to clipboard
Send using e-mail
Print
And after all that, i use the Windows function SetWindowDisplayAffinity in order to show the user a black box where the form should be:
This function and GetWindowDisplayAffinity are designed to support the window content protection feature that is new to Windows 7. This feature enables applications to protect their own onscreen window content from being captured or copied through a specific set of public operating system features and APIs. However, it works only when the Desktop Window Manager(DWM) is composing the desktop.
It is important to note that unlike a security feature or an implementation of Digital Rights Management (DRM), there is no guarantee that using SetWindowDisplayAffinity and GetWindowDisplayAffinity, and other necessary functions such as DwmIsCompositionEnabled, will strictly protect windowed content, for example where someone takes a photograph of the screen.
If their screenshots show a big black box, hopefully they'll get the hint.
I did add a defeat, if they hold down shift while clicking "show error details", i don't add the protection during form construction:
//Code released into public domain. No attribution required.
if (!IsShiftKeyPressed())
SetWindowDisplayAffinity(this.Handle, WDA_MONITOR); //Please don't screenshot the form, please e-mail me the contents!

how to access current word in any program

Answers.com has a taskbar application that when you ALT + mouse-click on a word in any program it will pop up a window with information pulled from their website.
My question is-- what are the actual programming mechanics and APIs used to do something like this? I don't have Windows application programming experience and am trying to figure out where to start. How do you access the current word pointed to by the mouse?
Anyone aware of any examples or open source software that does anything like this?
It's been a while and the last time I did something like this it was within my own wysiwyg editor so I had full access to all font characteristics needed to calculate which word was clicked by the mouse.
Maybe there's a n easy way to do this if all your apps are .NET or com or share some other framework which provides a way to retrieve this directly.
Via the API, I would look into hooking the keyboard and mouse messages so that your app can pre-process every mouse click on other applications - start with SetWindowsHookEx and read everything you can about hooking messages.
After getting your app to pre-process the messages, you then need to grab the text being clicked. Since text can be painted onto a device context in many different ways, you may be best off doing a screen scrape of the clicked area because the text may only exist as a bitmap. If this is the case, you have to perform some OCR to translate the scraped bitmap back into text. In other cases, the text may reside in the window as text - the WM_GETTEXT message may return this text from some types of windows (e.g. textboxes, buttons, etc.) but for normal windows, this message only return the title in the caption bar.
Sorry I don't have any definite answer, but this may get you started in the right direction.

How can I print to a label printer from a web page

I have an e-commerce web application and I'd some how like to make that print to a label printer for the back end stuff
I have two questions
1) I can't print from a normal webpage straight to the printer (A zedbra LP2844 i think) it just throws out junk
2) I want to be able to print labels to the label printer, but all other printing, such as invoices would go to the default printer - a laser, so need someway of selecting the right printer
It will all happen at a fixed location, so I can insist on for example using Firefox with a specific (custom?) plugin installed (already using firefox so this would be a neat way)
Does anybody know if this is possible, is a firefox extention a possible and/or good way of doing this?
Anybody out there that can write ff plugins?
I would presume this must have been done before surely, but cannot find anything on google
Thanks for any help
Dave
Surely the label printer comes with a Windows driver? Then it might be enough to produce pages with the right dimensions in the browser using CSS or, if that won't work out, a PDF.
You can use "cm" or "in" units in your CSS for the label printer; you should be able to set page dimensions and orientation in Firefox's print dialog .
As much as I can see there are Windows drivers for this particular printer. Printing shouldn't be a problem after you install them.
Thanks for your comments people, I've actually come up with a different solution which comes at the problem from a different angle as selecting the correct printer would likely always be an issue
At the moment we have a windows program that we enter the order number into, it then draws a label and prints it out, but its not pretty and getting changes done to the layout is difficult but more than anything I want the ability to print from the webpage
So what I'm planning is this -
Update the program so it sits in the background and polls the database for a list of orders to be printed, for each order it finds, request an image from the server and print that image to the label
On the server, an image is created on the fly using ASPJpeg which gives me full control over how the label looks
From the webapp, I then have a button on the order to print, this adds the order to a print table... I can then have an interface to the print table which shows whats waiting to print, whats been printed etc, and I can clear the print queue or delete individual items from it just as if it were the windows print queue
Only problem I'm worried about is polling often enough that staff aren't waiting for labels to print and not polling too often that too much bandwidth is being used up
I might make it so that when they hit despatch it sends the label to be printed, or some other existing function that ties into the order process

Possible To Print 4-Up From Visual Studio?

I got nowhere Googling for this question so if this is a "Google Is Your Friend (GIYF)" question, I apologize in advance.
I always print source code duplex to save paper. Is there an add-in for VS (2003) which allows you to print two pages on one side of the paper so I can print 4 pages on one sheet? I think this is called 4-Up printing. I'm almost certain I can do this if I drop the printing out to a file and then use an external utility but I'd like to be able to do this all from within VS.
This is usually a function of the printer driver. I use it on the Canon printers to print out pamphlets and the like.
If you have the features for duplex and multipage printing, it'll be in the printer properties of the Print dialog.
To print both sides of the page (duplex), you'll need a duplex attachment on the printer or do the old even/odd page two-pass printing.
As spoulson says, its a function of the printer,
Go File->Print
Click on "Properties . . ." button
Find an option called "Pages per
sheet" (on my currently selected
printer it's on the "Finishing" tab.
Set it to the desired number of
pages
Hope this helps
If you want more control than your printer driver provides, take a look at FinePrint.
It works as a virtual printer and can do all sorts of layout manipulations on print jobs. It can even combine several print jobs into one.

Resources