Header file for Listview: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
Line 56: Line 56:
Compile the script and run, you will see a page like this:
Compile the script and run, you will see a page like this:
[[File:Listview1.png]]
[[File:Listview1.png]]
== Example 2 ==
<highlight-nsis>
/* Listview styles are defined in header file */
!include "MUI2.nsh"
!include "ListView.nsh"
Name "List View Example"
OutFile ListView.exe
Page custom CreatePage
!insertmacro MUI_LANGUAGE "English"
Function CreatePage
    !insertmacro MUI_HEADER_TEXT "List view" "Using icon resource from system file as image list"
    nsDialogs::Create 1018
    Pop $0
    ${If} $0 == error
        Abort
    ${EndIf}
    ${NSD_CreateListView} 0u 0u 300u 140u "Listview"
    Pop $1
    ${NSD_LV_InsertColumn} $1 0 200 "column 0"
    ${NSD_LV_InsertColumn} $1 1 200 "column 1"
    ${NSD_LV_InsertItem} $1 0 'Item 0'
    ${NSD_LV_InsertItem} $1 1 'Item 1'
    ${NSD_LV_InsertItem} $1 2 'Item 2'
    ; Retrieve the recommended width and height of an icon
    System::Call 'user32::GetSystemMetrics(i ${SM_CXICON})i.r7'
    System::Call 'user32::GetSystemMetrics(i ${SM_CYICON})i.r8'
    ; Retrieve the handle of shell32.dll
    System::Call 'kernel32::GetModuleHandle(i)i(t"shell32.dll")i.r0'
    ; Load the 9th icon of recommended size in shell32
    System::Call 'user32::LoadImage(i,t,i,i,i,i)i(r0,i9,${IMAGE_ICON},r7,r8,${LR_SHARED})i.R1'
    ; Free the handle of shell32.dll
    System::Call 'user32::FreeLibrary(ir0)'
    ; Create an imagelist, width of each image is $7 and height is $8.
    System::Call 'comctl32::ImageList_Create(ir7,ir8,i${ILC_MASK}|${ILC_COLOR32},i0,i0)i.R0'
    ; Add icon to the imagelist by handle.
    System::Call 'comctl32::ImageList_AddIcon(iR0,iR1)'
    SendMessage $1 ${LVM_SETIMAGELIST} ${LVSIL_SMALL} $R0
    SendMessage $1 ${LVM_SETEXTENDEDLISTVIEWSTYLE} 0 ${LVS_EX_FULLROWSELECT}
    nsDialogs::Show
    ; Destroy the image list
    System::Call 'comctl32::ImageList_Destroy(iR0)'
FunctionEnd
Section -Main
SectionEnd
</highlight-nsis>
Compile the script and run, you will see a page like this:
[[File:Listview2.png]]

Revision as of 06:36, 2 July 2010

Header file for creating Listview control

In an NSIS forum "dreams8.com", a member named "gfm688" writes a header file to create and handle a listview control with the report view. This header file is modified by me, I add some new macro commands.

See the attachment for details, 8 examples included.

ListView.zip (328 KB)

Example 1

/* Listview styles are defined in header file */
!include "MUI2.nsh"
!include "ListView.nsh"
 
Name "List View Example"
OutFile ListView.exe
 
Page custom CreatePage
!insertmacro MUI_LANGUAGE "English"
 
Function CreatePage
 
    !insertmacro MUI_HEADER_TEXT "List view" "A listview control created by nsDialogs"
 
    nsDialogs::Create 1018
    Pop $0
    ${If} $0 == error
        Abort
    ${EndIf}
 
    ${NSD_CreateListView} 0u 0u 300u 140u "Listview"
    Pop $1
    ; ${NSD_LV_InsertColumn} hwnd col_idx_0_based col_width col_text
    ${NSD_LV_InsertColumn} $1 0 200 "column 0"
    ${NSD_LV_InsertColumn} $1 1 100 "column 1"
    ${NSD_LV_InsertColumn} $1 2 100 "column 2"
    ; ${NSD_LV_InsertItem} hwnd item_idx_0_based item_text
    ${NSD_LV_InsertItem} $1 0 'Item 0'
    ; ${NSD_LV_SetSubItem} hwnd item_idx_0_based subitem_idx_1_based subitem_text
    ${NSD_LV_SetSubItem} $1 0 1 'Subitem 0_1'
    ${NSD_LV_SetSubItem} $1 0 2 'Subitem 0_2'
    ${NSD_LV_InsertItem} $1 1 'Item 1'
    ${NSD_LV_SetSubItem} $1 1 2 'Subitem 1_2'
    ${NSD_LV_InsertItem} $1 2 'Item 2'
    ${NSD_LV_SetSubItem} $1 2 1 'Subitem 2_1'
 
    nsDialogs::Show

FunctionEnd
 
Section -Main
 
SectionEnd

Compile the script and run, you will see a page like this: Listview1.png

Example 2

/* Listview styles are defined in header file */
!include "MUI2.nsh"
!include "ListView.nsh"
 
Name "List View Example"
OutFile ListView.exe
 
Page custom CreatePage
!insertmacro MUI_LANGUAGE "English"
 
Function CreatePage
 
    !insertmacro MUI_HEADER_TEXT "List view" "Using icon resource from system file as image list"
 
    nsDialogs::Create 1018
    Pop $0
    ${If} $0 == error
        Abort
    ${EndIf}
 
    ${NSD_CreateListView} 0u 0u 300u 140u "Listview"
    Pop $1
    ${NSD_LV_InsertColumn} $1 0 200 "column 0"
    ${NSD_LV_InsertColumn} $1 1 200 "column 1"
    ${NSD_LV_InsertItem} $1 0 'Item 0'
    ${NSD_LV_InsertItem} $1 1 'Item 1'
    ${NSD_LV_InsertItem} $1 2 'Item 2'
    ; Retrieve the recommended width and height of an icon
    System::Call 'user32::GetSystemMetrics(i ${SM_CXICON})i.r7'
    System::Call 'user32::GetSystemMetrics(i ${SM_CYICON})i.r8'
    ; Retrieve the handle of shell32.dll
    System::Call 'kernel32::GetModuleHandle(i)i(t"shell32.dll")i.r0'
    ; Load the 9th icon of recommended size in shell32
    System::Call 'user32::LoadImage(i,t,i,i,i,i)i(r0,i9,${IMAGE_ICON},r7,r8,${LR_SHARED})i.R1'
    ; Free the handle of shell32.dll
    System::Call 'user32::FreeLibrary(ir0)'
    ; Create an imagelist, width of each image is $7 and height is $8.
    System::Call 'comctl32::ImageList_Create(ir7,ir8,i${ILC_MASK}|${ILC_COLOR32},i0,i0)i.R0'
    ; Add icon to the imagelist by handle.
    System::Call 'comctl32::ImageList_AddIcon(iR0,iR1)'
 
    SendMessage $1 ${LVM_SETIMAGELIST} ${LVSIL_SMALL} $R0
    SendMessage $1 ${LVM_SETEXTENDEDLISTVIEWSTYLE} 0 ${LVS_EX_FULLROWSELECT}
 
    nsDialogs::Show

    ; Destroy the image list
    System::Call 'comctl32::ImageList_Destroy(iR0)'
 
FunctionEnd
 
Section -Main
 
SectionEnd

Compile the script and run, you will see a page like this: Listview2.png