请教API函数 SetDefaultPrinter的用法,在线等待,当天给贴!
我以经include "winspool.h",但还是提示我SetDefaultPrinter没有定义,
我查看本地的MSDN没有这个函数,但微软网站上的MSDN却有。
我是VC6.0.是否需要.NET?
急,在线!
谢谢!
问题点数:100、回复次数:13Top
1 楼sdwtao(老王)回复于 2003-12-03 16:21:58 得分 5
To set the default printer on Windows 2000/XP, call SetDefaultPrinter. To set the default printer to earlier operating systems, call GetProfileString, WriteProfileString, and SendNotifyMessage, as shown in the following code:
Requirements
Windows NT/2000/XP: Included in Windows 2000 and later.
Windows 95/98/Me: Unsupported.
Header: Declared in Winspool.h; include Windows.h.
Library: Use Winspool.lib.
Unicode: Implemented as Unicode and ANSI versions.
你需要在stdafx.h里面把winver宏改成5Top
2 楼carbon107(<软件开发思想.h>)回复于 2003-12-03 16:32:51 得分 5
BOOL SetDefaultPrinter(
LPCTSTR pszPrinter // default printer name
);
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.
If this parameter is NULL or an empty string, that is, "", 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.
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.Top
3 楼jinn()回复于 2003-12-03 16:36:36 得分 0
我的STDAFX.H里面没有WINVER 宏,能说详细一点吗?
我是WIN2000系统.
谢谢!Top
4 楼osborn(SEANX)回复于 2003-12-03 16:36:46 得分 0
自己加载!
HMODULE hModule = GetModuleHandle(_T("WINSPOOL.DRV"));
BOOL bLoad = FALSE;
if(!hModule)
{
hModule = LoadLibrary(_T("WINSPOOL.DRV"));
bLoad = TRUE;
}
typedef BOOL (WINAPI *PFN_SetDefaultPrinter)(LPCTSTR pszPrinter);
PFN_SetDefaultPrinter pfnSetDefaultPrinter = NULL;
#ifdef UNICODE
pfnSetDefaultPrinter = (PFN_SetDefaultPrinter)GetProcAddress(hModule,"SetDefaultPrinterW");
#else
pfnSetDefaultPrinter = (PFN_SetDefaultPrinter)GetProcAddress(hModule,"SetDefaultPrinterA");
#endif
BOOL bRetValue = FALSE;
if(pfnSetDefaultPrinter)
{
pfnSetDefaultPrinter(_T("MyPrinter"));
}
if(bLoad)
FreeLibrary(hModule);Top
5 楼jinn()回复于 2003-12-03 16:39:03 得分 0
使用我知道,但是每次Compile都说我的SetDefaultPrinter undeclared,
why? How can I do?Top
6 楼carbon107(<软件开发思想.h>)回复于 2003-12-03 16:40:41 得分 5
译:
pszPrinter指向一个默认打印机名字的字符串, 对于一个远程打印机,名字格式为\\server\printername,对于本地打印机, 格式就是printername
如果这个参数为空或一个空的字符串, 如果你已经有个默认的打印机了,setdefaultprinter也不做任何事.但是, 如果没有默认的打印机,setdefaultprinter 设定默认的打印机为第一个打印机(从本地打印机中枚举出来的)
当你用这个方法时,就必须指定一个有效的打印机,驱动,端口.如果是无效的, 这个API作用不是失败,而是结果没有定义。你可以用EnumPrinters这个函数来检索打印机的名字,驱动名,端口名(从所有的可用打印中)
本人译,希望对你有所帮助Top
7 楼osborn(SEANX)回复于 2003-12-03 16:48:31 得分 0
直接用函数指针!不用头文件了!这样编译不会报错的。Top
8 楼jinn()回复于 2003-12-03 16:56:49 得分 0
To osborn,
I used your code, but the compile result is :
"hMoudle": undeclared indentifier
why?
thanksTop
9 楼osborn(SEANX)回复于 2003-12-03 17:04:33 得分 0
第一行就定义了啊,HMODULE hModule = GetModuleHandle(_T("WINSPOOL.DRV"));
哪一行报错啊??Top
10 楼wangweixing2000(星(inspiration(灵感)))回复于 2003-12-03 18:04:41 得分 5
upTop
11 楼jinn()回复于 2003-12-04 09:23:58 得分 0
Thanks osborn and all,
问题解决,给分!
自己加载是可以了,但我不明白为什么SetDefaultPrinter不能用,微软网站上的
MSDN里写的有,而我的VC6里的MSDN却没有这个函数的说明。
难道是.net里面的东东吗?困惑!!!
Top
12 楼osborn(SEANX)回复于 2003-12-04 09:46:27 得分 80
要想用头文件必须更新你的platform sdk,当然装了.net,就肯定可以用了。Top
13 楼jinn()回复于 2003-12-04 10:16:33 得分 0
谢谢,给分!Top




