AddPrinter() sets the new printer as default. How to avoid it? - winapi

After calling WinAPI's AddPrinter() function, the newly created printer is set as the default printer. I don't want that - I want the default printer to remain as it was.
So do I just have to get the default printer before calling AddPrinter() and then restore it afterwards?
I couldn't find any parameter that controls this behavior.

Related

why are the extended properties lost if printing to prn file

if printing direct to printer, all the extended properties of printer setup dialog will work, f.e. stapling, scaling to 50 % or make a watermark on the document. they are very important for the printer finisher to work as expected.
But if I first print to file and then copy the file to printer, all the extended properties are lost on HP Laserjet (PCL).
To reproduce this, I simulated this also in Delphi with a very simple code.
After normal printing to printer worked as expected, I only changed lpszOutput in DocInfo to "...\test.prn" (not more!) and the prn-file has been generated.
Then I opened the file in binary mode and wrote it to same printer ("StartDocPrinter","WritePrinter","EndDocPrinter").
And then the document has been printed correct, but all the settings in extended properties are lost, no scaling, no watermark..
I thought, the printer should get exactly the same binary data stream, but please what can be the reason, that obviously the driver writes different content to prn file and different to printer?
or are there some flags or commands, which I must set by code? is it an HP specific problem?
thank's in advance.
Are you calling PrintDlgEx or PageSetupDlg in both cases?
The properties are in the print job's DEVMODE structure which the driver uses when rendering the job. It sounds like your DEVMODE isn't being set up correctly or is being ignored when you set lpszOutput. The behaviour you're seeing is very similar to that when you uncheck a printer's "Enable advanced printing features" checkbox.
There's some info on using the print dialog with lpszOutput here.

using IUP - Is there any way to clear all the content out of a IupText object?

using IUP - Is there any way to clear all the content out of a IupText object? I'm implementing a very simple 4 line display that is supposed to emulate a hardware device. Unfortunately, through days of experimentation, I found that using IupInsert eventually reaches a limit, so you need to delete the contents. The only way I was able to simulate this was to destroy the IupText object and the IupDialog object containing it. This is very inefficient and ugly, but the documentation is misleading. I also attempted to detach and destroy the text box, without destroying the dialog, but I was unable to insert/append a new text box that would actually show up on the screen. The return value from the append was valid, but even after refresh, IupShow, etc., the dlg would never display the text again. Thank you for any insights
Just set the VALUE attribute to "".

Using WinApi invocation to set mask property masked text control from another program

I'm trying to change the mask property in editMask control in vb6 with another program using WinApi function or message and can't find a message that do it.
what WinApi message is used when the mask is set?
Thank you
What Winapi message is used when the mask is set?
A masked edit is not a Windows control. Windows EDIT controls do not offer mask functionality. If you are going to influence this from outside you will first need to know exactly what this control is. After that, it's likely that you would need to inject into the target application in order to make the change. That is, assuming that the target application does not support enough automation to avoid such egregious hacking.

How can I make a console-like textbox?

I am making a program called "BasicSys". It is a BASIC System simulator that uses a textbox for the console. So far I have everything working great but I need to have the text box act like a command prompt window. It needs to be able to ask for input and retreive the value without allowing the user to modify anything outside of the prompt space (the space where the user should only be able to type is after a ":" or a ">"). Some feilds are password feilds that require either no echoing or having the chartacters replaced by *'s. Is it possible to make a console out of a textbox?
P.S. I also want to know if there are any small BASIC v2 compilers for Win32 so BasicSys can compile and run BASIC programs.
Depending on how realistic you want it to be you can use the API to open a real console window and interact with it. There are many examples available that you can find by searching such as this one. My suggestion though would be to fake it with a multi-line textbox. It would not be very tricky. Set an index every time you draw the prompt, then as long as the cursor is positioned after the index the textbox is read / write. If the user scrolls backwards make the textbox read only. It should be fairly simple using the KeyDown event and setting the ReadOnly property True / False to get a passable "command" window.

How can I programatically print a DataReport to a pdf file?

I'm updating old VB6 code to save its DataReports out to a PDF, rather than bringing up a print dialog.
I cannot simply write the PDF within the code (using a VB6 PDF library, etc.), since all our software already uses DataReports, and writing print code for each one would be tedious, at best. Currently, the process requires an employee to print the DataReport to a PDF print driver, naming it manually and saving it to where it needs to go. I need to automate this all, so that the name and location of the saved PDF can be specified programatically, rather than entered by hand.
The best solution would be if DataReport simply had a .SaveToPdf(filename) routine. Worst-case scenario, I see myself automating the process using SendKeys. However, this solution needs to work in an environment with multiple possible printers (so the PDF print driver might not be the default,) and on Windows XP, Vista, or 7.
I've fruitlessly tried Googling the problem, which returns only tutorials on how to do it by hand, much as we do now.
You might consider using a PDF Printer Driver that allows you to configure silent "printing" to a preset directory using auto-generated names.
For an example of such a product, see:
http://www.iteksoft.com/modules.php?op=modload&name=Sections&file=index&req=viewarticle&artid=21
I would create a dialog that lets the user enter the printer (driver) name, directory to save to, and a file naming guideline, then save that to either a local ini file or the registry. You would then need two print buttons / menus. One to print straight to the printer using the default (saved) settings, and one that opens the print window they see now so they can perform a custom print.
Remember an ellipsis on a menu item indicates additional dialogs, Print vs Print...
Just use Crystal Report Viewer Control and follow the steps:
Set objRpt = objApp.OpenReport("type report path and name")
objRpt.DiscardSavedData
dim filepath as string
filepath = report path & report filename
With objRpt
.ExportOptions.FormatType = crEFTPortableDocFormat
.ExportOptions.DestinationType = crEDTDiskFile
.ExportOptions.DiskFileName = 'filepath string goes here
.ExportOptions.PDFExportAllPages = True
.Export False
End With
Follow these steps and the export is done.

Resources