Hi i want to get in a button a icon.
What i have to do ? - It is easy to realize ? - Perhaps its only a question of an resource option...
What i have to do ? - It is easy to realize ? - Perhaps its only a question of an resource option...
Create the button with a BS_ICON or BS_BITMAP style then use the BM_SETIMAGE message to add the bitmap or icon.
Unfortunetely the rc.exe doesn't know the keyword "BS_BITMAP".
To set the Icon, I tryed this:
add eax,offset BUTTONIMAGE
mov eax,
INVOKE SendDlgItemMessage, hDlg, IDC_BUTTON3,BM_SETIMAGE, BUTTONIMAGE, EAX
Who to eliminate the resourcen error ?
To set the Icon, I tryed this:
add eax,offset BUTTONIMAGE
mov eax,
INVOKE SendDlgItemMessage, hDlg, IDC_BUTTON3,BM_SETIMAGE, BUTTONIMAGE, EAX
Who to eliminate the resourcen error ?
BS_BITMAP is a style, not a Keyword, it is used as follows :
PUSHBUTTON "ON", 7, 10, 10, 20, 10, BS_BITMAP
PUSHBUTTON text, id, x, y, width, height , style , extended-style
If it still doesn't work check your resource header file or add the line
#include "\masm32\include\resource.h"
to the top of the file.
Donkey
PUSHBUTTON "ON", 7, 10, 10, 20, 10, BS_BITMAP
PUSHBUTTON text, id, x, y, width, height , style , extended-style
If it still doesn't work check your resource header file or add the line
#include "\masm32\include\resource.h"
to the top of the file.
Donkey
Hi, first i tryed to include the resource file from C++.
But now it works !
But the icon isnt visible :mad:
But now it works !
But the icon isnt visible :mad:
the proper way to use BM_SETIMAGE is like this:
invoke SendMessage, hButton, BM_SETIMAGE, IMAGE_ICON, BUTTONIMAGE
or
INVOKE SendDlgItemMessage, hDlg, IDC_BUTTON3, BM_SETIMAGE, IMAGE_ICON, BUTTONIMAGE
You have been sending the handle in the wrong param and not specifying what type of image it is.
Also forget about dereferencing the variable. The way you're doing it will lead to big problems and it isn't needed just pass the BUTTONIMAGE variable directly and delete the following lines:
add eax,OFFSET BUTTONIMAGE
mov eax,
invoke SendMessage, hButton, BM_SETIMAGE, IMAGE_ICON, BUTTONIMAGE
or
INVOKE SendDlgItemMessage, hDlg, IDC_BUTTON3, BM_SETIMAGE, IMAGE_ICON, BUTTONIMAGE
You have been sending the handle in the wrong param and not specifying what type of image it is.
Also forget about dereferencing the variable. The way you're doing it will lead to big problems and it isn't needed just pass the BUTTONIMAGE variable directly and delete the following lines:
add eax,OFFSET BUTTONIMAGE
mov eax,
BUTTONIMAGE EQU ....
hMyButton DWORD ?
... == INITDIALOG
mov eax,hDlg
mov hDlg,eax
invoke GetDlgItem,hDlg, BUTTONIMAGE
mov hMyButton,eax
invoke SendMessage, hMyButton, BM_SETIMAGE, IMAGE_ICON, BUTTONIMAGE
but this doesnt work.
:( :(
hMyButton DWORD ?
... == INITDIALOG
mov eax,hDlg
mov hDlg,eax
invoke GetDlgItem,hDlg, BUTTONIMAGE
mov hMyButton,eax
invoke SendMessage, hMyButton, BM_SETIMAGE, IMAGE_ICON, BUTTONIMAGE
but this doesnt work.
:( :(
BUTTONIMAGE EQU ....
hMyButton DWORD ?
... == INITDIALOG
mov eax,hDlg
mov hDlg,eax
invoke GetDlgItem,hDlg, BUTTONIMAGE
mov hMyButton,eax
invoke SendMessage, hMyButton, BM_SETIMAGE, IMAGE_ICON, BUTTONIMAGE
You are not loading an image any where, BUTTONIMAGE does what ? It is just the ID to the button in the example that you gave not a handle to the image.
EDIT be sure to use DestroyIcon to delete the icon when you no longer need it. Not while it is still on the button but when you exit your program.
hMyButton DWORD ?
... == INITDIALOG
mov eax,hDlg
mov hDlg,eax
invoke GetDlgItem,hDlg, BUTTONIMAGE
mov hMyButton,eax
invoke SendMessage, hMyButton, BM_SETIMAGE, IMAGE_ICON, BUTTONIMAGE
You are not loading an image any where, BUTTONIMAGE does what ? It is just the ID to the button in the example that you gave not a handle to the image.
hButtonIcon DWORD ?
hDlg DWORD ?
hMyButton DWORD ?
.IF uMsg == INITDIALOG
mov eax,hWnd
mov hDlg,eax
invoke GetDlgItem,hDlg,IDC_BUTTON3
mov hMyButton,eax
invoke LoadImage, hInstance, BUTTONIMAGE, IMAGE_ICON, 16, 16, NULL
mov hButtonIcon,eax
invoke SendMessage, hMyButton, BM_SETIMAGE, IMAGE_ICON, hButtonIcon
BUTTONIMAGE is the ID number of the icon in your resource file and IDC_BUTTON3 is the ID of the button.
EDIT be sure to use DestroyIcon to delete the icon when you no longer need it. Not while it is still on the button but when you exit your program.
hmm, it still doesnt work - im very sorry !
hICON DWORD ?
hMyButton DWORD ?
..EQU ...
..EQU ...
.IF uMsg == INITDIALOG
mov eax,hDlg
mov hDlg,eax
invoke GetDlgItem,hDlg, IDC_BUTTON3
mov hMyButton,eax
invoke LoadImage, hDlg, BUTTONIMAGE, IMAGE_ICON, 16, 16, NULL
mov hICON,eax
INVOKE SendMessage, hMyButton, BM_SETIMAGE, IMAGE_ICON, BUTTONIMAGE
nothin happens
:rolleyes: :mad: :( :mad:
P.S. Thanks for yout intensive helping donkey !
hICON DWORD ?
hMyButton DWORD ?
..EQU ...
..EQU ...
.IF uMsg == INITDIALOG
mov eax,hDlg
mov hDlg,eax
invoke GetDlgItem,hDlg, IDC_BUTTON3
mov hMyButton,eax
invoke LoadImage, hDlg, BUTTONIMAGE, IMAGE_ICON, 16, 16, NULL
mov hICON,eax
INVOKE SendMessage, hMyButton, BM_SETIMAGE, IMAGE_ICON, BUTTONIMAGE
nothin happens
:rolleyes: :mad: :( :mad:
P.S. Thanks for yout intensive helping donkey !
invoke LoadImage, hDlg, BUTTONIMAGE, IMAGE_ICON, 16, 16, NULL
should be
invoke LoadImage, hInstance, BUTTONIMAGE, IMAGE_ICON, 16, 16, NULL
Use the instance handle to indicate where LoadImage is supposed to get the icon from. hInstance indicates that the icon can be found in your applications resource section.
EDIT: Also you have just passed the icon ID to the BM_SETIMAGE again pass the handle to the icon !
should be
invoke LoadImage, hInstance, BUTTONIMAGE, IMAGE_ICON, 16, 16, NULL
Use the instance handle to indicate where LoadImage is supposed to get the icon from. hInstance indicates that the icon can be found in your applications resource section.
EDIT: Also you have just passed the icon ID to the BM_SETIMAGE again pass the handle to the icon !
hm, its doesnt work ! Although even the icon have 16*16 pixels.
:eek: :eek: :eek: :eek: :eek: :stupid:
:eek: :eek: :eek: :eek: :eek: :stupid:
hICON DWORD ?
hMyButton DWORD ?
..EQU ...
..EQU ...
.IF uMsg == INITDIALOG
mov eax,hDlg
mov hDlg,eax
invoke GetDlgItem,hDlg, IDC_BUTTON3
mov hMyButton,eax
invoke LoadImage, hInstance, BUTTONIMAGE, IMAGE_ICON, 16, 16, NULL
mov hICON,eax
INVOKE SendMessage, hMyButton, BM_SETIMAGE, IMAGE_ICON, hICON
hMyButton DWORD ?
..EQU ...
..EQU ...
.IF uMsg == INITDIALOG
mov eax,hDlg
mov hDlg,eax
invoke GetDlgItem,hDlg, IDC_BUTTON3
mov hMyButton,eax
invoke LoadImage, hInstance, BUTTONIMAGE, IMAGE_ICON, 16, 16, NULL
mov hICON,eax
INVOKE SendMessage, hMyButton, BM_SETIMAGE, IMAGE_ICON, hICON
Is the Icon in a file or in your resource section ? What is it's ID number and what is the ID number of the button.
Everything is defined as well.
I made a test. I tryed to hide the window on buttonclick(IDC_BUTTON3) and it works. But after that i tryed to make that with the button, but that doesnt work. Sp something have to be with the buttonhandle. Perhas getDlgitem is not a good solution. There is a funktion calld getResource or so, isn't there ?
ARGGGGGG ! :confused: :(
I made a test. I tryed to hide the window on buttonclick(IDC_BUTTON3) and it works. But after that i tryed to make that with the button, but that doesnt work. Sp something have to be with the buttonhandle. Perhas getDlgitem is not a good solution. There is a funktion calld getResource or so, isn't there ?
ARGGGGGG ! :confused: :(
Hi Red,
The GetDlgItem function is only there to retrieve the handle to the button so that you can send a message to it. It doesn't do anything else but the job it does is critical. You can alternately use SendDlgItemMessage function to send the message without the button handle. The LoadImage function will retrieve a handle to a bitmap or icon in the resource section of your code, YOU MUST PASS THIS HANDLE TO THE BUTTON, nothing else will do. This is a very simple task that is done every day. In your RC file make sure that the style of the button is set to the image type you want to display on it (BS_BITMAP,BS_ICON) it must be one or the other, both won't work. Then use GetDlgItem to retrieve the handle of the button and LoadImage to retrieve the handle of the Icon or bitmap resource. Once you have these two handles use the BM_SETIMAGE message to place the image on your button. That's all there is to it, nothing difficult.
I think you are having trouble understanding some basic concepts in Win32 programming. I would suggest that you check the example code with MASM32 and maybe get a copy of win32api.hlp. Have you ever done any programming in any language before ? If not get a primer or check some of the following web pages that discuss the basics of Win32 programming and the concepts involved.
http://spiff.tripnet.se/~iczelion/
http://www.eskimo.com/%7Ehtak/win32asm/win32asm.htm
http://webster.cs.ucr.edu/
http://www.madwizard.org/view.php?page=tutorials.contents
Donkey
The GetDlgItem function is only there to retrieve the handle to the button so that you can send a message to it. It doesn't do anything else but the job it does is critical. You can alternately use SendDlgItemMessage function to send the message without the button handle. The LoadImage function will retrieve a handle to a bitmap or icon in the resource section of your code, YOU MUST PASS THIS HANDLE TO THE BUTTON, nothing else will do. This is a very simple task that is done every day. In your RC file make sure that the style of the button is set to the image type you want to display on it (BS_BITMAP,BS_ICON) it must be one or the other, both won't work. Then use GetDlgItem to retrieve the handle of the button and LoadImage to retrieve the handle of the Icon or bitmap resource. Once you have these two handles use the BM_SETIMAGE message to place the image on your button. That's all there is to it, nothing difficult.
I think you are having trouble understanding some basic concepts in Win32 programming. I would suggest that you check the example code with MASM32 and maybe get a copy of win32api.hlp. Have you ever done any programming in any language before ? If not get a primer or check some of the following web pages that discuss the basics of Win32 programming and the concepts involved.
http://spiff.tripnet.se/~iczelion/
http://www.eskimo.com/%7Ehtak/win32asm/win32asm.htm
http://webster.cs.ucr.edu/
http://www.madwizard.org/view.php?page=tutorials.contents
Donkey
Thanks for your tips !
Im programming in C++ also.
But to come back ti my problem:
I checked, whether the button has the same Id, such the EQU declared in .const.
I think, the problem is the folowing codesniped:
mov eax,hDlg
mov hDlg,eax
invoke GetDlgItem,hDlg, IDC_BUTTON3
mov hMyButton,eax
Because if I want to hide the button (hMyButton), the button doesnt disapear.
:stupid:
Perhaps the mistake is here ?:
PUSHBUTTON "",IDC_BUTTON3, 210, 48,20,15, BS_BITMAP | BS_ICON
Im programming in C++ also.
But to come back ti my problem:
I checked, whether the button has the same Id, such the EQU declared in .const.
I think, the problem is the folowing codesniped:
mov eax,hDlg
mov hDlg,eax
invoke GetDlgItem,hDlg, IDC_BUTTON3
mov hMyButton,eax
Because if I want to hide the button (hMyButton), the button doesnt disapear.
:stupid:
Perhaps the mistake is here ?:
PUSHBUTTON "",IDC_BUTTON3, 210, 48,20,15, BS_BITMAP | BS_ICON
THIS:
mov eax,hDlg
mov hDlg,eax
Basically does nothing. it moves the value of hDlg into eax and back. The proper way is like this, the value for hDlg is in the first parameter of the call to DialogProc
DialogProc proc uses ebx esi edi hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg == WM_INITDIALOG
mov eax,hWnd
mov hDlg,eax
I posted the following code and you failed to use it at every turn. It works, you keep substituting the wrong values:
BUTTONIMAGE is the ID number of the icon in the resource file
IDC_BUTTON3 is the ID number of the Button on your dialog
All other values are unknown and not important at compile time
I have now wasted about 10 posts on a three line thing that is simple to do. You have to read about the API and maybe some tutorials on basic programming. I will unfortunely have to stop answering until you decide to do some groundwork yourself.
Donkey
mov eax,hDlg
mov hDlg,eax
Basically does nothing. it moves the value of hDlg into eax and back. The proper way is like this, the value for hDlg is in the first parameter of the call to DialogProc
DialogProc proc uses ebx esi edi hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg == WM_INITDIALOG
mov eax,hWnd
mov hDlg,eax
I posted the following code and you failed to use it at every turn. It works, you keep substituting the wrong values:
hButtonIcon DWORD ?
hDlg DWORD ?
hMyButton DWORD ?
.IF uMsg == INITDIALOG
mov eax,hWnd
mov hDlg,eax
invoke GetDlgItem,hDlg,IDC_BUTTON3
mov hMyButton,eax
invoke LoadImage, hInstance, BUTTONIMAGE, IMAGE_ICON, 16, 16, NULL
mov hButtonIcon,eax
invoke SendMessage, hMyButton, BM_SETIMAGE, IMAGE_ICON, hButtonIcon
BUTTONIMAGE is the ID number of the icon in the resource file
IDC_BUTTON3 is the ID number of the Button on your dialog
All other values are unknown and not important at compile time
I have now wasted about 10 posts on a three line thing that is simple to do. You have to read about the API and maybe some tutorials on basic programming. I will unfortunely have to stop answering until you decide to do some groundwork yourself.
Donkey
Have you checked if the IDC_BUTTON3 constant has the same values
in the resource header file(resource.h) and your assembly source?
in the resource header file(resource.h) and your assembly source?
Yes ! All right !
The Button3 works, but not the handle.
The Button3 works, but not the handle.
Please can someone give me an ultra sample for my quest to realize a icon in a button.
Im very surem that i have done everything well.
Please give me an example. (I know it sounds nasty, but I'm desperately ):confused:
Im very surem that i have done everything well.
Please give me an example. (I know it sounds nasty, but I'm desperately ):confused: