1. ## [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. 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) ;
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. 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?

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?

-

4. Are you trying to do something similar to this?

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

5. Originally Posted by TAZIN
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. Originally Posted by joaquim
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. 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. 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. Originally Posted by TAZIN
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. 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"

IDD_MYDLG  100

POPUP          "&Dialog"
BEGIN
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. Originally Posted by TAZIN
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"

IDD_MYDLG  100

POPUP          "&Dialog"
BEGIN
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. I'm sorry, but I don't understand your question.

13. Originally Posted by TAZIN
I'm sorry, but I don't understand your question.
instead a resource image, can i use an image file?

14. 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. Originally Posted by TAZIN
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