网站首页  词典首页

请输入您要查询的函数:

 

术语 setdefaultprinter
释义 SetDefaultPrinter
语法:
BOOL SetDefaultPrinter(
__in LPCTSTR pszPrinter
);
SetDefaultPrinter功能
该SetDefaultPrinter功能设置为本地计算机上的当前用户默认打印机的名称。
参数
pszPrinter [in]
一个指向 null 结尾的字符串指针包含默认打印机的名称。对于远程打印机的名称格式是\\ \\服务器\\ PrinterName的。对于本地打印机,名称格式为PrinterName的。
如果该参数为NULL或空字符串,即“”,SetDefaultPrinter将选择从安装的打印机的一个默认打印机。如果默认打印机已经存在,要求与NULL或在此参数为空字符串SetDefaultPrinter可能更改默认打印机。
返回值
如果函数成功,返回值是一个非零值。
如果函数失败,返回值是零。
备注
要设置默认打印机,请SetDefaultPrinter。要设置默认打印机以较早的操作系统,调用GetProfileString,WriteProfileString和SendNotifyMessage,如以下代码所示:

if ((DWORD)(LOBYTE(LOWORD(GetVersion()))) < 5) {
// if this is running on Windows NT4.0 or earlier, then
// read PrinterPorts section from win.ini
// returned string should be of the form "driver,port,timeout,timeout", i.e. "winspool,LPT1:,15,45".
GetProfileString(TEXT("Windows"),TEXT("Device"),_T(",,,"),m_szName, COUNTOF(m_szName));
WriteProfileString(TEXT("Windows"),TEXT("Device"),pszPrinterName );
// Notify all open applications of the change. Note, only applications that handle the message will recognize the change.
if (WM_WININICHANGE != WM_SETTINGCHANGE) {
// Old message type; for windows 95
SendNotifyMessage(HWND_BROADCAST,WM_WININICHANGE,0,(LPARAM)szWindows);
}
// New message type
SendNotifyMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,(LPARAM)szWindows);
} else {
// call SetDefaultPrinter
SetDefaultPrinter (pszPrinterName);
}
当使用此方法,则必须指定一个有效的打印机,驱动程序和端口。如果是无效的指数不失败,但结果是没有定义。这可能导致其他程序设置打印机返回到以前的有效打印机。您可以使用EnumPrinters检索打印机的名称,驱动程序的名称和端口的所有可用打印机的名称。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinspool.h(头文件:winuser.h)
LibraryWinspool.lib
Unicode和ANSI namesSetDefaultPrinterW(Unicode)和SetDefaultPrinterA(ANSI)的
参见
Printing and Print Spooler Overview
Printing and Print Spooler 函数
EnumPrinters
GetDefaultPrinter
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年7月11日
==英文原文==SetDefaultPrinter Function
The SetDefaultPrinter function sets the printer name of the default printer for the current user on the local computer.
Syntax
BOOL SetDefaultPrinter(
__in LPCTSTR pszPrinter
);
Parameters
pszPrinter [in]
A 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.
If this parameter is NULL or an empty string, that is, "", SetDefaultPrinter will select a default printer from one of the installed printers. If a default printer already exists, calling SetDefaultPrinter with a NULL or an empty string in this parameter might change the default printer.
Return Value
If the function succeeds, the return value is a nonzero value.
If the function fails, the return value is zero.
Remarks
To set the default printer, call SetDefaultPrinter. To set the default printer to earlier operating systems, call GetProfileString , WriteProfileString , and SendNotifyMessage , as shown in the following code:

if ((DWORD)(LOBYTE(LOWORD(GetVersion()))) < 5) {
// if this is running on Windows NT4.0 or earlier, then
// read PrinterPorts section from win.ini
// returned string should be of the form "driver,port,timeout,timeout", i.e. "winspool,LPT1:,15,45".
GetProfileString(TEXT("Windows"),TEXT("Device"),_T(",,,"),m_szName, COUNTOF(m_szName));
WriteProfileString(TEXT("Windows"),TEXT("Device"),pszPrinterName );
// Notify all open applications of the change. Note, only applications that handle the message will recognize the change.
if (WM_WININICHANGE != WM_SETTINGCHANGE) {
// Old message type; for windows 95
SendNotifyMessage(HWND_BROADCAST,WM_WININICHANGE,0,(LPARAM)szWindows);
}
// New message type
SendNotifyMessage(HWND_BROADCAST,WM_SETTINGCHANGE,0,(LPARAM)szWindows);
} else {
// call SetDefaultPrinter
SetDefaultPrinter (pszPrinterName);
}
When using this method, you must specify a valid printer, driver, and port. If they are invalid, the APIs do not fail but the result is not defined. This could cause other programs to set the printer back to the previous valid printer. You can use EnumPrinters to retrieve the printer name, driver name, and port name of all available printers.
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinspool.h (include Windows.h)
LibraryWinspool.lib
Unicode and ANSI namesSetDefaultPrinterW (Unicode) and SetDefaultPrinterA (ANSI)
See Also
Printing and Print Spooler Overview
Printing and Print Spooler Functions
EnumPrinters
GetDefaultPrinter
Send comments about this topic to Microsoft
Build date: 7/11/2009
==原始网址==http://msdn.microsoft.com/en-us/library/dd162971(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:24:01