是否需要写驱动?

解决方案 »

  1.   

    不需要。
    使用SHChangeNotifyRegister函数。
      

  2.   

    可是这样的话在Win9x下就失效了呀
      

  3.   

    可以使用 API 挂钩,钩住 CopyFile 等函数,参考:
    http://www.xfocus.net/articles/200403/681.html
      

  4.   

    再请教一下如何打印的API是哪个呀?谢谢了,问完这个马上结帖!
      

  5.   

    StartDoc
    StartPage
    EndPage
    EndDocMSDN里的例子
    memset( &di, 0, sizeof(DOCINFO) );
        di.cbSize = sizeof(DOCINFO); 
        di.lpszDocName = "Bitmap Printing Test"; 
        di.lpszOutput = (LPTSTR) NULL; 
        di.lpszDataType = (LPTSTR) NULL; 
        di.fwType = 0; 
     
        // Begin a print job by calling the StartDoc function. 
     
        nError = StartDoc(pd.hDC, &di); 
        if (nError == SP_ERROR) 
        { 
            errhandler("StartDoc", hwnd); 
            goto Error; 
        } 
     
        // Inform the driver that the application is about to begin 
        // sending data. 
     
        nError = StartPage(pd.hDC); 
        if (nError <= 0) 
        { 
            errhandler("StartPage", hwnd); 
            goto Error; 
        } 
     
        // Retrieve the number of pixels-per-logical-inch in the 
        // horizontal and vertical directions for the display upon which 
        // the bitmap was created. These are likely the same as for 
        // the present display, so we use those values here. 
     
        hWinDC = GetDC(hWnd);
        fLogPelsX1 = (float) GetDeviceCaps(hWinDC, LOGPIXELSX); 
        fLogPelsY1 = (float) GetDeviceCaps(hWindDC, LOGPIXELSY); 
     
        // Retrieve the number of pixels-per-logical-inch in the 
        // horizontal and vertical directions for the printer upon which 
        // the bitmap will be printed. 
     
        fLogPelsX2 = (float) GetDeviceCaps(pd.hDC, LOGPIXELSX); 
        fLogPelsY2 = (float) GetDeviceCaps(pd.hDC, LOGPIXELSY); 
     
        // Determine the scaling factors required to print the bitmap and 
        // retain its original proportions. 
     
        if (fLogPelsX1 > fLogPelsX2) 
            fScaleX = (fLogPelsX1 / fLogPelsX2); 
        else fScaleX = (fLogPelsX2 / fLogPelsX1); 
     
        if (fLogPelsY1 > fLogPelsY2) 
            fScaleY = (fLogPelsY1 / fLogPelsY2); 
        else fScaleY = (fLogPelsY2 / fLogPelsY1); 
     
        // Compute the coordinates of the upper left corner of the 
        // centered bitmap. 
     
        cWidthPels = GetDeviceCaps(pd.hDC, HORZRES); 
        xLeft = ((cWidthPels / 2) - ((int) (((float) bmih.biWidth) 
                * fScaleX)) / 2); 
        cHeightPels = GetDeviceCaps(pd.hDC, VERTRES); 
        yTop = ((cHeightPels / 2) - ((int) (((float) bmih.biHeight) 
                * fScaleY)) / 2); 
     
        // Use StretchDIBits to scale the bitmap and maintain 
        // its original proportions (that is, if the bitmap was square 
        // when it appeared in the application's client area, it should 
        // also appear square on the page). 
     
        if (StretchDIBits(pd.hDC, xLeft, yTop, (int) ((float) bmih.biWidth 
            * fScaleX), (int) ((float) bmih.biHeight * fScaleY), 0, 0, 
            bmih.biWidth, bmih.biHeight, lpBits, lpBitsInfo, iUsage, 
            SRCCOPY) == GDI_ERROR) 
        {
            errhandler("StretchDIBits Failed", hwnd); 
        }
     
     
        // Retrieve the width of the string that specifies the full path 
        // and filename for the file that contains the bitmap. 
     
        GetTextExtentPoint32(pd.hDC, ofn.lpstrFile, 
            ofn.nFileExtension + 3, &szMetric); 
     
        // Compute the starting point for the text-output operation. The 
        // string will be centered horizontally and positioned three lines 
        // down from the top of the page. 
     
        xLeft = ((cWidthPels / 2) - (szMetric.cx / 2)); 
        yTop = (szMetric.cy * 3); 
     
        // Print the path and filename for the bitmap, centered at the top 
        // of the page. 
     
        TextOut(pd.hDC, xLeft, yTop, ofn.lpstrFile, 
            ofn.nFileExtension + 3); 
     
        // Determine whether the user has pressed the Cancel button in the 
        // AbortPrintJob dialog box; if the button has been pressed, call 
        // the AbortDoc function. Otherwise, inform the spooler that the 
        // page is complete. 
     
        nError = EndPage(pd.hDC); 
     
        if (nError <= 0) 
        { 
            errhandler("EndPage", hwnd); 
            goto Error; 
        } 
     
        // Inform the driver that document has ended. 
     
        nError = EndDoc(pd.hDC); 
        if (nError <= 0) 
            errhandler("EndDoc", hwnd); 
     
    Error: 
        // Enable the application's window. 
     
        EnableWindow(hwnd, TRUE); 
     
        // Remove the AbortPrintJob dialog box. 
     
        DestroyWindow(hdlgCancel); 
     
        // Delete the printer DC. 
     
        DeleteDC(pd.hDC);