请教API函数 SetDefaultPrinter的用法,在线等待,当天给贴!

jinn 2003-12-03 03:57:56
我以经include "winspool.h",但还是提示我SetDefaultPrinter没有定义,
我查看本地的MSDN没有这个函数,但微软网站上的MSDN却有。
我是VC6.0.是否需要.NET?
急,在线!
谢谢!
...全文
501 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinn 2003-12-04
  • 打赏
  • 举报
回复
谢谢,给分!
osborn 2003-12-04
  • 打赏
  • 举报
回复
要想用头文件必须更新你的platform sdk,当然装了.net,就肯定可以用了。
jinn 2003-12-04
  • 打赏
  • 举报
回复
Thanks osborn and all,
问题解决,给分!
自己加载是可以了,但我不明白为什么SetDefaultPrinter不能用,微软网站上的
MSDN里写的有,而我的VC6里的MSDN却没有这个函数的说明。
难道是.net里面的东东吗?困惑!!!
wangweixing2000 2003-12-03
  • 打赏
  • 举报
回复
up
osborn 2003-12-03
  • 打赏
  • 举报
回复
第一行就定义了啊,HMODULE hModule = GetModuleHandle(_T("WINSPOOL.DRV"));

哪一行报错啊??
jinn 2003-12-03
  • 打赏
  • 举报
回复
To osborn,

I used your code, but the compile result is :
"hMoudle": undeclared indentifier

why?
thanks
osborn 2003-12-03
  • 打赏
  • 举报
回复
直接用函数指针!不用头文件了!这样编译不会报错的。
carbon107 2003-12-03
  • 打赏
  • 举报
回复
译:
pszPrinter指向一个默认打印机名字的字符串, 对于一个远程打印机,名字格式为\\server\printername,对于本地打印机, 格式就是printername
如果这个参数为空或一个空的字符串, 如果你已经有个默认的打印机了,setdefaultprinter也不做任何事.但是, 如果没有默认的打印机,setdefaultprinter 设定默认的打印机为第一个打印机(从本地打印机中枚举出来的)
当你用这个方法时,就必须指定一个有效的打印机,驱动,端口.如果是无效的, 这个API作用不是失败,而是结果没有定义。你可以用EnumPrinters这个函数来检索打印机的名字,驱动名,端口名(从所有的可用打印中)

本人译,希望对你有所帮助
jinn 2003-12-03
  • 打赏
  • 举报
回复
使用我知道,但是每次Compile都说我的SetDefaultPrinter undeclared,
why? How can I do?
osborn 2003-12-03
  • 打赏
  • 举报
回复
自己加载!

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);
jinn 2003-12-03
  • 打赏
  • 举报
回复
我的STDAFX.H里面没有WINVER 宏,能说详细一点吗?
我是WIN2000系统.
谢谢!
carbon107 2003-12-03
  • 打赏
  • 举报
回复
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.
sdwtao 2003-12-03
  • 打赏
  • 举报
回复
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宏改成5

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧