例子:使用ComboBoxEx类创建硬盘分区下拉列表
优质
小牛编辑
131浏览
2023-12-01
引用 ComboBoxEx.nsi 的内容:
!include "MUI2.nsh" !include "UsefulLib.nsh" /* User defines start */ !define __NSD_ComboBoxEx_CLASS ComboBoxEx32 !define __NSD_ComboBoxEx_STYLE ${DEFAULT_STYLES}|${WS_TABSTOP}|${CBS_DROPDOWN} !define __NSD_ComboBoxEx_EXSTYLE 0 !define __NSD_DropListEx_CLASS ComboBoxEx32 !define __NSD_DropListEx_STYLE ${DEFAULT_STYLES}|${WS_TABSTOP}|${CBS_DROPDOWNLIST} !define __NSD_DropListEx_EXSTYLE 0 !insertmacro __NSD_DefineControl ComboBoxEx !insertmacro __NSD_DefineControl DropListEx ${define} DRIVE_UNKNOWN 0 ${define} DRIVE_NO_ROOT_DIR 1 ${define} DRIVE_REMOVABLE 2 ${define} DRIVE_FIXED 3 ${define} DRIVE_REMOTE 4 ${define} DRIVE_CDROM 5 ${define} DRIVE_RAMDISK 6 ${define} ILC_COLOR 0 ${define} ILC_MASK 1 ${define} ILC_COLOR4 4 ${define} ILC_COLOR8 8 ${define} ILC_COLOR16 16 ${define} ILC_COLOR24 24 ${define} ILC_COLOR32 32 ${define} CBEM_INSERTITEM 0x00000401 ${define} CBEM_SETIMAGELIST 0x00000402 ${define} CBEM_GETIMAGELIST 0x00000403 ${define} CBEM_GETITEM 0x00000404 ${define} CBEM_SETITEM 0x00000405 ${define} CBEM_DELETEITEM ${CB_DELETESTRING} ${define} CBEM_GETCOMBOCONTROL 0x00000406 ${define} CBEM_GETEDITCONTROL 0x00000407 ${define} CBEM_GETEXTENDEDSTYLE 0x00000409 ${define} CBEM_HASEDITCHANGED 0x0000040A ${define} CBEM_SETEXTENDEDSTYLE 0x0000040E ${define} CBEIF_TEXT 0x00000001 ${define} CBEIF_IMAGE 0x00000002 ${define} CBEIF_SELECTEDIMAGE 0x00000004 ${define} CBEIF_OVERLAY 0x00000008 ${define} CBEIF_INDENT 0x00000010 ${define} CBEIF_LPARAM 0x00000020 ${define} CBEIF_DI_SETITEM 0x10000000 /* User defines end */ Name "ComboBoxEx" OutFile ComboBoxEx.exe InstallDir $TEMP Page custom CreatePage !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_LANGUAGE "English" Function CreatePage !insertmacro MUI_HEADER_TEXT "ComboBoxEx control" "ComboBoxEx control created using nsDialogs plugin" nsDialogs::Create 1018 Pop $0 ${If} $0 == error Abort ${EndIf} ${NSD_CreateLabel} 0u 0u 300u 9u "使用 ComboBoxEx32 类创建的带图标下拉列表:" Pop $0 ${NSD_CreateLabel} 0u 70u 300u 9u "使用 ComboBox 类创建的纯文字下拉列表:" Pop $0 ${NSD_CreateDropListEx} 0u 15u 300u 140u "DropListEx" Pop $1 ${NSD_CreateDropList} 0u 85u 300u 140u "DropList" Pop $2 System::Alloc 1024 Pop $R1 System::Call 'kernel32::GetLogicalDriveStrings(i1024,iR1)' OK: System::Call 'kernel32::lstrlen(t)i(iR1).R2' IntCmp $R2 0 Exit System::Call 'kernel32::GetDriveType(t)i(iR1).R3' StrCmp $R3 ${DRIVE_FIXED} 0 Next System::Call 'kernel32::GetDiskFreeSpaceEx(t,*l,*l,*l)i(iR1,.R3,.R4,.R5)' System::Call '*$R1(&t1024.R6)' System::Call 'kernel32::GetVolumeInformation(tR6,t.R7,i${MAX_PATH},*i,*i,*i,t.R8,i${MAX_PATH})' System::Call 'shlwapi::StrTrim(tR6R6,t"\")' System::Call 'shlwapi::StrFormatByteSize64(lR3,t.R3,t${MAX_PATH})' System::Call 'shlwapi::StrFormatByteSize64(lR4,t.R4,t${MAX_PATH})' ${IfThen} $R7 == '' ${|} StrCpy $R7 "本地磁盘" ${|} System::Call '*(i,i,t,i,i,i,i,i,i)i(${CBEIF_TEXT}|${CBEIF_IMAGE}|${CBEIF_SELECTEDIMAGE},0,"$R7 ($R6) ($R8) 可用空间:$R3",${NSIS_MAX_STRLEN},0,0,,,).r0' SendMessage $1 ${CBEM_INSERTITEM} 0 $0 ${NSD_CB_AddString} $2 '$R7 ($R6) ($R8) 可用空间:$R3' Next: IntOp $R1 $R1 + $R2 IntOp $R1 $R1 + 1 Goto OK Exit: System::Free $R1 System::Call 'kernel32::LoadLibrary(t"shell32.dll")i.r0' System::Call 'user32::LoadImage(i,t,i,i,i,i)i(r0,i9,${IMAGE_ICON},16,16,${LR_SHARED}).R0' System::Call 'kernel32::FreeLibrary(ir0)' System::Call 'comctl32::ImageList_Create(i16,i16,i${ILC_MASK}|${ILC_COLOR32},i0,i0)i.r0' System::Call 'comctl32::ImageList_AddIcon(ir0,iR0)' System::Call 'user32::DestroyIcon(iR0)' SendMessage $1 ${CBEM_SETIMAGELIST} 0 $0 nsDialogs::Show System::Call 'comctl32::ImageList_Destroy(ir0)' FunctionEnd Section -Main SectionEnd