how can i build(for exemple) a checkbox with an image and text in same time?
Printable View
how can i build(for exemple) a checkbox with an image and text in same time?
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?
why the image isn't showed?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) ;
}
if i put the BS_ICON the image is showed... so the information isn't correct or i'm doing something wrong?
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?
-
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
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.
-
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....
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.,).
I also added a fuction to process the dialog box....Basically standard stuff.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;
In the resource file (.rc) I have the following to support the dialog box.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 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:#include "my.dlg"
ID_ICON2 ICON DISCARDABLE acrobat.ico
IDD_MYDLG 100
/* Menu pull downs */
POPUP "&Dialog"
BEGIN
MENUITEM "&DLG...", M_MYDLG
END
And the end result of all this stuff is this.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
http://i1293.photobucket.com/albums/...A7/DlgBox3.jpg
I'm sorry, but I don't understand your question.
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?