void CControlPrinterDlg::OnSelchangePrinters()
{
// TODO: Add your control notiflication handler code here
m_listBox2.ResetContent();
int nIndex=m_listBox.GetCurSel();
CString strPrinterName;
if (nIndex!=CB_ERR) {
m_listBox.GetText(nIndex,strPrinterName);
if (!strPrinterName.IsEmpty()) {
ListJobs((LPTSTR)(LPCSTR)strPrinterName);
}
}
}
BOOL CControlPrinterDlg::ListJobs(LPSTR szPrinterName)
{
HANDLE hPrinter;
DWORD dwNeeded,dwReturned,i;
JOB_INFO_1 *pJobInfo;
if (!OpenPrinter(szPrinterName,&hPrinter,NULL)) {
return false;
}
if (!EnumJobs(hPrinter,0,0xFFFFFFFF,1,NULL,0,&dwNeeded,&dwReturned)) {
if (GetLastError()!=ERROR_INSUFFICIENT_BUFFER) {
ClosePrinter(hPrinter);
return false;
}
}
if ((pJobInfo=(JOB_INFO_1*)malloc(dwNeeded))==NULL) {
ClosePrinter(hPrinter);
return false;
}
if (!EnumJobs(hPrinter,0,0xFFFFFFFF,1,(LPBYTE)pJobInfo,
dwNeeded,&dwNeeded,&dwReturned)) {
ClosePrinter(hPrinter);
free(pJobInfo);
return false;
}
ClosePrinter(hPrinter);
for(i=0;i<dwReturned;i++)
{
m_listBox2.AddString(pJobInfo[i].pDocument);
}
free(pJobInfo);
return true;
}