如何得到默认打印机?

shallchen 2004-03-17 06:08:03
如何得到默认打印机?在WIN32 SDK下编程,主要是如何把这个“默认”的找出来,谢谢!
...全文
109 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
shallchen 2004-03-18
  • 打赏
  • 举报
回复
好吧,就暂时用仁兄的方法吧!给你散分了。
bluebohe 2004-03-18
  • 打赏
  • 举报
回复
建议你自己研究一下EnumPrinters函数和GetDefaultPrinter,后者在Win2000中需要更新SDK
给你一个可用的方法
static char szPrinter[80];
char *szDevice,*szDriver,*szOutPut;
GetProfileString("windows","device",",,,",szPrinter,80);
szDevice=strtok(szPrinter,",");
szDriver=strtok(NULL,",");
szOutPut=strtok(NULL,",");
if(szDevice&&szDriver&&szOutPut)
{
// return CreateDC(szDriver,szDevice,szOutPut,NULL);
}
shallchen 2004-03-18
  • 打赏
  • 举报
回复
通过word进程获得当前默认打印机的方法,这种方法对我来说恐怕不切实际,继续请教
shallchen 2004-03-18
  • 打赏
  • 举报
回复
PRINTER_ENUM_DEFAULT 只是在WIN95下设置有效,在WIN2000下这样设置还是查不出来。继续
liuxianzhi 2004-03-17
  • 打赏
  • 举报
回复
以前我写的通过word进程获得当前默认打印机的方法,你参考一下吧!
try
{
//ASSERT (NULL==m_objWord);
m_objWord = new _ApplicationWord;

if (!m_objWord->CreateDispatch("Word.Application", NULL))
{
AfxMessageBox("不能创建Word对象!", MB_ICONSTOP);
delete m_objWord; m_objWord = NULL;
throw 0;
return;
}
else{
// AfxMessageBox("成功创建Word对象!");
m_sOldDefaultPrinter = m_objWord->GetActivePrinter(); // Verify the new
if(m_sOldDefaultPrinter.Find(m_sNewPrinter)<0)
{
m_objWord->SetActivePrinter(m_sNewPrinter); //设置当前打印机
}
}
}
catch(COleException *oe)
{
oe->ReportError();
delete oe;
}
bluebohe 2004-03-17
  • 打赏
  • 举报
回复
PRINTER_ENUM_DEFAULT 这表标志的话不就是默认的么?
shallchen 2004-03-17
  • 打赏
  • 举报
回复
得到了所有打印机相关信息,怎么来判断哪一个是默认的呢?问题依然存在,继续求助!
bluebohe 2004-03-17
  • 打赏
  • 举报
回复
BOOL EnumPrinters(
DWORD Flags, // printer object types
LPTSTR Name, // name of printer object
DWORD Level, // information level
LPBYTE pPrinterEnum, // printer information buffer
DWORD cbBuf, // size of printer information buffer
LPDWORD pcbNeeded, // bytes received or required
LPDWORD pcReturned // number of printers enumerated
);

Flags :
PRINTER_ENUM_DEFAULT Windows 95: The function returns information about the default printer.
shallchen 2004-03-17
  • 打赏
  • 举报
回复
知道了default printer name还用着再得到吗此外在WIN32 APPLICATION 找不到这个函数,所以问题没有解决,继续请教。
vcforever 2004-03-17
  • 打赏
  • 举报
回复
agree with bluebohe(薄荷) (MVP)

use GetDefaultPrinter !
bluebohe 2004-03-17
  • 打赏
  • 举报
回复
GetDefaultPrinter
The GetDefaultPrinter function retrieves the printer name of the default printer for the current user on the local computer.

BOOL GetDefaultPrinter(
LPTSTR pszBuffer, // printer name buffer
LPDWORD pcchBuffer // size of name buffer
);
Parameters
pszBuffer
[in] Pointer to a buffer that receives a null-terminated character string containing the default printer name. If this parameter is NULL, the function fails and the variable pointed to by pcchBuffer returns the required buffer size, in characters.
pcchBuffer
[in/out] On input, specifies the size, in characters, of the pszBuffer buffer. On output, receives the size, in characters, of the printer name string, including the terminating null character.
Return Values
If the function succeeds, the return value is a nonzero value and the variable pointed to by pcchBuffer contains the number of characters copied to the pszBuffer buffer, including the terminating null character.

If the function fails, the return value is zero. To get extended error information, call GetLastError, which can return one of the following error codes.

Value Meaning
ERROR_INSUFFICIENT_BUFFER The pszBuffer buffer is too small. The variable pointed to by pcchBuffer contains the required buffer size, in characters.
ERROR_FILE_NOT_FOUND There is no default printer.

16,472

社区成员

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

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

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