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.
agree with bluebohe(薄荷) (MVP)use GetDefaultPrinter !
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.
PRINTER_ENUM_DEFAULT 这表标志的话不就是默认的么?
以前我写的通过word进程获得当前默认打印机的方法,你参考一下吧! try { //ASSERT (NULL==m_objWord); m_objWord = new _ApplicationWord;
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.
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.
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;
}
给你一个可用的方法
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);
}