Announcement

Collapse
No announcement yet.

Windows Photo Print Wizard

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Windows Photo Print Wizard

    I spent about a day trying to find a way to invoke the Windows Photo Printing Wizard. I'm not very familiar with the magic incantations of COM so the complicated ways I found were making me dizzy. But I eventually found out that there is very easy solution. I'm posting it here both to help others who may be struggling with the same thing and because I'm very pleased with myself!

    Code:
    #include once "wiapb.inc"          'Declarations for WIAAUT.DLL created by PB's
             'COM Browser (PBROW.EXE) or Jose Roca's TypeLib Browser (TLB_xxx.EXE).
    
    function PrintImage ( _________________________________________________________
     swFileName as wstring _
     ) as long
    '------------------------------------------------------------------------------
    '
    ' Invokes the standard Windows Print Photos Wizard.
    '
    '------------------------------------------------------------------------------
    
    local ComDialog as ICommonDialog
    
    ComDialog = newcom "WIA.CommonDialog"
    ComDialog.ShowPhotoPrintingWizard swFileName
    ComDialog = nothing
    
    end function
    - LJ

    #2
    I tried to expand on the above to be able to pass multiple filespecs in an array to the photo printing wizard. According to the old VB example I found on the web (https://www.vbforums.com/showthread....rinting-Wizard), the following should work but it doesn't.

    Code:
    #include once "wia.inc" 'Declarations for WIAAUT.DLL created by PB's
    'COM Browser (PBROW.EXE) or Jose Roca's TypeLib Browser (TLB_xxx.EXE).
    
    function PrintImage ( _________________________________________________________
    swFileSpec() as wstring _
    ) as long
    '------------------------------------------------------------------------------
    '
    ' Invokes the standard Windows Print Photos Wizard.
    '
    '------------------------------------------------------------------------------
    
    local ComDialog as ICommonDialog
    local Vector as IVector
    local lgCount as long
    
    Vector = newcom "WIA.Vector"
    if isobject(Vector) then
      ComDialog = newcom "WIA.CommonDialog"
      if isobject(ComDialog) then 
        for lgCount = 1 to ubound(swFileSpec)
          Vector.Add swFileSpec(lgCount)
          if objresult <> 0 then exit function
        next lgCount
        ComDialog.ShowPhotoPrintingWizard Vector
      end if
    end if
    
    Vector = nothing
    ComDialog = nothing
    
    end function
    This generates a PB runtime error on "ComDialog.ShowPhotoPrintingWizard Vector", code 99 (Object error). The PB help is not much help as to what may be causing it: "A run-time error occurred involving an object."! If I trap the error and look at the OBJERROR I get the undocumented value &H80210075. I'm pretty much a beginner in using external COM servers. Anyone has any idea what I'm doing wrong? All suggestions gratefully received.

    Note: I have omitted much of the error checking from the posted code for clarity.
    - LJ

    Comment


      #3
      <deleted>
      =========================
      https://camcopng.com
      =========================

      Comment


        #4
        Hi Stuart, thanks for taking an interest. ICommonDialog and IVector are defined in WIA.inc created by the TypeLib Browser - see the first line of the posted code.
        - LJ

        Comment


          #5
          Originally posted by Laurence Jackson View Post
          Hi Stuart, thanks for taking an interest. ICommonDialog and IVector are defined in WIA.inc created by the TypeLib Browser - see the first line of the posted code.
          Yep, My problem was a conflict with the same named .inc file in my includes directory getting in the way.

          Once I resolved that, it compiles and runs fine and creates an object, but doesn't show the wizard.

          '
          Code:
          #COMPILE EXE
          #DIM ALL
          #INCLUDE  "wiaaut2.inc" 'Declarations for WIAAUT.DLL created by PB's COM Browser
          
          FUNCTION PBMAIN() AS LONG
              LOCAL lDebug AS LONG: TXT.WINDOW EXE.FULL$, 200,50,40,85 TO lDebug
               LOCAL wsImage AS WSTRING
               wsImage = "MainMenu.jpg"
               printimage wsImage
          
          'Finalise
              TXT.COLOR = %RGB_BLUE
              TXT.PRINT
              TXT.PRINT "  ....Press any key to exit": TXT.WAITKEY$: TXT.END
          END FUNCTION
          
          FUNCTION PrintImage (swFileSpec AS WSTRING ) AS LONG
              LOCAL ComDialog AS ICommonDialog
              ComDialog = NEWCOM "WIA.CommonDialog"
              IF ISOBJECT(ComDialog) THEN
                  TXT.PRINT "OK"
                  ComDialog.ShowPhotoPrintingWizard swFileSpec
                  ComDialog = NOTHING
              ELSE
                  TXT.PRINT "Not OK"
              END IF
              TXT.PRINT "Done"
          END FUNCTION
          '
          All I get is OK immediately followed by Done

          Click image for larger version  Name:	PhotoPrint.jpg Views:	1 Size:	13.3 KB ID:	818530
          =========================
          https://camcopng.com
          =========================

          Comment


            #6
            You need to pass a fully qualified filespec, complete with path. Then your code works (but the print dialog is hidden under the txt box). Your code is equivalent to my first post which I had working. My query was about the second post, passing multiple filespecs.
            - LJ

            Comment


              #7
              > You need to pass a fully qualified filespec, complete with path

              Yep, I worked that out while you were posting (OBJRESULT returned &H8007002 = File not found )
              Looking at the second issue now that I have the first one resolved
              =========================
              https://camcopng.com
              =========================

              Comment


                #8
                OBJRESULT returns &H80210075 after ComDialog.ShowPhotoPrintingWizard Vector

                Tracking down that error now..

                Google doesn't recognise that value and it's not in here
                https://docs.microsoft.com/en-us/ope...3-3918024b10b8
                =========================
                https://camcopng.com
                =========================

                Comment


                  #9
                  I couldn't find it. That's why I described it as "undocumented". I hope you have better luck!
                  - LJ

                  Comment


                    #10
                    Cracked it! Declare a variant variable, assign the Vector object variable to it, then pass the variant to ComDialog.ShowPhotoPrintingWizard. Thanks Stuart, you gave me the will to continue investigating (happens more often than you think!). I hope that this helps somebody in the future.

                    Code:
                    function PrintImage ( _________________________________________________________
                      swFileSpec() as wstring _
                    ) as long
                    '------------------------------------------------------------------------------
                    '
                    ' Invokes the standard Windows Print Photos Wizard for one or multiple files.
                    ' Note that files must be fully specified with full path.
                    '
                    '------------------------------------------------------------------------------
                    
                    local ComDialog as ICommonDialog
                    local Vector as IVector
                    local lgCount as long
                    local vVector as variant
                    
                    Vector = anycom "WIA.Vector"
                    if isobject(Vector) then
                      ComDialog = anycom "WIA.CommonDialog"
                      if isobject(ComDialog) then
                        for lgCount = 1 to ubound(swFileSpec)
                          Vector.Add swFileSpec(lgCount)
                          if objresult <> 0 then exit function
                        next lgCount
                        vVector = Vector
                        ComDialog.ShowPhotoPrintingWizard(vVector)
                      end if
                    end if
                    
                    Vector = nothing
                    ComDialog = nothing
                    
                    end function
                    - LJ

                    Comment


                      #11
                      Darn it, you just beat me again. Came to post the same solution and saw yours.

                      '
                      Code:
                      #COMPILE EXE
                      #DIM ALL
                      #INCLUDE  "wiaaut2.inc" '
                      FUNCTION PBMAIN() AS LONG
                           DIM wsImages(0 TO 2) AS WSTRING
                           wsImages(0)  = EXE.PATH$  & "MainMenu.jpg"
                           wsImages(1)  = EXE.PATH$  & "Licence.jpg"
                           wsImages(2)  = EXE.PATH$  & "Config.jpg"
                      
                           printimage wsImages()
                      END FUNCTION
                      
                      FUNCTION PrintImage (swFileSpec() AS WSTRING) AS LONG
                      LOCAL WIADLg AS ICommonDialog
                      LOCAL Vec AS IVector
                      LOCAL lgCount AS LONG
                      LOCAL v AS VARIANT
                        WIADlg = NEWCOM "WIA.CommonDialog"
                        IF ISOBJECT(WIADLg) THEN
                          Vec = NEWCOM "WIA.Vector"
                          IF ISOBJECT(Vec) THEN
                              FOR lgCount = 0 TO UBOUND(swFileSpec)
                                  Vec.Add swFileSpec(lgCount)
                              NEXT
                              v = vec
                              WIADLg.ShowPhotoPrintingWizard v
                              Vec = NOTHING
                          END IF
                         WIADlg = NOTHING
                        END IF
                      END FUNCTION
                      '
                      (You will notice that I don't like to use Class names for variables, hence Vec and WIADlg to avoid potential confusion)
                      =========================
                      https://camcopng.com
                      =========================

                      Comment


                        #12
                        For people using Jose Roca's includes
                        You can change the following (no need to create one with COM Browser (PBROW.EXE))
                        In either post#10 or post#11

                        _#INCLUDE "wiaaut.inc" ' Jose Roca's Includes

                        LOCAL WIADLg AS WIA_ICommonDialog
                        LOCAL Vec AS WIA_IVector



                        Comment


                          #13
                          Originally posted by Rod Macia View Post
                          For people using Jose Roca's includes
                          You can change the following (no need to create one with COM Browser (PBROW.EXE))
                          In either post#10 or post#11

                          _#INCLUDE "wiaaut.inc" ' Jose Roca's Includes

                          LOCAL WIADLg AS WIA_ICommonDialog
                          LOCAL Vec AS WIA_IVector


                          Yep, that was what caused my initial issue with iCommonDialog not being recognised
                          =========================
                          https://camcopng.com
                          =========================

                          Comment


                            #14
                            I'd never used the WIA PhotoPrintWizard (I wasn't even aware of it), but it looks like a very handy tool, so I built a simple Drag and Drop uitlity to use it

                            '
                            Code:
                            #COMPILE EXE
                            #DIM ALL
                            #INCLUDE  "wiaaut2.inc" 'PowerBASIC COM Browser (PBRow.exe generated file) from
                                                     ' Library File: C:\Windows\SysWOW64\wiaaut.dll
                                                     ' Description : Microsoft Windows Image Acquisition Library v2.0
                            
                            FUNCTION PBMAIN() AS LONG
                                DIM wsImages() AS WSTRING
                                LOCAL wsFile AS WSTRING
                                LOCAL lArg,lPic AS LONG
                                lArg = 1:lPic = 0
                                WHILE COMMAND$(lArg) > ""
                                    wsFile =TRIM$(COMMAND$(lArg),$DQ)
                                    IF  ISFILE(wsFile) _ In case someone drags and drops a folder!!!
                                            AND LEN(wsFile) > 4 _ At least x.yyy
                                            AND INSTR(".BMP.GIF.ICO.JPG.PNG,.TIFF", _  'Acceptable image extensions
                                                UCASE$(PATHNAME$(EXTN,wsFile))) > 0  THEN
                                        INCR lPic
                                        REDIM PRESERVE wsImages(1 TO lPic)
                                        wsImages(lPic) = wsFile
                                   ELSE
                                       ? TRIM$(COMMAND$(lArg)) & " does not have an acceptable image extension" & _
                                           $LF & $LF & _
                                           "Only drop .BMP, .GIF, .ICO, .JPG, .PNG, or .TIFF files",,"Print Images"
                                   END IF
                                   INCR lArg
                                WEND
                                IF lPic > 0 THEN
                                    Printimages wsImages()
                                ELSE
                                    ? "No images passed on command line",,"Print Images"
                                END IF
                            END FUNCTION
                            
                            FUNCTION PrintImages(wsFiles() AS WSTRING) AS LONG
                            LOCAL WIADlg AS ICommonDialog
                            LOCAL Vec AS IVector
                            LOCAL lCount AS LONG
                            LOCAL v AS VARIANT
                              WIADlg = NEWCOM "WIA.CommonDialog"
                              IF ISOBJECT(WIADlg) THEN
                                Vec = NEWCOM "WIA.Vector"
                                IF ISOBJECT(Vec) THEN
                                    FOR lCount = 1 TO UBOUND(wsFiles())
                                        Vec.add wsFiles(lCount)
                                    NEXT
                                    v = Vec
                                    WIADlg.ShowPhotoPrintingWizard v
                                    Vec = NOTHING
                                END IF
                                WIADlg = NOTHING
                              END IF
                            END FUNCTION
                            '
                            =========================
                            https://camcopng.com
                            =========================

                            Comment


                              #15
                              If you right click on an image file, or group of files, in Explorer you should see a "Print" option in the context menu. This brings up the photo printing wizard.
                              - LJ

                              Comment


                                #16
                                Originally posted by Laurence Jackson View Post
                                If you right click on an image file, or group of files, in Explorer you should see a "Print" option in the context menu. This brings up the photo printing wizard.
                                Doh! I've been using WIndows for over 30 years and I've never come across that one

                                Looks like I wasted some time there


                                =========================
                                https://camcopng.com
                                =========================

                                Comment


                                  #17
                                  Same here, I'm constantly learning new tricks. I can't say when that one first appeared, but it definitely wasn't there 30 years ago! 😂
                                  - LJ

                                  Comment


                                    #18
                                    Originally posted by Laurence Jackson View Post
                                    Same here, I'm constantly learning new tricks. I can't say when that one first appeared, but it definitely wasn't there 30 years ago! 😂
                                    The Windows Image Acquisition (WIA) Automation Layer is a high-quality, full-featured image manipulation component that provides end-to-end image processing capabilities for Microsoft Visual Basic 6.0, Active Server Pages (ASP), and scripting languages.

                                    The WIA Automation Layer exposes features in Windows XP Service Pack 1 (SP1) or later
                                    =========================
                                    https://camcopng.com
                                    =========================

                                    Comment

                                    Working...
                                    X
                                    😀
                                    🥰
                                    🤢
                                    😎
                                    😡
                                    👍
                                    👎