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

Retrieve Bitmap, RCData or String Resources from a DLL

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

  • PBWin Retrieve Bitmap, RCData or String Resources from a DLL

    Code:
    'Demonstration of retrieving Bitmap, RCData and String resources from a separate DLL
    'Huge thanks to Dave Biggs for the solution to getting a Bitmap into a PB command useable form!
    'S McLachlan Feb 2018
    
    '=======================Begin DLL Source =====================================
    #COMPILE DLL "DemoData.DLL"
    #DIM ALL
    #RESOURCE RCDATA, myData, "myRCData.txt"
    #RESOURCE STRING, 1, "This is a string!"
    #RESOURCE BITMAP, myBitmap, "myLogo.bmp"
    '========================End DLL Source ==========================================
    
    '=======================Begin EXE Source =========================================
    #COMPILER PBWIN 10
    #COMPILE EXE  "GetDLLData.exe"
    #DIM ALL
    #INCLUDE "win32api.inc"
    
    FUNCTION PBMAIN () AS LONG
        LOCAL hMod AS DWORD
    'For Bitmap
         LOCAL hcBmp, DC_BMP, hmBmp, hgDC AS DWORD
         LOCAL bmp AS BITMAP
         LOCAL hBmp, hGWin,hDlg AS DWORD
    ' For RCData
        LOCAL hFind, hLoc,hRes AS DWORD
        LOCAL lngResSize AS LONG
        LOCAL str AS STRING
    'For String
        LOCAL strz AS STRINGZ * 127
        LOCAL dptr AS DWORD
    
    'Load the DLL for a start
        hMod = loadlibrary ("DemoData.DLL")
        IF hMOd = 0 THEN ? "No module handle":EXIT FUNCTION
    '=============================================================================================================
    'Get BITMAP
        hBmp = LoadBitmap(hMod,"myBitmap")
        IF hBmp = 0 THEN  ? "Failed to load bitmap": EXIT FUNCTION
        GetObject hBmp, SIZEOF(Bmp), Bmp  'Load bitmap info into Bmp
    
    'Now you can EITHER:
    'Show Image in a Static Control (Label) using the API.
        DIALOG NEW PIXELS, 0, "Bitmap from DLL", ,, Bmp.bmWidth, Bmp.bmHeight, %WS_CAPTION OR %WS_SYSMENU TO hDlg
        CONTROL ADD LABEL,  hDlg, 1, "" ,0,0,0,0, %WS_CHILD OR %WS_VISIBLE OR %SS_BITMAP
        CONTROL SEND hDlg, 1, %STM_SETIMAGE, %IMAGE_BITMAP, hBmp
        DIALOG SHOW MODAL hDlg
    
    'OR
    'Convert resource to PB compatible Bitmap with PB handle to use with any PB Graphic commmands (Thanks, Dave Biggs)
          hcBmp = CopyImage(hBmp, %IMAGE_BITMAP, 0, 0, %LR_COPYRETURNORG) ' create working copy of resource bitmap
          DC_BMP = CreateCompatibleDC ( %NULL )                   ' create DC compatible with the screen (to hold bitmap)
          SelectObject ( DC_BMP, hcBmp )                          ' select bitmap into DC, making it available for use with API
          GRAPHIC BITMAP NEW bmp.bmWidth, bmp.bmHeight TO hmBmp   ' create graphic bitmap for PB Statements
          GRAPHIC ATTACH hmBmp, 0
          GRAPHIC GET DC TO hgDC                                  ' get DC of Graphic Window
          BitBlt ( hgDC, 0, 0, bmp.bmWidth, bmp.bmHeight, DC_BMP, 0, 0, %SRCCOPY ) 'DC_BMP is blitted to graphic window
          ReleaseDC hgDC, DC_BMP
          DeleteObject hcBmp
          DeleteObject hBmp
    
    'Now do something with the Bitmap
          GRAPHIC WINDOW NEW "Bitmap to Graphic Window",200,200,Bmp.bmWidth, Bmp.bmHeight TO hGWin
          GRAPHIC ATTACH hGWin, 0
          GRAPHIC COPY hmBmp, 0
          ? "Showing Graphic Window with bitmap"
          GRAPHIC WINDOW END
    
    '============================================================================================
    'GET RCDATA
        hFind  = FindResource (hMod,"myData", BYVAL %RT_RCDATA)
        IF hFind = 0 THEN ? "No Find handle":EXIT FUNCTION
        lngResSize = SizeOFResource(hMod,hFind)
        hRes = LoadResource(hMod,hFind)
        IF hRes = 0 THEN ? "Load failed":EXIT FUNCTION
        dptr = lockresource(hRes)
        IF dptr = 0 THEN ? "No Lock": EXIT FUNCTION
        str = PEEK$(dptr,lngResSize)
        ? "This as stored as a RCDATA: " & str
    '=============================================================================================
    'GET STRINGS
        lngresSize = LoadString(hMod,1,BYVAL VARPTR(strZ),127)
        ? "This was stored as STRING1: " & strZ
    END FUNCTION
    '=======================End EXE Source =====================================

    --
    [URL="http://www.camcopng.com"]CAMCo - Applications Development & ICT Consultancy[/URL][URL="http://www.hostingpng.com"]
    PNG Domain Hosting[/URL]
Working...
X