怎么监视打印机?我希望能用HOOK,不知可不可以?我希望能HOOK打印发送程序和打印处理程序之间交流的消息,不知可不可以,谢谢。
解决方案 »
- cpu 占用高
- WIN7下窗口的左窗口是用的什么接口?IShellView?
- 200分哦~ 如何直接使用微软的JS引擎
- 为什么加了这几句我的鼠标弹起事件就不响应了??
- 热烈庆祝我的生日!
- 求救! 如何将ScrollView的水平滚动条只是隐藏不见?
- 《深入浅出MFC》中Command Routing一节有些不懂的地方。正如P153页所说的,当CMyFrameWnd对象获得一个WM_COMMAND时,所引起的消息怎么会
- 我新建一个类出现的问题!帮我看看!谢谢!
- 文件操作
- 请问 CEdit 类有没有取得edit上文本内容的函数?
- 一个超级郁闷的问题,在线等待,马上揭帖!
- CHtmlView的单文档程序,如何使用JavaScript向应用程序发送命令或消息?
为什么GetProcAddress不能对WINSPOOL.DRV作用呢?
By Merrion
然后
做监听处理
不过
用hook我想是可以的
不过
hook我没有用过!
WH_CALLWNDPROC和WH_CALLWNDPROCRET Hooks使你可以监视发送到窗口过程的消息。系统在消息发送到接收窗口过程之前调用WH_CALLWNDPROC Hook子程,并且在窗口过程处理完消息之后调用WH_CALLWNDPROCRET Hook子程。
如果某个应用程序调用打印 可以用HOOk钩住 但是从Print Pool到Printer不知真么监视
DDk不是很熟
发出消息wm_spoolrestatus
处理该消息
CWnd::OnSpoolerStatus See AlsoThe framework calls this member function from Print Manager whenever a job is added to or removed from the Print Manager queue.afx_msg void OnSpoolerStatus(
UINT nStatus,
UINT nJobs
);
不过
我没有这么写
用很笨的办法
线程处理:
bool CPrintList::OperateJob(int index)
{
HANDLE handle;
JOB_INFO_2 *pJobStorage = NULL;
PRINTER_INFO_2 *pPrinterInfo = NULL;
DWORD cByteNeeded,cByteUsed,nReturned; char buf[256];
DWORD dw = 256;
BOOL isadd = false; if (!m_bselected) return false; isadd =GetDefaultPrinter(buf,&dw);
if (!isadd)
return false ;
if(!OpenPrinter(buf,&handle,NULL))
{
MessageBox(_T("Could not open printer"),_T("Error"), MB_ICONINFORMATION);
return false;
}
if (!GetPrinter(handle, 2, NULL, 0, &cByteNeeded))
{
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
return false;
}
pPrinterInfo = (PRINTER_INFO_2 *)malloc(cByteNeeded);
if (!(pPrinterInfo))
return false; /* Failure to allocate memory. */ if (!GetPrinter(handle, 2,(LPBYTE)pPrinterInfo, cByteNeeded, &cByteUsed))
{
/* Failure to access the printer. */
free(pPrinterInfo);
pPrinterInfo = NULL;
return false;
} if (!EnumJobs(handle, 0, pPrinterInfo->cJobs, 2,NULL,0,(LPDWORD)&cByteNeeded,(LPDWORD)&nReturned))
{
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
free(pPrinterInfo);
pPrinterInfo = NULL;
return false;
}
}
pJobStorage = (JOB_INFO_2 *)malloc(cByteNeeded);
if (!pJobStorage)
{
/* Failure to allocate Job storage space. */
free(pPrinterInfo);
pPrinterInfo = NULL;
return false;
}
ZeroMemory(pJobStorage, cByteNeeded); if (!EnumJobs(handle,0,pPrinterInfo->cJobs, 2,(LPBYTE)pJobStorage, cByteNeeded,(LPDWORD)&cByteUsed,(LPDWORD)&nReturned))
{
free(pPrinterInfo);
free(pJobStorage);
pJobStorage = NULL;
pPrinterInfo = NULL;
return false;
} if (!nReturned) //打印队列中没有数据
{
free(pPrinterInfo);
free(pJobStorage);
pJobStorage = NULL;
pPrinterInfo = NULL;
return true;
} for (int i = 0; i < (int)nReturned; i++)
{
if (m_selectjob.JobID == pJobStorage[i].JobId )
{
if (index == 0)
SetJob(handle,pJobStorage[i].JobId,0,NULL,JOB_CONTROL_PAUSE);
else if (index == 1)
SetJob(handle,pJobStorage[i].JobId,0,NULL,JOB_CONTROL_RESTART);
else if (index == 2)
SetJob(handle,pJobStorage[i].JobId,0,NULL,JOB_CONTROL_DELETE);
else if (index == 3)
SetJob(handle,pJobStorage[i].JobId,0,NULL,JOB_CONTROL_RESUME);
break;
}
}
free(pPrinterInfo);
free(pJobStorage);
pPrinterInfo = NULL;
pJobStorage = NULL;
m_bselected = false;
return true;
}
关于
hookWH_CALLWNDPROC和WH_CALLWNDPROCRET Hooks
WH_CALLWNDPROC和WH_CALLWNDPROCRET Hooks使你可以监视发送到窗口过程的消息。系统在消息发送到接收窗口过程之前调用WH_CALLWNDPROC Hook子程,并且在窗口过程处理完消息之后调用WH_CALLWNDPROCRET Hook子程。怎么用的
给我发一点?
thank you !
Sample Code BOOL GetJobs(HANDLE hPrinter, /* Handle to the printer. */ JOB_INFO_2 **ppJobInfo, /* Pointer to be filled. */
int *pcJobs, /* Count of jobs filled. */
DWORD *pStatus) /* Print Queue status. */ { DWORD cByteNeeded,
nReturned,
cByteUsed;
JOB_INFO_2 *pJobStorage = NULL;
PRINTER_INFO_2 *pPrinterInfo = NULL; /* Get the buffer size needed. */
if (!GetPrinter(hPrinter, 2, NULL, 0, &cByteNeeded))
{
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
return FALSE;
} pPrinterInfo = (PRINTER_INFO_2 *)malloc(cByteNeeded);
if (!(pPrinterInfo))
/* Failure to allocate memory. */
return FALSE; /* Get the printer information. */
if (!GetPrinter(hPrinter,
2,
(LPSTR)pPrinterInfo,
cByteNeeded,
&cByteUsed))
{
/* Failure to access the printer. */
free(pPrinterInfo);
pPrinterInfo = NULL;
return FALSE;
} /* Get job storage space. */
if (!EnumJobs(hPrinter,
0,
pPrinterInfo->cJobs,
2,
NULL,
0,
(LPDWORD)&cByteNeeded,
(LPDWORD)&nReturned))
{
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
free(pPrinterInfo);
pPrinterInfo = NULL;
return FALSE;
}
} pJobStorage = (JOB_INFO_2 *)malloc(cByteNeeded);
if (!pJobStorage)
{
/* Failure to allocate Job storage space. */
free(pPrinterInfo);
pPrinterInfo = NULL;
return FALSE;
} ZeroMemory(pJobStorage, cByteNeeded); /* Get the list of jobs. */
if (!EnumJobs(hPrinter,
0,
pPrinterInfo->cJobs,
2,
(LPBYTE)pJobStorage,
cByteNeeded,
(LPDWORD)&cByteUsed,
(LPDWORD)&nReturned))
{
free(pPrinterInfo);
free(pJobStorage);
pJobStorage = NULL;
pPrinterInfo = NULL;
return FALSE;
} /*
* Return the information.
*/
*pcJobs = nReturned;
*pStatus = pPrinterInfo->Status;
*ppJobInfo = pJobStorage;
free(pPrinterInfo); return TRUE; } BOOL IsPrinterError(HANDLE hPrinter)
{ JOB_INFO_2 *pJobs;
int cJobs,
i;
DWORD dwPrinterStatus; /*
* Get the state information for the Printer Queue and
* the jobs in the Printer Queue.
*/
if (!GetJobs(hPrinter, &pJobs, &cJobs, &dwPrinterStatus))
return FALSE; /*
* If the Printer reports an error, believe it.
*/
if (dwPrinterStatus &
(PRINTER_STATUS_ERROR |
PRINTER_STATUS_PAPER_JAM |
PRINTER_STATUS_PAPER_OUT |
PRINTER_STATUS_PAPER_PROBLEM |
PRINTER_STATUS_OUTPUT_BIN_FULL |
PRINTER_STATUS_NOT_AVAILABLE |
PRINTER_STATUS_NO_TONER |
PRINTER_STATUS_OUT_OF_MEMORY |
PRINTER_STATUS_OFFLINE |
PRINTER_STATUS_DOOR_OPEN))
{
return TRUE;
} /*
* Find the Job in the Queue that is printing.
*/
for (i=0; i < cJobs; i++)
{
if (pJobs[i].Status & JOB_STATUS_PRINTING)
{
/*
* If the job is in an error state,
* report an error for the printer.
* Code could be inserted here to
* attempt an interpretation of the
* pStatus member as well.
*/
if (pJobs[i].Status &
(JOB_STATUS_ERROR |
JOB_STATUS_OFFLINE |
JOB_STATUS_PAPEROUT |
JOB_STATUS_BLOCKED_DEVQ))
{
return TRUE;
}
}
} /*
* No error condition.
*/
return FALSE; }
这段程序中:
if (m_selectjob.JobID == pJobStorage[i].JobId )
{
if (index == 0)
SetJob(handle,pJobStorage[i].JobId,0,NULL,JOB_CONTROL_PAUSE);
else if (index == 1)
SetJob(handle,pJobStorage[i].JobId,0,NULL,JOB_CONTROL_RESTART);
else if (index == 2)
SetJob(handle,pJobStorage[i].JobId,0,NULL,JOB_CONTROL_DELETE);
else if (index == 3)
SetJob(handle,pJobStorage[i].JobId,0,NULL,JOB_CONTROL_RESUME);
break;
index是干什么的?m_selectjob是那儿来的?希望详解,我明白了就结帖.谢谢.