Announcement

Collapse
No announcement yet.

Insert image in a Button

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

  • Insert image in a Button

    I've always worked this way and it works:
    Code:
    #RESOURCE ICON,  114, "CONTADINO.ico"
    
    %IDC_BUTT_DIPE  = 1215
    
    CONTROL ADD BUTTON, hDlg, %IDC_BUTT_DIPE , "DIPENDENTI" ,155, 30, 50, 30,
    CONTROL SEND hDlg, %IDC_BUTT_DIPE , %BM_SETIMAGE, %Image_Icon, LOADICON( GETMODULEHANDLE( BYVAL %NULL ), "#"+"114" )

    but now with a special case I have some problem:
    Code:
    #RESOURCE ICON,  114, "CONTADINO.ico"
    
    %IDOK = 1
    %BS_DEFAULT = 1
    %IDC_BUTT_DIPE  = %IDOK
    
    CONTROL ADD BUTTON, hDlg, %IDC_BUTT_DIPE , "DIPENDENTI" ,155, 30, 50, 30,  %BS_DEFAULT
    CONTROL SEND hDlg, %IDC_BUTT_DIPE , %BM_SETIMAGE, %Image_Icon, LOADICON( GETMODULEHANDLE( BYVAL %NULL ), "#"+"114" )
    When I use a Button% BS_DEFAULT, the image is not displayed.

    If I use:
    Code:
    %IDOK = 1
    %BS_DEFAULT = 2
    I only see a small box similar to a Check Box before the description "DIPENDENTI".

    The Button works in any case.
    mailto:info@softplus.it
    From Italy.

  • #2
    %BS_DEFAULT should be "1". Style %BS_CHECKBOX=2 . In PBWin 10.xx %BS_DEFAULT is a built-in value. You're not getting compile time errors?

    Have you seen CONTROL ADD IMGBUTTON and CONTROL ADD IMGBUTTONX? I find IMGBUTTONX handy, it compensates for different screen settings & button sizes in units (vs. pixels).

    Cheers,
    Last edited by Dale Yarker; 13 Aug 2017, 06:42 AM.
    Dale

    Comment


    • #3
      Hi Giuseppe

      Try this program it has an image button, when click it launch the Internet URL, it uses IMGBUTTONX as Dale stated

      Btn Image.zip

      Comment


      • #4
        Try using %BS_ICON instead of %BS_DEFAULT
        Rgds, Dave

        Comment


        • #5
          To clarify, I can create the Button with the single image and the Button with image and text.
          Is in the case when I use the %BS_DEFAULT or the %BS_ICON option that the selected image is not displayed
          .
          mailto:info@softplus.it
          From Italy.

          Comment


          • #6
            In your post #1, in the second code box you said you were setting %BS_DEFAULT to 2. That is incorrect value for that style on a button.

            If that is not the case, please show more complete coding that demonstrates the problem.
            Dale

            Comment


            • #7
              Giuseppe,

              In you first post, you said that your code used to work but not now.
              I wonder if you were using themed controls before?
              Try this test code with and without a #Resource Manifest statement.
              Code:
              #Compile Exe                      ' PBWin10
              #Dim All
              #Include "WIN32API.INC"
              
               ' Un-comment the next line and re-compile for test
               '#RESOURCE MANIFEST, 1, "C:\PBWin10\samples\DDT\Address\XPTheme.xml"     ' set your path to files
              #RESOURCE Icon, 114, "C:\PBWin10\samples\DDT\treeview\icons\EARTH.ICO"    '      "        "
              
              %IDOK = 1
              %BS_DEFAULT = 1
              %IDC_BUTT_DIPE  = %IDOK
              '------------------/
              
              Function PBMain()
               Local hDlg  As Dword
              
                Dialog New 0, "Test", , , 300, 120, %WS_Caption Or %WS_SysMenu, To hDlg
              
                  CONTROL ADD BUTTON, hDlg, %IDC_BUTT_DIPE , "DIPENDENTI", 155, 10, 50, 30
                  CONTROL SEND hDlg, %IDC_BUTT_DIPE , %BM_SETIMAGE, %Image_Icon, LOADICON( GETMODULEHANDLE( BYVAL %NULL ), "#"+"114" )
              
                  CONTROL ADD BUTTON, hDlg, 200 , "%BS_ICON", 155, 45, 50, 30, %BS_ICON
                  CONTROL SEND hDlg, 200 , %BM_SETIMAGE, %Image_Icon, LOADICON( GETMODULEHANDLE( BYVAL %NULL ), "#"+"114" )
              
                  CONTROL ADD BUTTON, hDlg, 201 , "%BS_DEFAULT", 155, 80, 50, 30, %BS_DEFAULT
                  CONTROL SEND hDlg, 201 , %BM_SETIMAGE, %Image_Icon, LOADICON( GETMODULEHANDLE( BYVAL %NULL ), "#"+"114" )
              
                Dialog Show Modal hDlg
              End Function
              '------------------/PbMain
              Also. What are you trying to do by adding %BS_DEFAULT? Do you want to make this the 'default' button for your Dialog?

              As Dale suggested, a compilable example, that demonstrates your problem, could help us to help you
              Rgds, Dave

              Comment


              • #8
                Using window styles:
                • BS_BITMAP (optional message BM_SETIMAGE)
                • BS_ICON (optional message BM_SETIMAGE)
                • BS_OWNERDRAW (plus appropriate GDI drawing commands at drawing time)



                Using DDT proprietary things
                • CONTROL ADD IMGBUTTON
                • CONTROL ADD IMGBUTTONX




                Regardless of technique chosen:
                Michael Mattias
                Tal Systems Inc.
                Racine WI USA
                mmattias@talsystems.com
                http://www.talsystems.com

                Comment

                Working...
                X