Announcement

Collapse
No announcement yet.

loadin a external Bitmap 4 DDT use

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

  • loadin a external Bitmap 4 DDT use

    Hi, got a few questions:

    (1.) How can I load an external[not in the resource file] image
    [with LoadImage() ??] to display it in a dialog with the
    command CONTROL ADD IMAGE?
    (2.) Is it possible to set a dialog icon after the generation
    of a new dialog with the command DIALOG NEW?

    Hope to find some answers..

    -Uwe


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

  • #2
    Easiest is to have icons and bitmaps in resource file, but can do
    without too. Use %WM_SETICON message to set application's icon. Must
    remember to set both %ICON_BIG and %ICON_SMALL, so all parts of
    Windows has something to look on. Following little sample maybe can
    help show some of the ways to make an external bitmap "stick" to a
    control, plus show how to set icon:
    Code:
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' BITMAPS - TEMPLATE
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    DECLARE CALLBACK FUNCTION DlgProc() AS LONG
    %ID_LBLBMP = 20
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' MAIN ENTRANCE - CREATE DIALOG
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION PBMAIN () AS LONG
      LOCAL hDlg AS LONG
     
      DIALOG NEW 0, "Bitmap Template",,, 240, 120, _
                 %WS_CAPTION Or %WS_POPUP Or %WS_SYSMENU Or %DS_MODALFRAME TO hDlg
     
      DIALOG SEND hDlg, %WM_SETICON, %ICON_BIG, LoadIcon(0, BYVAL %IDI_APPLICATION)
      DIALOG SEND hDlg, %WM_SETICON, %ICON_SMALL, LoadIcon(0, BYVAL %IDI_APPLICATION)
     
      CONTROL ADD LABEL, hDlg, %ID_LBLBMP, "",  0, 0, 120, 120, %SS_SUNKEN
     
      DIALOG SHOW MODAL hDlg CALL DlgProc
     
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' MAIN DIALOG'S CALLBACK PROCEDURE
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION DlgProc() AS LONG
      SELECT CASE CBMSG
         CASE %WM_INITDIALOG
            STATIC hBmp AS LONG
            LOCAL hBmpDC AS LONG, rc AS RECT, bm AS BITMAP, zBmpFile AS ASCIIZ * %MAX_PATH
     
            GetWindowsDirectory zBmpFile, %MAX_PATH 'test with start-up logo
            zBmpFile = zBmpFile + "\logow.sys"      'whatever bmp file we want to show..
            IF LEN(DIR$(zBmpFile)) THEN
               hBmp = LoadImage(0, zBmpFile, %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE)
            END IF
     
         CASE %WM_CTLCOLORSTATIC 'if correct label and we have a bitmap handle
            IF CBLPARAM = GetDlgItem(CBHNDL, %ID_LBLBMP) AND hBmp THEN
               GetClientRect CBLPARAM, rc               'label's size
               GetObject hBmp, SIZEOF(bm), bm           'get bitmap's size
     
               hBmpDC = CreateCompatibleDC(CBWPARAM)    'create DC for bitmap
               SelectObject hBmpDC, hBmp                'select bitmap into DC, then paint it to label's dc
     
               StretchBlt CBWPARAM, 0, 0, rc.nRight, rc.nBottom, _
                            hBmpDC, 0, 0, bm.bmWidth, bm.bmHeight, %SRCCOPY  'stretched to control
     
              'BitBlt CBWPARAM, 0, 0, bm.bmWidth, bm.bmHeight, _
              '         hBmpDC, 0, 0, %SRCCOPY                               'if without stretch..
     
               DeleteDC hBmpDC                          'clean up temporary DC
               FUNCTION = GetStockObject(%HOLLOW_BRUSH) 'return a hollow brush
            END IF
     
         CASE %WM_DESTROY
            IF hBmp THEN DeleteObject hBmp             'clean-up time
     
         CASE %WM_COMMAND                              'NOTE: don't actually need a button, because
           IF CBCTL = %IDCANCEL THEN DIALOG END CBHNDL '      Windows sends %IDCANCEL also on Esc..
     
      END SELECT
     
    END FUNCTION

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

    Comment


    • #3
      Another way with less code than Borje's technique is to place just one icon in the resource file, and use CONTROL ADD IMAGE and specify that icon. Then you can use CONTROL SET IMAGE to change the image loaded with LoadIcon at a later time, say in %WM_INITDIALOG, etc.

      Note that if you are using bitmaps or icons loaded from a file with LoadImage() much be release or a memory leak will occur. When you need to change the image, use this technique:
      Code:
      CONTROL SEND CBHNDL, Id&, %STM_GETIMAGE, %IMAGE_BITMAP, 0 TO hBmp&
      CONTROL SET IMAGE hDlg&, Id&, NewImage$ 
      ' Or use CONTROL SEND..%STM_SETIMAGE for images loaded from disk
      DeleteObject hBmp&
      Change %IMAGE_BITMAP to %IMAGE_ICON for icons. Note that CONTROL SET IMAGE also requires that you replace the image with the same image type (bitmap for bitmap or icon for icon, etc).


      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Thanks 4 help!
        But I still got two little question:

        (1.) What's in CBWPARAM at command:
        "hBmpDC = CreateCompatibleDC(CBWPARAM)"
        ..in that way, how can I load the image out
        of a CALLBACK FUNCTION?

        (2.) I got a icon in a resource file like here:
        Code:
        // resource file
        #define HELLO 101
        HELLO ICON HELLO.ICO
        than I want 2 set the dialog icon in my basic program like this:
        Code:
        %icon_ID = 101
        
        DIALOG SEND hDlg, %WM_SETICON, %ICON_BIG, LoadIcon(0, BYVAL %icon_ID)  
        DIALOG SEND hDlg, %WM_SETICON, %ICON_SMALL, LoadIcon(0, BYVAL %icon_ID)
        But it doesn't work.. what's wrong?

        -Uwe


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

        Comment


        • #5
          You should use:
          Code:
          DIALOG SEND hDlg, %WM_SETICON, %ICON_BIG, LoadIcon(GetModuleHandle(ByVal %NULL), BYVAL %icon_ID)
          You should only use 0 if you use a Windows default system icon.


          ------------------
          Peter.
          mailto[email protected][email protected]</A>
          Regards,
          Peter

          Comment


          • #6
            (1.) What's in CBWPARAM at command:
            "hBmpDC = CreateCompatibleDC(CBWPARAM)"
            ..in that way, how can I load the image out
            of a CALLBACK FUNCTION?
            CBWPARAM in the context above, is the DC handle (hDC) of the static control. CBWPARAM is a DDT CALLBACK keyword, and is equivalent to the wParam& parameter of a SDK-style window or dialog procedure.

            Outside of a window/dialog procedure, you could use GetDC() to get the handle, and in this case, you'd also need to call ReleaseDC() when you no longer need it.

            ------------------
            Lance
            PowerBASIC Support
            mailto:[email protected][email protected]</A>
            Lance
            mailto:[email protected]

            Comment


            • #7
              Thank's... it work's!!! GREAT

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

              Comment


              • #8
                UPS... displayin a BMP out of a CALLBACK FUNCTION:
                (I modified the code above)

                I took Lance tip to display the BMP on Desktop
                -> that works!
                But than I tried 2 display it into the Label
                ->it did'nt work!

                see the followin code:
                Code:
                '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                ' BITMAPS - TEMPLATE   (there must be logow.sys in the WinDir)
                '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                #COMPILE EXE
                #INCLUDE "WIN32API.INC"
                
                %ID_LBLBMP = 20
                
                GLOBAL hDlg AS LONG
                
                DECLARE SUB displayBMP ()
                DECLARE CALLBACK FUNCTION DlgProc() AS LONG
                
                
                '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                ' MAIN ENTRANCE - CREATE DIALOG
                '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                FUNCTION PBMAIN () AS LONG
                
                  DIALOG NEW 0, "Bitmap Template",,, 240, 120, %WS_CAPTION OR %WS_POPUP OR %WS_SYSMENU OR %DS_MODALFRAME TO hDlg
                
                  CONTROL ADD LABEL, hDlg, %ID_LBLBMP, "",  0, 0, 100, 100, %SS_SUNKEN
                
                  CALL displayBMP ()
                
                  DIALOG SHOW MODAL hDlg
                
                END FUNCTION
                
                '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                ' MAIN DIALOG'S CALLBACK PROCEDURE
                '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                SUB displayBMP ()
                   STATIC hBmp    AS LONG
                   LOCAL hBmpDC   AS LONG
                   LOCAL lParam   AS LONG
                   LOCAL wParam   AS LONG
                   LOCAL rc       AS RECT
                   LOCAL bm       AS BITMAP
                   LOCAL zBmpFile AS ASCIIZ * %MAX_PATH
                
                   GetWindowsDirectory zBmpFile, %MAX_PATH 'test with start-up logo
                   zBmpFile = zBmpFile + "\logow.sys"      'whatever bmp file we want to show..
                   hBmp = LoadImage(0, zBmpFile, %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE)
                
                
                   lParam = GetDlgItem(hDlg, %ID_LBLBMP) 'or CONTROL HANDLE hMainDlg,%ID_LBLBMP TO hParam
                
                       '------------[here might be the error]----------------
                   wParam = GetDC(%HWND_DESKTOP) 'this works ->BMP is displayed on desktop
                   'wParam = GetDC(hDlg)           'this doesn't work ->should display BMP at the label
                       '-----------------------------------------------------
                
                   GetClientRect lParam, rc               'label's size
                   GetObject hBmp, SIZEOF(bm), bm           'get bitmap's size
                
                   hBmpDC = CreateCompatibleDC(wParam)    'create DC for bitmap
                   SelectObject hBmpDC, hBmp                'select bitmap into DC, then paint it to label's dc
                
                   StretchBlt wParam, 0, 0, rc.nRight, rc.nBottom, _
                                        hBmpDC, 0, 0, bm.bmWidth, bm.bmHeight, %SRCCOPY  'stretched to control
                
                   'BitBlt wParam, 0, 0, bm.bmWidth, bm.bmHeight, _
                   '         hBmpDC, 0, 0, %SRCCOPY                               'if without stretch..
                
                   ReleaseDC hDlg, wParam
                   DeleteDC hBmpDC                          'clean up temporary DC
                END SUB
                -Uwe

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

                Comment


                • #9
                  Uwe,

                  You should add %SS_BITMAP to label style to enable bitmap drawing.
                  Could also be a lot simpler to set image:
                  (LoadImage can directly resize image, or else use %LR_DEFAULTSIZE....)
                  Code:
                  '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                  ' BITMAPS - TEMPLATE   (there must be logow.sys in the WinDir)
                  '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                  #Compile Exe
                  #Include "WIN32API.INC"
                  
                  %ID_LBLBMP = 20
                  
                  Global hDlg As Long
                  Declare Sub displayBMP ()
                  Declare CallBack Function DlgProc() As Long
                   
                  '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                  ' MAIN ENTRANCE - CREATE DIALOG
                  '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                  Function PbMain () As Long
                    Dialog New 0, "Bitmap Template",,, 240, 120, %WS_CAPTION Or %WS_POPUP Or %WS_SYSMENU Or %DS_MODALFRAME To hDlg
                    Control Add Label, hDlg, %ID_LBLBMP, "",  0, 0, 100, 100, %SS_SUNKEN Or %SS_BITMAP
                    Call displayBMP ()
                    Dialog Show Modal hDlg
                  End Function
                  
                  '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                  ' MAIN DIALOG'S CALLBACK PROCEDURE
                  '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                  Sub displayBMP ()
                     Static hBmp    As Long
                     Local rc       As RECT
                     Local zBmpFile As Asciiz * %MAX_PATH
                  
                     GetWindowsDirectory zBmpFile, %MAX_PATH         'Test with start-up logo
                     zBmpFile = zBmpFile + "\logow.sys"              'whatever bmp file we want to show..
                     GetClientRect GetDlgItem(hDlg, %ID_LBLBMP), rc  'label's size
                     hBmp = LoadImage(0, zBmpFile, %IMAGE_BITMAP, rc.nRight-rc.nLeft,rc.nBottom-rc.nTop, %LR_LOADFROMFILE)
                     Control Send hDlg, %ID_LBLBMP, %STM_SETIMAGE, %IMAGE_BITMAP, hBmp
                  
                  End Sub
                  ------------------
                  Peter.
                  mailto[email protected][email protected]</A>

                  [This message has been edited by Peter Lameijn (edited October 10, 2001).]
                  Regards,
                  Peter

                  Comment

                  Working...
                  X