Default Printer Behavior (Magic xpa 4.x)
This Technical Note shows you how to use the operating system's default printer even if the user changed it in previous prints.
When printing a report, the printer that was chosen by the end user in the print dialog box in the previous print job will be used as the default printer. Sometimes you want to ignore the last printer selected and instead use the operating system's default printer as the default printer for the reports.
To implement the behavior described above, you can draw your printer name from the registry. The key is HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows and the subkey is Device.
To draw the registry key from Magic xpa:
-
Use the Invoke OS operation with the command: reg export "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows" c:\temp\printer.txt
This will write the entire key to C:\temp\printer.txt file.
-
Use the File2Blb function to get the content of the file to Magic xpa.
-
Use string functions to get the name of the printer for use in the INIPut function.
-
Use the INIPut function to assign the printer name to Printer1.