Announcement

Collapse
No announcement yet.

Using ListView to load JPG/GIF - Updates?

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

  • Using ListView to load JPG/GIF - Updates?

    I ran into this code ... tested it and it seemed to work fine.

    http://www.powerbasic.com/support/pb...ad.php?t=24710

    Has anyone updated it to load the image into one of the graphic targets (Graphic Control, Memory Bitmap, or Graphic Window)?

    I was surprised to find so little mention of it. Seems like a very useful niche code - especially if the image can be moved to one of the graphic targets to make it available for other PowerBASIC actions.

    ... added later - here's another online link discussing the approach.
    http://www.codeguru.com/cpp/controls...cle.php/c12345
    Last edited by Gary Beene; 18 Jul 2009, 12:47 AM.

  • #2
    To use a ListView to load an image and later move it to a graphic control? A bit cumbersome, don't think you? Much easier to use GDI+.

    See this example in my forum:
    http://www.jose.it-berater.org/smffo...p?topic=1847.0

    The zipped file contains three examples, one using SDK code, another using DDT and another using a DDT graphic control:

    Code:
    ' ========================================================================================
    ' GdipDrawImage
    ' ========================================================================================
    
    ' SED_PBWIN
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "GDIPLUS.INC"
    
    %IDC_GRAPHIC  = 101
    
    ' ========================================================================================
    ' The following example draws an image with its upper-left corner at (10, 10).
    ' ========================================================================================
    SUB GDIP_DrawImage (BYVAL hdc AS DWORD)
    
       LOCAL hStatus AS LONG
       LOCAL pGraphics AS DWORD
       LOCAL pImage AS DWORD
       LOCAL strFileName AS STRING
    
       hStatus = GdipCreateFromHDC(hdc, pGraphics)
    
       ' // Create the Image object
       strFileName = UCODE$("climber.jpg")
       hStatus = GdipLoadImageFromFile(STRPTR(strFileName), pImage)
    
       ' // Draw the image
       hStatus = GdipDrawImage(pGraphics, pImage, 10, 10)
    
       ' // Cleanup
       IF pImage THEN GdipDisposeImage(pImage)
       IF pGraphics THEN GdipDeleteGraphics(pGraphics)
    
    END SUB
    ' ========================================================================================
    
    ' ========================================================================================
    ' Main
    ' ========================================================================================
    FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG
    
       LOCAL hr AS LONG
       LOCAL hDlg AS DWORD
       LOCAL hdc AS DWORD
       LOCAL token AS DWORD
       LOCAL StartupInput AS GdiplusStartupInput
    
       ' Initialize GDI+
       StartupInput.GdiplusVersion = 1
       hr = GdiplusStartup(token, StartupInput, BYVAL %NULL)
       IF hr THEN
          MSGBOX "Error initializing GDI+"
          EXIT FUNCTION
       END IF
    
       ' Create a new dialog
       DIALOG NEW PIXELS, 0, "GdipDrawImage", , , 420, 250, %WS_SYSMENU TO hDlg
    
       ' Add a graphic control
       CONTROL ADD GRAPHIC, hDlg, %IDC_GRAPHIC,"", 0, 0, 420, 250
       ' Select the drawing target
       GRAPHIC ATTACH hDlg, %IDC_GRAPHIC
       ' Set the foreground and background color
       GRAPHIC COLOR %BLACK, %WHITE
       ' Clear the entire selected graphic window
       GRAPHIC CLEAR
       ' Retrieve the handle of the device context
       GRAPHIC GET DC TO hdc
       ' Draw the graphics
       GDIP_DrawImage hdc
    
       DIALOG SHOW MODAL hDlg, CALL DlgProc
    
       ' Shutdown GDI+
       GdiplusShutdown token
    
    END FUNCTION
    ' ========================================================================================
    
    ' ========================================================================================
    ' Main Dialog procedure
    ' ========================================================================================
    CALLBACK FUNCTION DlgProc() AS LONG
    
       SELECT CASE CBMSG
    
          CASE %WM_COMMAND
             SELECT CASE CBCTL
                CASE %IDCANCEL
                   IF CBCTLMSG = %BN_CLICKED THEN DIALOG END CBHNDL, 0
             END SELECT
    
       END SELECT
    
    END FUNCTION
    ' ========================================================================================
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      Jose,
      Which win32api.inc do you use? Get duplicate equate messages.
      http://www.powerbasic.com/support/downloads/windows.htm (not current.)

      win32api.inc with the current compilers is dated Last Update: 26 January 2009
      The one in the powerbasic support forum is dated 2005. http://www.powerbasic.com/support/downloads/windows.htm (old)
      It might be nice for PowerBASIC to work with Jose on this.
      Last edited by Mike Doty; 18 Jul 2009, 09:45 AM.

      Comment


      • #4
        Mike,

        You should Jose's new WinAPI headers that he provides for free. Check out the latest version (1.14) available at http://www.jose.it-berater.org/smffo...hp?board=344.0

        Basically, you would install his includes into a separate folder and then point the compiler to that folder rather than the one that ships with the compiler (ie. the \WinAPI folder). Jose's includes are much more complete than the ones that ship with the compiler.
        Paul Squires
        FireFly Visual Designer (for PowerBASIC Windows 10+)
        Version 3 now available.
        http://www.planetsquires.com

        Comment


        • #5
          916 files and it worked immediately.
          Thank you!
          Last edited by Mike Doty; 18 Jul 2009, 01:16 PM.

          Comment


          • #6
            No problem Mike - happy that I could help. It boggles my mind the amount of work and effort that Jose has put into these new include files. It is an amazing work and all of Jose's new code is based on using these includes. The new includes have opened up a wide range of new technologies for PB'ers.
            Paul Squires
            FireFly Visual Designer (for PowerBASIC Windows 10+)
            Version 3 now available.
            http://www.planetsquires.com

            Comment


            • #7
              Thanks Jose,

              I'm having trouble finding the link to the gdiplus.inc.

              I see a Part1/2 in the Source Code forum, circa 2002.

              Is there a more recent version?

              I'll give your code a try! I've been wanting to step into the GDI+ arena and play, this will be a good time.

              Comment


              • #8
                I use my own include files, available in my forum. Please read the posts above.
                Forum: http://www.jose.it-berater.org/smfforum/index.php

                Comment


                • #9
                  Deleted.
                  Last edited by José Roca; 18 Jul 2009, 04:25 PM.
                  Forum: http://www.jose.it-berater.org/smfforum/index.php

                  Comment

                  Working...
                  X