 |
SetDefaultPrinter ..msdn Add comment W32 Constants Translate this page |
 |
 |
|
Sets the printer name of the default printer for the current user on the local computer. |
 |
 |
| Code examples: |
 |
|
|
 |
 |
| Declaration: |
 |
 |
BOOL SetDefaultPrinter(
LPCTSTR pszPrinter // default printer name
);
|
 |
 |
 |
| FoxPro declaration: |
 |
 |
DECLARE INTEGER SetDefaultPrinter IN winspool.drv;
STRING pszPrinter
|
 |
 |
 |
| Parameters: |
 |
pszPrinter
[in] Pointer to a null-terminated string containing the default printer name. For a remote printer, the name format is \\server\printername. For a local printer, the name format is printername. |
 |
 |
| Return value: |
 |
| If the function succeeds, the return value is a nonzero value. |
 |
 |
| Usage: |
 |
cPrinter = GetPrinter()
IF NOT EMPTY(m.cPrinter)
= SetDefaultPrinter(m.cPrinter)
ENDIF
|
 |
 |
| My comment: |
 |
If pszPrinter is NULL or an empty string, SetDefaultPrinter does nothing if there is already a default printer. However, if there is no default printer, SetDefaultPrinter sets the default printer to the first printer, if any, in an enumeration of printers installed on the local computer.
The function is as simple as it is and hardly requires a sample code. If SetDefaultPrinter returns 0, call GetLastError to get an extended error information.
#DEFINE ERROR_INVALID_PRINTER_NAME 1801
Also consider using Windows scripting objects:
ws = CreateObject("WScript.Network")
ws.SetDefaultPrinter("\\MyServer\HP5")
See also: GetDefaultPrinter, EnumPrinters, PrinterProperties.
* * *
As you prpobably noticed the Printer And Faxes OS Window immediately reflects a change in default printer. Here is a screen copy of a tap put on the messages received by a member of this window subtree (window class CtrlNotifySink).

Each successful SetDefaultPrinter call broadcasts the WM_SETTINGCHANGE message.
 |
 |
 |
| Word Index links for the SetDefaultPrinter : |
 |
|
|
 |
 |
| Translate this page: |
 |
|
 |
 |
| • |
 |
| Created: | 2005-04-26 15:30:17 | | Modified: | 2008-04-16 13:33:59 | Visited in last 7 days: 60 |