Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

20 Lines PB Code to Show GIF,JPEG or BMP Images.

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

    20 Lines PB Code to Show GIF,JPEG or BMP Images.

    This comes from "rv ListView Tips and Tricks" bag

    Tested on 2000 and Me.
    If it does not work, try update the common controls dll.
    If it stills not working, sorry...

    Code:
    #Include "win32api.inc"
    #Include "commctrl.inc"
     
    Function PBMain As Long
      Local hDlg As Dword
      Local lvbi As LVBKIMAGE
      Local szFile As Asciiz*%MAX_PATH
     
      InitCommonControls
      Dialog New 0,"Test JPG",,,550,380,%WS_OVERLAPPEDWINDOW  To hDlg
      Control Add "syslistview32",hDlg,1000,"",10,10,530,360, %WS_CHILD Or %WS_VISIBLE
     
      szFile = "D:\WINNT\Web\Wallpaper\Chateau.jpg"
      lvbi.ulFlags = %LVBKIF_STYLE_NORMAL Or %LVBKIF_SOURCE_URL
      lvbi.pszImage = VarPtr(szFile)
      lvbi.cchImageMax = Len(szFile)
      Control Send hDlg, 1000,  %LVM_SETBKIMAGE, 0, VarPtr(lvbi)
     
      Dialog Show Modal hDlg 
    End Function
    Regards,
    RValois.
    ------------------
    http://www.rvalois.com.br/downloads/free/



    [This message has been edited by Roberto Valois (edited June 18, 2004).]
    http://www.rvalois.com.br/downloads/free/

    #2
    Roberto,
    Works like a charm on XP Pro !!
    Also works with .bmp files (Just noticed that the title of your thread says so... ).

    Great example, thanks! Got any more of these?

    Kind regards


    ------------------
    Eddy
    email: raimundo4u at yahoo dot com
    www.devotechs.com -- HIME Huge Integer Math and Encryption library--

    [This message has been edited by Eddy Van Esch (edited June 18, 2004).]
    Eddy

    Comment


      #3
      Both BMP and JPEG work just ducky PB/Win 7.02 Win/98 Common Controls v 5.81

      Clever.

      NOTE FROM MSDN:
      Because the list-view control uses OLE COM to manipulate the background images, the calling application must call CoInitialize or OleInitialize before sending this message. It is best to call one of these functions when the application is initialized and call either CoUninitialize or OleUninitialize when the application is terminating.
      I think this means you need to call this explicitly if using compiler version < 7.0, which silently does this, needed or not.



      [This message has been edited by Michael Mattias (edited June 18, 2004).]
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


        #4
        Doesn't work for me !

        Using PB 6.1 on WinXP Home.


        ------------------
        Chris Boss
        Computer Workshop
        Developer of "EZGUI"
        http://ezgui.com
        Chris Boss
        Computer Workshop
        Developer of "EZGUI"
        http://cwsof.com
        http://twitter.com/EZGUIProGuy

        Comment


          #5
          Works great on Windows XP Pro using PB 7.04 )

          Thanks for the code!!!

          ------------------
          Robert

          Comment


            #6
            this source code is for pb 7 compilers.

            one probably notice it as it is inteded to be exe and lacks the
            #compile exe directive.

            discussion at: http://www.powerbasic.com/support/pb...ad.php?t=13535

            regards,
            rvalois.

            ------------------
            http://www.rvalois.com.br/downloads/free/
            http://www.rvalois.com.br/downloads/free/

            Comment


              #7
              Works like a charm for me Robert. Compiler 7.04, OS: Windows ME.

              Thanks very much for the code.

              David

              ------------------
              David Gwillim
              Noesis Corporation, NY

              noesisdg at optonline.net

              There are 10 kinds of people.
              Those who understand binary arithmetic
              and those who do not.


              [This message has been edited by David Gwillim (edited June 19, 2004).]
              David Gwillim
              Noesis Corporation, NY

              noesisdgatverizondotnet

              GAIA - the Mother of us all
              Isaac Asimov's Gaia

              Comment


                #8
                Hmmm, I thought the source code forum was for posting source
                code only.

                regards,
                Adam

                ------------------

                Comment


                  #9
                  Added scroll bar.
                  Tested on Me and 2000. PB 6.11 and PB 7.04
                  Code:
                  #Compile Exe
                   
                  #Include "win32api.inc"
                  #Include "commctrl.inc"
                   
                  Function PBMain As Long
                    Local hDlg As Dword
                    Local lvbi As LVBKIMAGE
                    Local szFile As Asciiz*%MAX_PATH
                    Local lvi As LVITEM
                    
                    InitCommonControls
                   
                    Call CoInitialize(ByVal 0)
                   
                    Dialog New 0,"Test JPG",,,340,260,%WS_OVERLAPPEDWINDOW  Or %WS_CLIPCHILDREN  To hDlg
                    Control Add "syslistview32",hDlg,1000,"",10,10,320,240, %WS_CHILD Or %WS_VISIBLE
                   
                    Control Send hDlg, 1000, %LVM_INSERTITEM, 0, VarPtr(lvi)
                    Control Send hDlg, 1000, %LVM_INSERTITEM, 0, VarPtr(lvi)
                    Control Send hDlg, 1000, %LVM_SETITEMPOSITION, 1, &H02000300
                   
                    szFile = "D:\WINNT\Web\Wallpaper\Chateau.jpg"
                    lvbi.ulFlags = %LVBKIF_STYLE_NORMAL Or %LVBKIF_SOURCE_URL
                   
                    lvbi.pszImage = VarPtr(szFile)
                    lvbi.cchImageMax = Len(szFile)
                    Control Send hDlg, 1000,  %LVM_SETBKIMAGE, 0, VarPtr(lvbi)
                   
                    Dialog Show Modal hDlg
                   
                    Call CoUnInitialize()
                   
                  End Function

                  ------------------
                  http://www.rvalois.com.br/downloads/free/
                  http://www.rvalois.com.br/downloads/free/

                  Comment


                    #10
                    Added resizing of LV if dialog resizes.

                    Code:
                    #Compile Exe
                    
                    #Include "win32api.inc"
                    #Include "commctrl.inc"
                    
                    
                    CallBack Function DlgCallBack()
                             Local nWidth As Long
                             Local nHight As Long
                             Local hWnd As Dword
                    
                             If CbMsg = %WM_SIZE Then
                                Control Handle CbHndl ,1000 To hWnd
                                MoveWindow hWnd ,0,0,LoWrd(CbLParam),HiWrd(CbLParam),1
                             End If
                    End Function
                    
                    Function PBMain As Long
                      Local hDlg As Dword
                      Local lvbi As LVBKIMAGE
                      Local szFile As Asciiz*%MAX_PATH
                      Local lvi As LVITEM
                    
                    
                      InitCommonControls
                    
                      Call CoInitialize(ByVal 0)
                    
                      Dialog New 0,"Test JPG",,,340,260,%WS_OVERLAPPEDWINDOW  Or %WS_CLIPCHILDREN  To hDlg
                      Control Add "syslistview32",hDlg,1000,"",10,10,320,240, %WS_CHILD Or %WS_VISIBLE
                    
                    
                      Control Send hDlg, 1000, %LVM_INSERTITEM, 0, VarPtr(lvi)
                      Control Send hDlg, 1000, %LVM_INSERTITEM, 0, VarPtr(lvi)
                      Control Send hDlg, 1000, %LVM_SETITEMPOSITION, 1,&H02000300
                    
                    
                      szFile = "D:\WINNT\Web\Wallpaper\Chateau.jpg"
                    
                      lvbi.ulFlags = %LVBKIF_STYLE_NORMAL Or %LVBKIF_SOURCE_URL
                    
                      lvbi.pszImage = VarPtr(szFile)
                      lvbi.cchImageMax = Len(szFile)
                      Control Send hDlg, 1000,  %LVM_SETBKIMAGE, 0, VarPtr(lvbi)
                    
                      Dialog Show Modal hDlg ,Call DlgCallBack
                    
                      Call CoUnInitialize()
                    
                    End Function
                    ------------------
                    Byte Hunters of the World Unite.
                    Byte Hunters of the World Unite.

                    Comment


                      #11
                      now with drag and drop of even multiple files by dean schrage!
                      keeps getting better. now if only on a pbform or ezgui dialog!
                      http://www.powerbasic.com/support/pb...ad.php?t=24274

                      ------------------

                      Comment


                        #12
                        Bottom of image may be truncated unless run maximized.

                        ------------------

                        Comment


                          #13
                          Strange !

                          The code works fine when compiling with PB 8.0.
                          It does not display the image when compiling with PB 6.1 though !

                          I checked the include file constants/structures used and they are the same
                          in both versions.

                          Why does PB 6.1 not work while PB 8.0 does ?


                          ------------------
                          Chris Boss
                          Computer Workshop
                          Developer of "EZGUI"
                          http://ezgui.com
                          Chris Boss
                          Computer Workshop
                          Developer of "EZGUI"
                          http://cwsof.com
                          http://twitter.com/EZGUIProGuy

                          Comment


                            #14
                            You win one (1) RTFM, too. from LVM_SETBKIMAGE doc:

                            Remarks

                            Because the list-view control uses OLE COM to manipulate the background images, the calling application must call CoInitialize or OleInitialize before sending this message. It is best to call one of these functions when the application is initialized and call either CoUninitialize or OleUninitialize when the application is terminating.
                            No, cancel that RTFM. Give it to PowerBASIC instead, since they are the ones who never documented how they call CoInitializeEx (needed or not) in PB/WIN 7+

                            Michael Mattias
                            Tal Systems (retired)
                            Port Washington WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                              #15
                              Code:
                              Eliminates truncation
                              Control Send hDlg, 1000, %LVM_SETITEMPOSITION, 1,&H03000300
                              ------------------

                              Comment


                                #16
                                http://www.powerbasic.com/support/pb...ad.php?t=13535


                                ------------------
                                http://www.rvalois.com.br/downloads/free/
                                http://www.rvalois.com.br/downloads/free/

                                Comment


                                  #17
                                  Resize Image

                                  Is there a way to define the size of the image to display?

                                  Comment


                                    #18
                                    Michael,
                                    I think this means you need to call this explicitly if using compiler version < 7.0, which silently does this, needed or not.
                                    does this mean that in your opinion, pbwin >=7.0 need not use coinitialize/conunitialize or OLEinitialize/OLEunitialize in this example ? or is it just a good idea to do it anyway
                                    Client Writeup for the CPA

                                    buffs.proboards2.com

                                    Links Page

                                    Comment


                                      #19
                                      Current PB compilers call CoInitialize and CoUninitialize for the main thread. They don't call OleInitialize/OleUninitialize, so you need to call them if you need the additional functionality that they provide.
                                      Forum: http://www.jose.it-berater.org/smfforum/index.php

                                      Comment


                                        #20
                                        does this mean that in your opinion, pbwin >=7.0 need not use coinitialize/conunitialize or OLEinitialize/OLEunitialize in this example ? or is it just a good idea to do it anyway
                                        It cannot hurt to do it in code, ever.
                                        Michael Mattias
                                        Tal Systems (retired)
                                        Port Washington WI USA
                                        [email protected]
                                        http://www.talsystems.com

                                        Comment

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