阅读:1695回复:3
如何在程序中指定当前默认打印机打印指定的文档
各位大虾,我刚刚做了一个虚拟打印机,可以将打印内容输出成为BMP文件.但我的老板要求必须在程序里由用户来选择某个文档,然后在程序里自动将其发送给当前默认打印机进行打印.晕....
请问有什么方法可以实现这个问题呢? 不胜感激!!!!!!!!! |
|
最新喜欢:xmuhl |
沙发#
发布于:2004-03-19 20:16
没有人顶,自己顶一下先.
诸位大虾,俺在这里跪求了,不愿意告诉我给个思路也行阿 |
|
板凳#
发布于:2004-03-22 18:24
意思不太明白。
你的虚拟打印机又是起什么功能? 给一段取得当前缺省打印机的代码,看有没有用。 typedef BOOL (WINAPI *WINAPI_GetDefaultPrinter)(LPTSTR pszBuffer, LPDWORD pcchBuffer); BOOL DPGetDefaultPrinter(LPTSTR pPrinterName, LPDWORD pdwBufferSize) { BOOL bFlag; OSVERSIONINFO osv; TCHAR cBuffer[MAX_PATH]=""; PRINTER_INFO_2 *ppi2 = NULL; DWORD dwNeeded = 0; DWORD dwReturned = 0; static WINAPI_GetDefaultPrinter procGetDefaultPrinter=NULL; // What version of Windows are you running? osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osv); // If Windows 95 or 98, use EnumPrinters... if (osv.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { EnumPrinters(PRINTER_ENUM_DEFAULT, NULL, 2, NULL, 0, &dwNeeded, &dwReturned); if (dwNeeded == 0) return FALSE; ppi2 = (PRINTER_INFO_2 *)GlobalAlloc(GPTR, dwNeeded); if (!ppi2) return FALSE; // The second EnumPrinters() will fill in all the current information... bFlag = EnumPrinters(PRINTER_ENUM_DEFAULT, NULL, 2, (LPBYTE)ppi2, dwNeeded, &dwNeeded, &dwReturned); if (!bFlag) { GlobalFree(ppi2); return FALSE; } if ((DWORD)lstrlen(ppi2->pPrinterName) >= *pdwBufferSize) { *pdwBufferSize = (DWORD)lstrlen(ppi2->pPrinterName) + 1; GlobalFree(ppi2); return FALSE; } lstrcpy(pPrinterName, ppi2->pPrinterName); *pdwBufferSize = (DWORD)lstrlen(ppi2->pPrinterName) + 1; } // If Windows NT, use the GetDefaultPrinter API for Windows 2000, // or GetProfileString for version 4.0 and earlier... else if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) { //#if(WINVER >= 0x0500) if (osv.dwMajorVersion >= 5) // Windows 2000 or later { if (procGetDefaultPrinter==NULL) { HMODULE hDll=NULL; hDll=GetModuleHandle("WINSPOOL.DRV"); if (hDll==NULL) return FALSE; #ifdef UNICODE procGetDefaultPrinter = (WINAPI_GetDefaultPrinter)GetProcAddress(hDll, _T("GetDefaultPrinterW")); #else procGetDefaultPrinter = (WINAPI_GetDefaultPrinter)GetProcAddress(hDll, "GetDefaultPrinterA"); #endif if (procGetDefaultPrinter==NULL) return FALSE; } bFlag = procGetDefaultPrinter(pPrinterName, pdwBufferSize); if (!bFlag) return FALSE; } else // NT4.0 or earlier //#endif { // Retrieve the default string from Win.ini (the registry). // String will be in form "printername,drivername,portname". if (GetProfileString("windows", "device", ",,,", cBuffer, MAX_PATH) <= 0) return FALSE; // Printer name precedes first "," character... strtok(cBuffer, ","); // If given buffer too small, set required size and fail... if ((DWORD)lstrlen(cBuffer) >= *pdwBufferSize) { *pdwBufferSize = (DWORD)lstrlen(cBuffer) + 1; return FALSE; } // Copy printer name into passed-in buffer... lstrcpy(pPrinterName, cBuffer); // Set buffer size parameter to min required buffer size... *pdwBufferSize = (DWORD)lstrlen(cBuffer) + 1; } } // Cleanup... if (ppi2) GlobalFree(ppi2); return TRUE; } |
|
地板#
发布于:2004-03-27 22:07
谢谢二楼的回复,我已经解决问题了.是用ShellExecute函数将文档发送到系统当前默认打印机打印的
.呵呵 |
|