Mark Veldt
April 26th, 1999, 08:32 AM
How can i detect if there is any printer installed?
And can i put these printernames into a list?
Thanks in advance,
Mark
And can i put these printernames into a list?
Thanks in advance,
Mark
|
Click to See Complete Forum and Search --> : How to detect if any printer installed Mark Veldt April 26th, 1999, 08:32 AM How can i detect if there is any printer installed? And can i put these printernames into a list? Thanks in advance, Mark klussier April 26th, 1999, 01:23 PM There are several questions that need answers first: Is this Windows 95/98 or NT? Do you want local or network printers (or both). Let's see... If you want to browse for network printers (under 95/98 or NT), you can use the SHBrowseForFolder() function. Here is some code that I use to browse for network printers: // Get the shell's allocator. LPMALLOC g_pMalloc; if ( !SUCCEEDED( SHGetMalloc( &g_pMalloc ) ) ) { MessageBox( _T("Failed to get IMalloc interface"), _T("Select Printer Error"), MB_ICONSTOP | MB_OK ); return; } // Allocate some memory for our buffer LPTSTR location = (LPTSTR)g_pMalloc->Alloc( MAX_PATH ); if ( location == NULL ) { MessageBox( _T("Failed to allocate memory for printer location"), _T("Select Printer Error"), MB_ICONSTOP | MB_OK ); return; } // Get the PIDL for the network folder LPITEMIDLIST pidlNetwork; // PIDL for Network folder if ( !SUCCEEDED( SHGetSpecialFolderLocation( GetSafeHwnd(), CSIDL_NETWORK, &pidlNetwork ) ) ) { // Free allocated memory g_pMalloc->Free( location ); MessageBox( _T("Failed to get the network folder"), _T("Select Printer Error"), MB_ICONSTOP | MB_OK ); return; } // Browse for network printer BROWSEINFO bi; memset( &bi, 0, sizeof( BROWSEINFO ) ); bi.hwndOwner = GetSafeHwnd(); // bi.pidlRoot = NULL; // Desktop bi.pidlRoot = pidlNetwork; // Networks bi.pszDisplayName = location; bi.lpszTitle = _T("Select the network printer that you want to use.\nNote: Printers are usually attached to computers."); bi.ulFlags = BIF_BROWSEFORPRINTER; bi.lpfn = NULL; bi.lParam = NULL; bi.iImage = 0; LPITEMIDLIST pPidl = SHBrowseForFolder( &bi ); if ( pPidl != NULL ) { if ( SHGetPathFromIDList( pPidl, location ) ) { // Set the printer name m_sPrinterName = location; // Send the data to the dialog UpdateData( FALSE ); } // Free the system allocated pidl g_pMalloc->Free( pPidl ); } // Free our network pidl g_pMalloc->Free( pidlNetwork ); // Free our location holder g_pMalloc->Free( location ); For local printers, you'll probably have to use the EnumPrinters() command with the PRINTER_ENUM_LOCAL flag. Sorry, no code snippets here. Hope this helps. Good luck! Kevin Andy St.Clair April 26th, 1999, 01:23 PM Lookup the help on the EnumPrinters() function. There is a lot of data of various type that this function can give you. codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |