hello, I have a problem trying to painting an icon into a button. I have tried several ways, but no one works. I share a code where I couldn't do this job.
Can anyone help, please?
VentWN1.asm:
VentWN1.rc:
Compila.bat
ambU.ico --> I couldn't upload it, I'm sorry
Can anyone help, please?
VentWN1.asm:
; ----------------------------------------------------------------------------
; - TITULO : Ejemplo de botón con icono W-NASM -
; ----- -----
; - AUTOR : Alfonso Víctor Caballero Hurtado -
; ----- -----
; - VERSION : 1.0 -
; ----------------------------------------------------------------------------
%include '..\..\..\inc\nasmx.inc' ; Incluímos macros
%include '..\..\..\inc\win32\windows.inc' ; Incluímos definiciones de estructuras y constantes
%include '..\..\..\inc\win32\kernel32.inc' ; Importamos las bibliotecas para que el enlazador pueda trabajar
%include '..\..\..\inc\win32\user32.inc' ; Importamos las bibliotecas para que el enlazador pueda trabajar
cdXPos EQU 128 ; Constante double X-Posición de la ventana(esq sup izqda)
cdYPos EQU 128 ; Constante double Y-Posición de la ventana(esq sup izqda)
cdXSize EQU 320 ; Constante double X-tamaño de la ventana
cdYSize EQU 200 ; Constante double Y-tamaño de la ventana
cdColFondo EQU COLOR_BTNFACE + 1 ; Color de fondo de la ventana: gris de un botón de comando
cdVIcono EQU IDI_APPLICATION ; Icono de la ventana
cdVCursor EQU IDC_ARROW ; Cursor para la ventana
cdVBarTipo EQU NULL ; Normal, con icono
cdVBtnTipo EQU WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU ; Normal sólo con botón cerrar
entry Entrada
proc Entrada
invoke GetModuleHandleA, dword NULL
mov , eax
INVOKE GetCommandLineA
mov , EAX
invoke WinMain, dword wc + WNDCLASSEX.hInstance, dword NULL, dword CommandLine, dword SW_SHOWNORMAL
invoke ExitProcess, dword NULL
ret
endproc
proc WinMain
; Propósito: Inicializamos la ventana principal de la aplicación y captura errores, si los hubiere
; Entrada : hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
; Salida : Ninguna
; Destruye : Ninguna
; Recogemos los parámetros
hinst argd ; Current instance handle - enganche a la instancia actual
hpinst argd ; Previous instance handle- enganche a la instancia previa
cmdln argd ; Command line arguments - argumentos de la línea de comandos
dwshow argd ; Display style - Estilo de despliegue
invoke LoadIconA, dword argv(hinst), NULL;dword cdVIcono
mov edx, eax
mov eax, dword argv(hinst)
mov ebx, dword NombreClase
mov ecx, dword WndProc
mov , eax
mov , ebx
mov , ecx
mov , edx
mov , edx
invoke LoadCursorA, NULL, cdVCursor
mov , eax
invoke RegisterClassExA, dword wc
test eax, eax
jz L_Error
invoke CreateWindowExA, dword cdVBarTipo, dword NombreClase, dword MsgCabecera, dword cdVBtnTipo,dword cdXPos, dword cdYPos, dword cdXSize, dword cdYSize, dword NULL, dword NULL, dword , dword NULL
test eax, eax
jz L_Error
mov , eax
invoke ShowWindow, dword hWnd, dword SW_SHOWNORMAL
invoke UpdateWindow, dword hWnd
.msgloop:
invoke GetMessageA, dword message, dword NULL, dword NULL, dword NULL
cmp eax, dword 0
je end_loop
invoke TranslateMessage, dword message
invoke DispatchMessageA, dword message
jmp .msgloop
L_Error:
invoke MessageBoxA, DWORD NULL, DWORD MsgError, NULL, DWORD MB_ICONERROR+MB_OK
end_loop:
mov eax, dword
ret
endproc
proc WndProc
; Propósito: Procesa los mensajes provenientes de las ventanas
; Entrada : hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
; Salida : Ninguna
; Destruye : Ninguna
; Recogemos los parámetros
uhwnd argd ; Window handle
uMsg argd ; Window message
wParam argd ; wParam
lParam argd ; lParam
mov eax, dword argv(uMsg)
cmp eax, WM_DESTROY
jz wm_destroy
cmp eax, WM_COMMAND
jz wm_command
cmp eax, WM_CREATE
jz wm_create
jmp wm_default
wm_create:
mov eax, dword argv(uhwnd)
mov , eax
invoke CreateWindowExA,dword cdVBarTipo,ClaseBoton,blnk1,WS_CHILD + WS_VISIBLE + BS_ICON,dword 20,dword 20,dword 36,dword 36,dword argv(uhwnd),400,dword ,NULL
mov , eax
invoke LoadIconA,dword ,101
invoke SendMessageA,,BM_SETIMAGE,1,eax
jmp wm_fin
wm_command:
mov eax, argv(wParam)
cmp eax, 400
je btn_Informa
jmp wm_fin
btn_Informa:
invoke MessageBoxA,dword argv(uhwnd), icoMsg1, icoMsgCab,MB_OK+MB_ICONASTERISK
jmp wm_fin
wm_destroy:
invoke PostQuitMessage,0
wm_default:
invoke DefWindowProcA, dword argv(uhwnd), dword argv(uMsg), dword argv(wParam), dword argv(lParam)
wm_fin:
ret
endproc
CommandLine resd 1
hWnd resd 1
hBtn1 resd 1
wHandle resd 1
MsgCabecera: db "Botón con icono (NASM)", 0x0
NombreClase: db "SimpleWinClass", 0x0
MsgError: db "Carga inicial fallida.",0x0
icoMsg1 db "Programado 100% en ensamblador (Nasm)",0x0
icoMsgCab db "Información", 0x0
ClaseBoton db "BUTTON", 0x0
blnk1 db 0x0
wc:
istruc WNDCLASSEX
at WNDCLASSEX.cbSize, dd WNDCLASSEX_size
at WNDCLASSEX.style, dd CS_VREDRAW + CS_HREDRAW
at WNDCLASSEX.lpfnWndProc, dd NULL
at WNDCLASSEX.cbClsExtra, dd NULL
at WNDCLASSEX.cbWndExtra, dd NULL
at WNDCLASSEX.hInstance, dd NULL
at WNDCLASSEX.hIcon, dd NULL
at WNDCLASSEX.hCursor, dd NULL
at WNDCLASSEX.hbrBackground, dd cdColFondo
at WNDCLASSEX.lpszMenuName, dd NULL
at WNDCLASSEX.lpszClassName, dd NULL
at WNDCLASSEX.hIconSm, dd NULL
iend
message:
istruc MSG
at MSG.hwnd, dd NULL
at MSG.message, dd NULL
at MSG.wParam, dd NULL
at MSG.lParam, dd NULL
at MSG.time, dd NULL
at MSG.pt, dd NULL
iend
VentWN1.rc:
#define IDR_VERSION1 1
#define BUTTON_ICON 101
LANGUAGE 10,1
IDR_VERSION1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEOS 0x00000004
FILETYPE 0x00000000
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "FFFF0000"
BEGIN
VALUE "FileVersion", "1.0.0.0\0"
VALUE "ProductVersion", "1.0.0.0\0"
VALUE "CompanyName", "Abre los ojos al ensamblador\0"
VALUE "FileDescription", "Botón con icono\0"
VALUE "InternalName", "VentWN1\0"
VALUE "LegalCopyright", "no rights reserved\0"
VALUE "OriginalFilename", "VentWN1.exe\0"
VALUE "ProductName", "VentWN1\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0xFFFF, 0x0000
END
END
BUTTON_ICON ICON DISCARDABLE "ambU.ico"
Compila.bat
del VentWN?.exe
..\..\..\bin\nasm -f win32 VentWN1.ASM -o VentWN1.obj
..\..\..\bin\GoRC.exe /r=VentWN1.res VentWN1.rc
..\..\..\bin\GoLink.exe /entry _main VentWN1.obj VentWN1.res kernel32.dll user32.dll
del *.obj
del *.bak
ambU.ico --> I couldn't upload it, I'm sorry
this is what i did to create a icon on a button.
@invoke CreateWindowEx, NULL, "button", "Volgend", \
WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON or BS_ICON, \
125,315,40,25, .hWnd, IDC_BUTTON_NEXT, hInstance, NULL
mov .hWnd_BUTTON_NEXT, eax
@invoke LoadImage, hInstance, "ICON_NEXT", IMAGE_ICON, 0, 0, 0
mov Icon_next, eax
invoke SendMessage, .hWnd_BUTTON_NEXT, BM_SETIMAGE, IMAGE_ICON, Icon_next
Hello, jpam, thanks por your replay.
What compiler did you have used?. It doesn't appear to be nasmx. I have used the same code in masm and fasm and works fine, not in nasmx. I'm considering using nagoa.inc instead of nasmx ....
Regards
What compiler did you have used?. It doesn't appear to be nasmx. I have used the same code in masm and fasm and works fine, not in nasmx. I'm considering using nagoa.inc instead of nasmx ....
Regards
i only use masm and ObjAsm32 from biterider
Same thing in NASMX
I haven't done windows assembly in a while, but this should work as a decent port. NASMX's invoke macro handles strings internally so there is no need for @invoke vs invoke and types default to the current word size (qword in in 64-bit mode and dword in 32-bit mode). Other than that you are mostly dealing with NASM's language constructs.
invoke CreateWindowEx, NULL, "button", "Volgend", \
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON | BS_ICON, \
125,315,40,25, \
, IDC_BUTTON_NEXT, , NULL
mov , eax ; Add a hButton DD 0 in the SECTION .data to store our button handle
invoke LoadImage, , "ICON_NEXT", IMAGE_ICON, 0, 0, 0
mov , eax ; Same here, store a handle to our icon handle in the .data section
invoke SendMessage, , BM_SETIMAGE, IMAGE_ICON,
I haven't done windows assembly in a while, but this should work as a decent port. NASMX's invoke macro handles strings internally so there is no need for @invoke vs invoke and types default to the current word size (qword in in 64-bit mode and dword in 32-bit mode). Other than that you are mostly dealing with NASM's language constructs.
Thanks, Synfire, but It doesn't work. This is what I did. Commented lines are substituted. But now it even doesn't create any button. Surely I did something wrong.
invoke CreateWindowExA, NULL, ClaseBoton, blnk1, \
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON | BS_ICON, \
125,315,40,25, \
dword argv(uhwnd), 400, , NULL
mov , eax ; Add a hButton DD 0 in the SECTION .data to store our button handle
invoke LoadImageA, , "ICON_NEXT", 101, 0, 0, 0
invoke SendMessageA, , BM_SETIMAGE, IMAGE_ICON,eax;
; invoke CreateWindowExA,dword cdVBarTipo,ClaseBoton,blnk1,WS_CHILD + WS_VISIBLE + BS_ICON+ BS_DEFPUSHBUTTON,dword 20,dword 20,dword 36,dword 36,dword argv(uhwnd),400,dword ,NULL
; mov , eax
; invoke LoadIconA,dword ,101
; invoke SendMessageA,,BM_SETIMAGE,1,eax
[...]
CommandLine resd 1
hWnd resd 1
wHandle resd 1
hBtn1 resd 1
invoke CreateWindowExA, NULL, ClaseBoton, blnk1, \
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON | BS_ICON, \
125,315,40,25, \
dword argv(uhwnd), 400, , NULL
mov , eax ; Add a hButton DD 0 in the SECTION .data to store our button handle
invoke LoadImageA, , "ICON_NEXT", 101, 0, 0, 0
invoke SendMessageA, , BM_SETIMAGE, IMAGE_ICON,eax;
; invoke CreateWindowExA,dword cdVBarTipo,ClaseBoton,blnk1,WS_CHILD + WS_VISIBLE + BS_ICON+ BS_DEFPUSHBUTTON,dword 20,dword 20,dword 36,dword 36,dword argv(uhwnd),400,dword ,NULL
; mov , eax
; invoke LoadIconA,dword ,101
; invoke SendMessageA,,BM_SETIMAGE,1,eax
[...]
CommandLine resd 1
hWnd resd 1
wHandle resd 1
hBtn1 resd 1
I don't really see much of a reason this shouldn't work, I've tried cleaning it up and reducing invokes to one line, try it out and see if it works. I don't have a windows machine to test this out on so I can't see first hand what works and what doesn't. :(
BIMG_STYLE equ (WS_CHILD + WS_VISIBLE + BS_DEFPUSHBUTTON + BS_ICON)
invoke CreateWindowExA, NULL, ClaseBoton, blnk1, BIMG_STYLE, 125, 315, 40, 25, dword argv(uhwnd), 400, , NULL
mov , eax ; Add a hButton DD 0 in the SECTION .data to store our button handle
invoke LoadImageA, , "ICON_NEXT", 101, 0, 0, 0
invoke SendMessageA, , BM_SETIMAGE, IMAGE_ICON, eax
[...]
CommandLine resd 1
hWnd resd 1
wHandle resd 1
hBtn1 resd 1
NaN once wrote a very fancy Icon Button Custom Control - Check our CC section and see if it's still there.
Guys, only joined recently, looking through old posts and came across this unresolved one!
After using BS_ICON in your window creation, use:
invoke LoadIcon,hInstance,IconName
invoke SendMessage,hwndButton1,BM_SETIMAGE,1,eax
After using BS_ICON in your window creation, use:
invoke LoadIcon,hInstance,IconName
invoke SendMessage,hwndButton1,BM_SETIMAGE,1,eax
I also wrote one and posted it here, mine does 'button skinning', so you can make the buttons (and even the app window itself) any shape you like based on bitmap images.