Ejemplo n.º 1
0
static void EnumeratePrinters() {
    str::Str<WCHAR> output;

    PRINTER_INFO_5 *info5Arr = nullptr;
    DWORD bufSize = 0, printersCount;
    bool fOk = EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, nullptr, 5, nullptr,
                            bufSize, &bufSize, &printersCount);
    if (fOk || GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
        info5Arr = (PRINTER_INFO_5 *)malloc(bufSize);
        fOk = EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, nullptr, 5,
                           (LPBYTE)info5Arr, bufSize, &bufSize, &printersCount);
    }
    if (!fOk || !info5Arr) {
        output.AppendFmt(L"Call to EnumPrinters failed with error %#x", GetLastError());
        MessageBox(nullptr, output.Get(), L"SumatraPDF - EnumeratePrinters", MB_OK | MB_ICONERROR);
        free(info5Arr);
        return;
    }
    ScopedMem<WCHAR> defName(GetDefaultPrinterName());
    for (DWORD i = 0; i < printersCount; i++) {
        const WCHAR *printerName = info5Arr[i].pPrinterName;
        const WCHAR *printerPort = info5Arr[i].pPortName;
        bool fDefault = str::Eq(defName, printerName);
        output.AppendFmt(L"%s (Port: %s, attributes: %#x%s)\n", printerName, printerPort,
                         info5Arr[i].Attributes, fDefault ? L", default" : L"");

        DWORD bins = DeviceCapabilities(printerName, printerPort, DC_BINS, nullptr, nullptr);
        DWORD binNames =
            DeviceCapabilities(printerName, printerPort, DC_BINNAMES, nullptr, nullptr);
        CrashIf(bins != binNames);
        if (0 == bins) {
            output.Append(L" - no paper bins available\n");
        } else if (bins == (DWORD)-1) {
            output.AppendFmt(L" - Call to DeviceCapabilities failed with error %#x\n",
                             GetLastError());
        } else {
            ScopedMem<WORD> binValues(AllocArray<WORD>(bins));
            DeviceCapabilities(printerName, printerPort, DC_BINS, (WCHAR *)binValues.Get(),
                               nullptr);
            ScopedMem<WCHAR> binNameValues(AllocArray<WCHAR>(24 * binNames));
            DeviceCapabilities(printerName, printerPort, DC_BINNAMES, binNameValues.Get(), nullptr);
            for (DWORD j = 0; j < bins; j++) {
                output.AppendFmt(L" - '%s' (%d)\n", binNameValues.Get() + 24 * j,
                                 binValues.Get()[j]);
            }
        }
    }
    free(info5Arr);
    MessageBox(nullptr, output.Get(), L"SumatraPDF - EnumeratePrinters",
               MB_OK | MB_ICONINFORMATION);
}
Ejemplo n.º 2
0
 /**
  * Calculate the Y and E values for the given possible overlap
  * @param inputWS :: A pointer to the inputWS
  * @param newPoly :: A reference to a polygon to test for overlap
  * @returns A pair of Y and E values
  */
 std::pair<double,double> 
 SofQW2::calculateYE(API::MatrixWorkspace_const_sptr inputWS,
                     const ConvexPolygon & newPoly) const
 {
   // Build a list intersection locations in terms of workspace indices
   // along with corresponding weights from that location
   std::vector<BinWithWeight> overlaps = findIntersections(inputWS, newPoly);
   std::pair<double,double> binValues(0,0);
   if( inputWS->isDistribution() )
   {
     const double newWidth = newPoly[3].X() - newPoly[0].X(); // For distribution
     binValues = calculateDistYE(inputWS, overlaps, newWidth);
   }
   else
   {
     binValues = calculateYE(inputWS, overlaps);
   }
   return binValues;
 }