Skip to content
⌘ NSIS Forum Archive

Skinned custom buttom on custom page on Windows 8

12 posts

oldfriend#

Skinned custom buttom on custom page on Windows 8

Hello.

Does anybody has an experience of creating custom buttons with images over them and it works on Windows 7,8,10?

I used for Windows 7 such code
  System::Call 'user32::LoadImage(i 0, t "MyImage.bmp", i ${IMAGE_BITMAP}, i 0, i 0, i ${LR_CREATEDIBSECTION}|${LR_LOADFROMFILE}) i.s'
    Pop $6
  SendMessage $hButton_handle ${BM_SETIMAGE} ${IMAGE_BITMAP} $6 
but it doesn't work for windows 8 and 10 (and for XP)
oldfriend#
Originally Posted by Anders View Post
Is $6 NULL? Why are you not using a absolute path?
Yes, $6 is NULL and absolute path doesn't change anything ($6 still NULL).
stass#
OutFile "test.exe"
!include "MUI2.nsh"
Page Custom MyPage
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
var dlg
var Button
Var IMAGE
Function MyPage
nsDialogs::Create 1018
Pop $dlg
${NSD_CreateButton} 100u 20u 157 57 ''
Pop $Button
${NSD_OnClick} $Button ButtonClick
${NSD_AddStyle} $Button "${BS_BITMAP}" 
StrCpy $7 "${NSISDIR}\Contrib\Graphics\Header\nsis.bmp" 
System::Call 'user32::LoadImage(i 0, t "$7", i ${IMAGE_BITMAP}, i 0, i 0, i ${LR_CREATEDIBSECTION}|${LR_LOADFROMFILE}) i.s' 
Pop $IMAGE 
SendMessage $Button ${BM_SETIMAGE} ${IMAGE_BITMAP} $IMAGE 
nsDialogs::Show
System::Call "gdi32::DeleteObject(i$IMAGE)"
FunctionEnd
Function ButtonClick
MessageBox MB_OK "ButtonClick"
FunctionEnd
Section
SectionEn 
If you compile the script in Windows 7, in Windows 10 - the picture on the button, no!

If you compile the script in Windows 10, then everything is OK. It is amazing...
Anders#
Change the first Call to '...) i.s?e' and add another Pop, it should contain the error code.

@Stass: Use a File instruction and extract the bitmap to $pluginsdir with /oname...
oldfriend#
Originally Posted by stass View Post
If you compile the script in Windows 7, in Windows 10 - the picture on the button, no!

If you compile the script in Windows 10, then everything is OK. It is amazing...
Well, but is there inverse relation? I mean if compiling it on Win10 will it work for Win7?
stass#
Originally Posted by oldfriend View Post
Well, but is there inverse relation? I mean if compiling it on Win10 will it work for Win7?
Does not work ! What nonsense ...


Anders
No difference, and if so:
Function .onInit
    InitPluginsDir
    File /ONAME=$PLUGINSDIR\nsis.bmp "${NSISDIR}\Contrib\Graphics\Header\nsis.bmp"
FunctionEnd
Function MyPage
nsDialogs::Create 1018
Pop $dlg
${NSD_CreateButton} 100u 20u 157 57 ''
Pop $Button
${NSD_OnClick} $Button ButtonClick
${NSD_AddStyle} $Button "${BS_BITMAP}" 
System::Call 'user32::LoadImage(i 0, t "$PLUGINSDIR\nsis.bmp", i ${IMAGE_BITMAP}, i 0, i 0, i ${LR_CREATEDIBSECTION}|${LR_LOADFROMFILE}) i.s' 
Pop $IMAGE 
SendMessage $Button ${BM_SETIMAGE} ${IMAGE_BITMAP} $IMAGE 
(Version NSIS - nsis-3.0b2-setup.exe )
oldfriend#
Originally Posted by Anders View Post
Change the first Call to '...) i.s?e' and add another Pop, it should contain the error code.
Well, I changed it to

  System::Call 'user32::LoadImage(i 0, t "D:\\MyImage.bmp", i ${IMAGE_BITMAP}, i 0, i 0, i ${LR_CREATEDIBSECTION}|${LR_LOADFROMFILE}) i.s?e'
    Pop $2 
But $2 contains 0. Probably I did something wrong?
stass#
Icon button - Works on all OS


OutFile "test-ico-button.exe"
!include "MUI2.nsh"
Page Custom MyPage
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
var dlg
var Button
Var IMAGE
Function .onInit
InitPluginsDir
 File /ONAME=$PLUGINSDIR\orange-install.ico "${NSISDIR}\Contrib\Graphics\Icons\orange-install.ico"
FunctionEnd
Function MyPage
nsDialogs::Create 1018
Pop $dlg
${NSD_CreateButton} 100u 20u 48 48 ''
Pop $Button
${NSD_OnClick} $Button ButtonClick
${NSD_AddStyle} $Button "${BS_ICON}" 
System::Call 'user32::LoadImage(i 0, t "$PLUGINSDIR\orange-install.ico", i ${IMAGE_ICON}, i 0, i 0, i ${LR_CREATEDIBSECTION}|${LR_LOADFROMFILE}) i.s' 
Pop $IMAGE 
SendMessage $Button ${BM_SETIMAGE} ${IMAGE_ICON} $IMAGE 
nsDialogs::Show
System::Call "gdi32::DeleteObject(i$IMAGE)"
FunctionEnd
Function ButtonClick
MessageBox MB_OK "ButtonClick"
FunctionEnd
Section
SectionEnd 
Anders#
Originally Posted by oldfriend View Post
But still impossible to set image on the button for all Operation Systems. Why?
It should work, we just need to figure out what the problem is.

Try this:
OutFile Test.exe
RequestExecutionLevel user
Section
SectionEnd
Function .onInit
InitPluginsDir
File "/ONAME=$PLUGINSDIR\nsis.bmp" "${NSISDIR}\Contrib\Graphics\Header\nsis.bmp"
FunctionEnd
Page Custom MyPage
Page InstFiles

!include nsDialogs.nsh
!include WinMessages.nsh
Function MyPage
nsDialogs::Create 1018
Pop $0

${NSD_CreateButton} 10u 0u 157 57 ""
Pop $0
${NSD_AddStyle} $0 "${BS_BITMAP}"
System::Call 'user32::LoadImage(i 0, t "$PLUGINSDIR\nsis.bmp", i ${IMAGE_BITMAP}, i 0, i 0, i ${LR_CREATEDIBSECTION}|${LR_LOADFROMFILE})i.s?e'
Pop $2 ; GetLastError
Pop $1 ; HANDLE
SendMessage $0 ${BM_SETIMAGE} ${IMAGE_BITMAP} $1

System::Call kernel32::GetVersion()i.r9
IntOp $8 $9 & 0xff
IntOp $9 $9 >> 8
IntOp $9 $9 & 0xff
nsDialogs::CreateControl EDIT ${DEFAULT_STYLES}|${WS_TABSTOP}|${ES_MULTILINE}|${ES_READONLY} "0" 0 50% 100% 50% "hBitmap=$1$\r$\nLoadImage():GLE=$2$\r$\nWinVer=$8.$9$\r$\nNSIS_PACKEDVERSION=${NSIS_PACKEDVERSION}, NSIS_CHAR_SIZE=${NSIS_CHAR_SIZE}, NSIS_PTR_SIZE=${NSIS_PTR_SIZE}"
Pop $0

nsDialogs::Show
${NSD_FreeBitmap} $1
FunctionEnd