1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
bool GetPrinterList(HWND hWnd,int id_Ctrl)
{
DWORD dwSizeNeeded;
DWORD dwNumItems;
DWORD dwItem;
LPPRINTER_INFO_2 lpInfo = NULL;
EnumPrinters ( PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &dwSizeNeeded, &dwNumItems );
lpInfo = (LPPRINTER_INFO_2)HeapAlloc ( GetProcessHeap (), HEAP_ZERO_MEMORY, dwSizeNeeded );
if ( lpInfo == NULL )
{
puts ( "Not enough memory\n" );
return 0;
}
if ( EnumPrinters ( PRINTER_ENUM_LOCAL,
NULL,
2,
(LPBYTE)lpInfo,
dwSizeNeeded,
&dwSizeNeeded,
&dwNumItems
) == 0 )
{
MessageBox(NULL,"Impossible de trouver les imprimantes","erreur !!!",MB_OK);
return false;
}
for ( dwItem = 0; dwItem < dwNumItems; dwItem++ )
{
SendDlgItemMessage(hWnd,id_Ctrl,LB_INSERTSTRING,dwItem,(LPARAM)lpInfo[dwItem].pPrinterName);
}
HeapFree ( GetProcessHeap (), 0, lpInfo );
return true;
} |
Partager