谁有实现改变默认打印机及打印机的默认属性的控件的原码,谢谢,分可以再加

wangmingsheng 2002-02-01 11:22:08
...全文
221 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
dancetime 2002-08-27
  • 打赏
  • 举报
回复
mark~~
wangms 2002-02-02
  • 打赏
  • 举报
回复
upup
wangmingsheng 2002-02-02
  • 打赏
  • 举报
回复
帮帮忙吧
wangmingsheng 2002-02-02
  • 打赏
  • 举报
回复
自己up一下吧,
帮忙up的也有分,
谢谢
wangmingsheng 2002-02-02
  • 打赏
  • 举报
回复
我没用过VC,希望大家能解释清楚点谢谢
wangmingsheng 2002-02-02
  • 打赏
  • 举报
回复
pzone(见分眼红) 能不能详细解释一下
typedef struct tagDEVNAMES { // dvnm
WORD wDriverOffset;
WORD wDeviceOffset;
WORD wOutputOffset;
WORD wDefault;
// driver, device, and port name strings follow wDefault
} DEVNAMES;
各个变量的用途;
TangDL(^_^) :修改Ini文件 ,怎么改,98中不能用程序实现吗?
TangDL 2002-02-02
  • 打赏
  • 举报
回复
以上为修改缺省打印机,修改属性API为GetPrinter/SetPrinter
TangDL 2002-02-02
  • 打赏
  • 举报
回复
Win2K: GetDefaultPrinter/SetDefaultPrinter
Win98: 修改Ini文件
wangmingsheng 2002-02-02
  • 打赏
  • 举报
回复
自己up一下吧,
wangmingsheng 2002-02-02
  • 打赏
  • 举报
回复
upup
pzone 2002-02-02
  • 打赏
  • 举报
回复
函数由指定的设备名,获得DEVMODE 与DEVNAMES 所需要的内容,再由它们设置打印机,ok.
wangmingsheng 2002-02-02
  • 打赏
  • 举报
回复
pzone(见分眼红)
让您就等了,那50分给了,
今天之前就结,
你缺分的话,
我再开一贴
wangmingsheng 2002-02-02
  • 打赏
  • 举报
回复
谢谢
pzone 2002-02-02
  • 打赏
  • 举报
回复
not call DoPreparePrinting().
wangmingsheng 2002-02-02
  • 打赏
  • 举报
回复
pzone(见分眼红)
先到http://www.csdn.net/Expert/topic/514/514630.shtm
我先付50分,这个贴子我想等会儿再结,
谢谢你
pzone 2002-02-02
  • 打赏
  • 举报
回复
再不给分,我可要告你了!嘿、嘿
pzone 2002-02-02
  • 打赏
  • 举报
回复
class CMyApp : public CWinApp
{
public:
CTestprintApp();
BOOL SetPrinterDevice(char*);
...
};

#include <winspool.h>

BOOL CMyApp::SetPrinterDevice(char* pszDeviceName)
{
// Open printer and obtain PRINTER_INFO_2 structure.
HANDLE hPrinter;
if (OpenPrinter(pszDeviceName, &hPrinter, NULL) == FALSE)
return FALSE;
DWORD dwBytesReturned, dwBytesNeeded;
GetPrinter(hPrinter, 2, NULL, 0, &dwBytesNeeded);
PRINTER_INFO_2* p2 = (PRINTER_INFO_2*)GlobalAlloc(GPTR,
dwBytesNeeded);
if (GetPrinter(hPrinter, 2, (LPBYTE)p2, dwBytesNeeded,
&dwBytesReturned) == 0) {
GlobalFree(p2);
ClosePrinter(hPrinter);
return FALSE;
}
ClosePrinter(hPrinter);

// Allocate a global handle for DEVMODE and copy DEVMODE data.
HGLOBAL hDevMode = GlobalAlloc(GHND, sizeof(*p2->pDevMode));
DEVMODE* pDevMode = (DEVMODE*)GlobalLock(hDevMode);
memcpy(pDevMode, p2->pDevMode, sizeof(*p2->pDevMode));
GlobalUnlock(hDevMode);

// Compute size of DEVNAMES structure you'll need.
DWORD drvNameLen = strlen(p2->pDriverName); // driver name
DWORD ptrNameLen = strlen(p2->pPrinterName); // printer name
DWORD porNameLen = strlen(p2->pPortName); // port name
DWORD devNameSize = sizeof(DEVNAMES) +
ptrNameLen + porNameLen + drvNameLen + 3;

// Allocate a global handle big enough to hold DEVNAMES.
HGLOBAL hDevNames = GlobalAlloc(GHND, devNameSize);
DEVNAMES* pDevNames = (DEVNAMES*)GlobalLock(hDevNames);

// Copy the DEVNAMES information from PRINTER_INFO_2 structure.
pDevNames->wDriverOffset = sizeof(DEVNAMES);
memcpy((char*)pDevNames + pDevNames->wDriverOffset,
p2->pDriverName, drvNameLen);

pDevNames->wDeviceOffset = sizeof(DEVNAMES) +
drvNameLen + 1;
memcpy((char*)pDevNames + pDevNames->wDeviceOffset,
p2->pPrinterName, ptrNameLen);

pDevNames->wOutputOffset = sizeof(DEVNAMES) +
drvNameLen + ptrNameLen + 2;
memcpy((char*)pDevNames + pDevNames->wOutputOffset,
p2->pPortName, porNameLen);

pDevNames->wDefault = 0;

GlobalUnlock(hDevNames);
GlobalFree(p2); // free PRINTER_INFO_2

m_hDevMode = hDevMode;
m_hDevNames = hDevNames;
return TRUE;
}
pzone 2002-02-02
  • 打赏
  • 举报
回复

1.Call the Windows API functions GetProfileString and WriteProfileString to change the printer setting device= in the [windows] section of the WIN.INI file to one of the printers listed in the [devices] section.
For example, a WIN.INI file would contain the following settings to make an HP LaserJet the default printer:



[windows]
device=HP LaserJet IIISi PostScript,pscript,LPT1:



[devices]
Generic / Text Only=TTY,FILE:
HP LaserJet IIISi PostScript=pscript,LPT1:


2.Call the Windows API WriteProfileString function using all NULL pointer parameters to force Windows to reload the WIN.INI file into memory. (WIN.INI is normally cached in memory and not reloaded until you restart Windows.) Pass all parameters By Value as type Long with value 0.

3.Call the SendMessage API function with hWnd% parameter set to HWND_BROADCAST (&hffff) to broadcast a message to all pop-up windows currently loaded in the system. Setting the wMsg% parameter to WM_WININICHANGE notifies all top-level windows of a WIN.INI change, and WM_DEVMODECHANGE notifies them of a device-mode change.

wangmingsheng 2002-02-02
  • 打赏
  • 举报
回复
自己up一下吧,
pzone 2002-02-02
  • 打赏
  • 举报
回复
试通,我等分用
加载更多回复(4)

16,551

社区成员

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

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

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