View Single Post
Old 24th April 2020, 14:10   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,320
Of course you ask for the icon that is hardest to get FYI, the generic image is not in shell32 and there is no real generic drive icon on < Vista.

On < Vista the generic icon might be wrong.

PHP Code:
!include nsDialogs.nsh
Page Custom MyIconPage

!define /IfNDef LOAD_LIBRARY_AS_DATAFILE 2
!define /IfNDef LR_DEFAULTSIZE 0x0040
!define /IfNDef SHGFI_ADDOVERLAYS 0x000000020
!define /IfNDef SHGFI_ICON 0x000000100
!define /IfNDef SHGFI_USEFILEATTRIBUTES 0x000000010
!if "${NSIS_CHAR_SIZE}1
!define /redef /math SHFILEINFO_SIZE ${NSIS_PTR_SIZE} + 688
!else
!
define /redef /math SHFILEINFO_SIZE ${NSIS_PTR_SIZE} + 348
!endif
!
define /IfNDef SIID_DRIVEFIXED 8
Var hIcoByIndex
Var hIcoByResId
Var hIcoForSpecificDrive
Var hIcoForGenericDrive
Function MyIconPage
nsDialogs
::Create 1018
Pop 
$0

${NSD_CreateIcon0 0u 20u 20u ''
Pop $1
System
::Call 'SHELL32::ExtractIcon(p0, t "$SysDir\SHELL32.dll", i 8)p.s'
Pop $hIcoByIndex
SendMessage 
$${STM_SETIMAGE} ${IMAGE_ICON$hIcoByIndex


${NSD_CreateIcon22u 0u 20u 20u ''
Pop $1
System
::Call 'KERNEL32::LoadLibraryEx(t "$SysDir\SHELL32.dll", p0, i${LOAD_LIBRARY_AS_DATAFILE})p.s'
System::Call 'USER32::LoadImage(pss, t "#9", i ${IMAGE_ICON}, i0, i0, i${LR_DEFAULTSIZE})p.s'
Pop $hIcoByResId
System
::Call 'KERNEL32::FreeLibrary(ps)'
SendMessage $${STM_SETIMAGE} ${IMAGE_ICON$hIcoByResId


${NSD_CreateIcon0 20u 20u 20u ''
Pop $1
StrCpy 
$2 $SysDir 3 "c:\" probably
System::Call 'SHELL32::SHGetFileInfo(t"
$2", i0, @r2, i ${SHFILEINFO_SIZE}, i${SHGFI_ICON}|${SHGFI_ADDOVERLAYS})p.r3'
${If} $3 P<> 0
    System::Call '*$2(p.s)'
    Pop 
$hIcoForSpecificDrive
${EndIf}
SendMessage $1 
${STM_SETIMAGE} ${IMAGE_ICON} $hIcoForSpecificDrive


${NSD_CreateIcon} 0 40u 20u 20u ''
Pop $1
System::Call 'USER32::GetClientRect(p0,@r2)' ; Just to get a buffer
System::Call '*$2(&l
${NSIS_PTR_SIZE},p,i,i,&w260)'
System::Call 'SHELL32::SHGetStockIconInfo(i 
${SIID_DRIVEFIXED}, i${SHGFI_ICON}, pr2)i.r3' ; Vista+
${If} $3 >= 0
${AndIf} $3 != "error"
    System::Call '*$2(&i
${NSIS_PTR_SIZE},p.s)'
    Pop 
$hIcoForGenericDrive
${Else}
    System::Call 'SHELL32::SHGetFileInfo(t"
c:\", i0x10, @r2, i ${SHFILEINFO_SIZE}, i${SHGFI_ICON}|${SHGFI_USEFILEATTRIBUTES})p.r3'
    
${If} $3 P<> 0
        System::Call '*$2(p.s)'
        Pop 
$hIcoForGenericDrive
    
${EndIf}
${EndIf}
SendMessage $1 
${STM_SETIMAGE} ${IMAGE_ICON} $hIcoForGenericDrive


nsDialogs::Show
${NSD_FreeIcon} $hIcoByIndex
${NSD_FreeIcon} $hIcoByResId
${NSD_FreeIcon} $hIcoForSpecificDrive
${NSD_FreeIcon} $hIcoForGenericDrive
FunctionEnd 

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote