[win32] - about child controls with text and image

This is a discussion on [win32] - about child controls with text and image within the Windows Programming forums, part of the Platform Specific Boards category; how can i build(for exemple) a checkbox with an image and text in same time?...

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    137

    [win32] - about child controls with text and image

    how can i build(for exemple) a checkbox with an image and text in same time?

  2. #2
    Registered User
    Join Date
    Aug 2013
    Posts
    137
    these link tell me that i can show text and image in same time:
    msdn.microsoft.com/en-us/library/windows/desktop/bb775951(v=vs.85).aspx

    in Remarks section:

    The appearance of text or an icon or both on a button control depends on the BS_ICON and BS_BITMAP styles, and whether the BM_SETIMAGE message is sent. The possible results are as follows.

    BS_ICON or BS_BITMAP set? BM_SETIMAGE called? Result
    Yes Yes Show icon only.
    No Yes Show icon and text.
    Yes No Show text only.
    No No Show text only

    so what isn't right with these code?

    Code:
    LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
    {
        static HWND HandleButton;
        static HICON HandleIcon;
    
        switch (iMsg)
        {
            case WM_DESTROY:
                DestroyIcon(HandleIcon);
                PostQuitMessage (0) ;
                return 0 ;
            case WM_SHOWWINDOW:
                HandleButton=CreateWindow (TEXT("button"), TEXT ("hello"),
                WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON | BS_TEXT ,
                100, 100,500, 200,hwnd, NULL, (HINSTANCE)GetModuleHandle(NULL), NULL) ;
                HandleIcon=(HICON)LoadImage(NULL,"c:\\acrobat.ico",IMAGE_ICON,LR_DEFAULTSIZE,LR_DEFAULTSIZE,LR_LOADFROMFILE);
                SendMessage(HandleButton, BM_SETIMAGE,(WPARAM) IMAGE_ICON,(LPARAM)HandleIcon );
                return 0;
        }
        return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
    }
    why the image isn't showed?
    if i put the BS_ICON the image is showed... so the information isn't correct or i'm doing something wrong?

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    419
    It's possible that the truth table shown is wrong.

    Have you tried all four combinations to see exactly what happens?

    BS_ICON set ------ BM_SETIMAGE sent
    BS_ICON not set ------ BM_SETIMAGE sent
    BS_ICON set ------ BM_SETIMAGE not sent
    BS_ICON not set ----- BM_SETIMAGE not sent

    What results do you get for those four conditions?

    edited to add this:

    Is it possible that the text is writing over the icon image?
    Are the text and icon trying to occupy the same area of the button?

    -
    Last edited by megafiddle; 05-22-2014 at 05:29 PM.

  4. #4
    Registered User
    Join Date
    Jun 2009
    Posts
    87
    Are you trying to do something similar to this?

    http://i1293.photobucket.com/albums/...CA7/DlgBox.jpg

  5. #5
    Registered User
    Join Date
    Aug 2013
    Posts
    137
    Quote Originally Posted by TAZIN View Post
    Are you trying to do something similar to this?

    http://i1293.photobucket.com/albums/...CA7/DlgBox.jpg
    show a button with text and image(icon).

    megafiddle: the image isn't showed with that code... but if i use the BS_ICON style, the image is showed, but not the text
    the image\text are showed in center of button(i don't know why).
    i need show the text with image

  6. #6
    Registered User
    Join Date
    Mar 2011
    Posts
    419
    Quote Originally Posted by joaquim View Post
    show a button with text and image(icon).

    megafiddle: the image isn't showed with that code... but if i use the BS_ICON style, the image is showed, but not the text
    the image\text are showed in center of button(i don't know why).
    i need show the text with image
    The BS_TEXT style places the text in the center, I believe.
    Try using a BS_TOP or BS_BOTTOM style to locate the text.

    -

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    419
    I tried running your code. I got the same results using Pelles C on an XP computer.
    I can get text or icon, but not both.

    Others have had the same problem:

    [Solved] How can I create button showing icon and text using BS_ICON and sending BM_SETIMAGE? - CodeProject

    The problem is apparently related to certain operating systems (eg XP) and/or the compiler.

    The styles like BS_BOTTOM and BS_TOP also seem to affect both text and images. So I'm not
    sure how we are supposed to control the locations of each independantly, even when it does work.

    -

  8. #8
    Registered User
    Join Date
    Jun 2009
    Posts
    87
    So, you want to have text and an image on a button...Kinda like this?

    http://i1293.photobucket.com/albums/...A7/DlgBox2.jpg

    If so, then you might want to try it the old fashion via a dialog file like I did it....

  9. #9
    Registered User
    Join Date
    Aug 2013
    Posts
    137
    Quote Originally Posted by TAZIN View Post
    So, you want to have text and an image on a button...Kinda like this?

    http://i1293.photobucket.com/albums/...A7/DlgBox2.jpg

    If so, then you might want to try it the old fashion via a dialog file like I did it....
    yes... like that... can you show me your code just for add the image to button?

  10. #10
    Registered User
    Join Date
    Jun 2009
    Posts
    87
    Here's an example of the old fashion way I did the dialog box. Also, I call the dialog box by way of a pull down menu item. In my command function I added the following:
    Note: this is where all the other pull down menu items are (i.e. Save, SaveAs, Copy, Paste, etc.,).

    Code:
    DLGPROC dlgprc;    /* pointer to MyDlgProc */
    
    case M_MYDLG:
           if (dlgprc = (DLGPROC)MakeProcInstance(MyDlgProc, hInstance))
              {
                  DialogBoxParam(hInstance, (LPTSTR)MAKEINTRESOURCE(IDD_MYDLG), hwnd, dlgprc, 0);
                  FreeProcInstance((FARPROC) dlgprc);
              }
              break;
    I also added a fuction to process the dialog box....Basically standard stuff.

    Code:
    BOOL WINAPI MyDlgProc (
             HWND    hwnd,
             UINT    msg,
             WPARAM  wParam,
             LONG    lParam)
    {
        switch (msg)
        {
            case WM_INITDIALOG:
                   break;
    
            case WM_COMMAND:
                   switch (wParam)
                   {
                       case IDOK:
                              EndDialog(hwnd, 0);
                              break;
    
                       default:
                              return (FALSE);
                   }
                   break;
    
            default:
                   return (FALSE);
    
        }
        return (TRUE);
    }
    In the resource file (.rc) I have the following to support the dialog box.
    Code:
    #include "my.dlg"
    
    ID_ICON2 ICON DISCARDABLE    acrobat.ico
    
    IDD_MYDLG  100
    
    /* Menu pull downs */
        POPUP          "&Dialog"
        BEGIN
            MENUITEM   "&DLG...",   M_MYDLG
        END
    In a separate dialog file (my.dlg) I have the following to create the parameters of the dialog box. I could have put this info in the resource file if I wanted to.
    Code:
    IDD_MYDLG DIALOG LOADONCALL MOVEABLE DISCARDABLE 62, 54, 100, 100
    STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
    CAPTION "MyDlg"
    FONT 8, "MS Sans Serif"
    BEGIN
            PUSHBUTTON      "Hello", IDOK, 16, 20, 65, 63
            CONTROL         "\002", -1, "static", SS_ICON | WS_CHILD, 39, 25, 18, 20
    END
    And the end result of all this stuff is this.

    http://i1293.photobucket.com/albums/...A7/DlgBox3.jpg

  11. #11
    Registered User
    Join Date
    Aug 2013
    Posts
    137
    Quote Originally Posted by TAZIN View Post
    Here's an example of the old fashion way I did the dialog box. Also, I call the dialog box by way of a pull down menu item. In my command function I added the following:
    Note: this is where all the other pull down menu items are (i.e. Save, SaveAs, Copy, Paste, etc.,).

    Code:
    DLGPROC dlgprc;    /* pointer to MyDlgProc */
    
    case M_MYDLG:
           if (dlgprc = (DLGPROC)MakeProcInstance(MyDlgProc, hInstance))
              {
                  DialogBoxParam(hInstance, (LPTSTR)MAKEINTRESOURCE(IDD_MYDLG), hwnd, dlgprc, 0);
                  FreeProcInstance((FARPROC) dlgprc);
              }
              break;
    I also added a fuction to process the dialog box....Basically standard stuff.

    Code:
    BOOL WINAPI MyDlgProc (
             HWND    hwnd,
             UINT    msg,
             WPARAM  wParam,
             LONG    lParam)
    {
        switch (msg)
        {
            case WM_INITDIALOG:
                   break;
    
            case WM_COMMAND:
                   switch (wParam)
                   {
                       case IDOK:
                              EndDialog(hwnd, 0);
                              break;
    
                       default:
                              return (FALSE);
                   }
                   break;
    
            default:
                   return (FALSE);
    
        }
        return (TRUE);
    }
    In the resource file (.rc) I have the following to support the dialog box.
    Code:
    #include "my.dlg"
    
    ID_ICON2 ICON DISCARDABLE    acrobat.ico
    
    IDD_MYDLG  100
    
    /* Menu pull downs */
        POPUP          "&Dialog"
        BEGIN
            MENUITEM   "&DLG...",   M_MYDLG
        END
    In a separate dialog file (my.dlg) I have the following to create the parameters of the dialog box. I could have put this info in the resource file if I wanted to.
    Code:
    IDD_MYDLG DIALOG LOADONCALL MOVEABLE DISCARDABLE 62, 54, 100, 100
    STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
    CAPTION "MyDlg"
    FONT 8, "MS Sans Serif"
    BEGIN
            PUSHBUTTON      "Hello", IDOK, 16, 20, 65, 63
            CONTROL         "\002", -1, "static", SS_ICON | WS_CHILD, 39, 25, 18, 20
    END
    And the end result of all this stuff is this.

    http://i1293.photobucket.com/albums/...A7/DlgBox3.jpg
    i'm sorry, you use a resource file for that. can i use a file name too?

  12. #12
    Registered User
    Join Date
    Jun 2009
    Posts
    87
    I'm sorry, but I don't understand your question.

  13. #13
    Registered User
    Join Date
    Aug 2013
    Posts
    137
    Quote Originally Posted by TAZIN View Post
    I'm sorry, but I don't understand your question.
    instead a resource image, can i use an image file?

  14. #14
    Registered User
    Join Date
    Jun 2009
    Posts
    87
    Good question....With my limited knowledge of programming I'd have to say no. I don't think you can call an external reference (such as an image file) when it comes to this type of programming. I believe the image has to be compiled with the source code. Again, a more advanced programmer might have a better idea as to what you can and cannot do.
    BTW, why is it a problem to incorporate a resource file with your project?

  15. #15
    Registered User
    Join Date
    Aug 2013
    Posts
    137
    Quote Originally Posted by TAZIN View Post
    Good question....With my limited knowledge of programming I'd have to say no. I don't think you can call an external reference (such as an image file) when it comes to this type of programming. I believe the image has to be compiled with the source code. Again, a more advanced programmer might have a better idea as to what you can and cannot do.
    BTW, why is it a problem to incorporate a resource file with your project?
    yes... you have right... it's better not share the images for a standard project
    i must use more resources and understand more about them
    thanks for all

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Child Window Text/Buttons Missing [WIN32 API/C++/VS 2010]
    By William Putnam in forum Windows Programming
    Replies: 3
    Last Post: 07-22-2013, 09:53 PM
  2. Child Window Text/Buttons Missing [WIN32 API/C++/VS 2010]
    By William Putnam in forum C++ Programming
    Replies: 0
    Last Post: 07-22-2013, 11:47 AM
  3. Tab Orders (Child Controls)
    By (TNT) in forum Windows Programming
    Replies: 6
    Last Post: 07-14-2006, 07:11 AM
  4. Method of placing child window controls
    By Garfield in forum Windows Programming
    Replies: 4
    Last Post: 01-13-2002, 10:09 PM
  5. Child window controls & fonts
    By chomper in forum Windows Programming
    Replies: 0
    Last Post: 10-03-2001, 05:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21