Move data between ListBoxes: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
Line 94: Line 94:
System::Call user32::SendMessage(i$ListBox_left,i${LB_GETTEXT},i$0,t.r1)
System::Call user32::SendMessage(i$ListBox_left,i${LB_GETTEXT},i$0,t.r1)
${NSD_LB_AddString} $ListBox_right "$1"
${NSD_LB_AddString} $ListBox_right "$1"
SendMessage $ListBox_left ${LB_DELETESTRING} $0 `STR:$1`
SendMessage $ListBox_left ${LB_DELETESTRING} 0 `STR:$1`
${EndIf}
${EndIf}
   FunctionEnd
   FunctionEnd
Line 104: Line 104:
System::Call user32::SendMessage(i$ListBox_right,i${LB_GETTEXT},i$0,t.r1)
System::Call user32::SendMessage(i$ListBox_right,i${LB_GETTEXT},i$0,t.r1)
${NSD_LB_AddString} $ListBox_left "$1"
${NSD_LB_AddString} $ListBox_left "$1"
SendMessage $ListBox_right ${LB_DELETESTRING} $0 `STR:$1`
SendMessage $ListBox_right ${LB_DELETESTRING} 0 `STR:$1`
${EndIf}
${EndIf}
   FunctionEnd
   FunctionEnd

Revision as of 16:59, 7 August 2008

Author: Jan (talk, contrib)


Description

A custom page using nsDialogs to move (or copy) data between controls, in this case two listboxes

ListeBoxes.jpg

Function

OutFile listboxes.exe
 
;Includes
!include nsDialogs.nsh
!include LogicLib.nsh
 
;Definitions
!define MOVE_BUTTONS
!define COPY_BUTTONS
 
;Variables
Var Dialog
Var ListBox_left
Var ListBox_right
!ifdef MOVE_BUTTONS
  Var Button_MoveRight
  Var Button_MoveLeft
!endif ;MOVE_BUTTONS
!ifdef COPY_BUTTONS
  Var Button_CopyRight
  Var Button_CopyLeft
!endif ;COPY_BUTTONS
 
;Pages
Page custom nsDialogsPage
Page InstFiles
 
;Functions
Function nsDialogsPage
 
	nsDialogs::Create /NOUNLOAD 1018
	Pop $Dialog
 
	${If} $Dialog == error
		Abort
	${EndIf}
 
	${NSD_CreateListBox} 0 5% 33% 90% " "
	Pop $ListBox_left
 
	;dummy data
	${NSD_LB_AddString} $ListBox_left "111"
	${NSD_LB_AddString} $ListBox_left "222"
	${NSD_LB_AddString} $ListBox_left "333"
 
	${NSD_CreateListBox} 66% 5% 33% 90% " "
	Pop $ListBox_right
 
	;more dummy data
	${NSD_LB_AddString} $ListBox_right "AAA"
	${NSD_LB_AddString} $ListBox_right "BBB"
	${NSD_LB_AddString} $ListBox_right "CCC"
 
  !ifdef MOVE_BUTTONS
	${NSD_CreateButton} 50% 40% 10% 20 "->"
	Pop $Button_MoveRight
	GetFunctionAddress $0 OnClick_MoveRight
	${NSD_OnClick} $Button_MoveRight OnClick_MoveRight
 
	${NSD_CreateButton} 40% 40% 10% 20 "<-"
	Pop $Button_MoveLeft
	GetFunctionAddress $0 OnClick_MoveLeft
	${NSD_OnClick} $Button_MoveLeft OnClick_MoveLeft
  !endif ;MOVE_BUTTONS	
 
  !ifdef COPY_BUTTONS
	${NSD_CreateButton} 50% 50% 10% 20 ">>"
	Pop $Button_CopyRight
	GetFunctionAddress $0 OnClick_CopyRight
	${NSD_OnClick} $Button_CopyRight OnClick_CopyRight
 
	${NSD_CreateButton} 40% 50% 10% 20 "<<"
	Pop $Button_CopyLeft
	GetFunctionAddress $0 OnClick_CopyLeft
	${NSD_OnClick} $Button_CopyLeft OnClick_CopyLeft
  !endif ;COPY_BUTTONS
 
	nsDialogs::Show

FunctionEnd
 
!ifdef MOVE_BUTTONS
  Function OnClick_MoveRight
	Pop $R0
	SendMessage $ListBox_left ${LB_GETCURSEL} 0 0 $0
	${If} $0 >= 0
		System::Call user32::SendMessage(i$ListBox_left,i${LB_GETTEXT},i$0,t.r1)
		${NSD_LB_AddString} $ListBox_right "$1"
		SendMessage $ListBox_left ${LB_DELETESTRING} 0 `STR:$1`
	${EndIf}
  FunctionEnd
 
  Function OnClick_MoveLeft
	Pop $R0
	SendMessage $ListBox_right ${LB_GETCURSEL} 0 0 $0
	${If} $0 >= 0
		System::Call user32::SendMessage(i$ListBox_right,i${LB_GETTEXT},i$0,t.r1)
		${NSD_LB_AddString} $ListBox_left "$1"
		SendMessage $ListBox_right ${LB_DELETESTRING} 0 `STR:$1`
	${EndIf}
  FunctionEnd
!endif ;MOVE_BUTTONS
 
!ifdef COPY_BUTTONS
  Function OnClick_CopyRight
	Pop $R0
	SendMessage $ListBox_left ${LB_GETCURSEL} 0 0 $0
	${If} $0 >= 0
		System::Call user32::SendMessage(i$ListBox_left,i${LB_GETTEXT},i$0,t.r1)
		${NSD_LB_AddString} $ListBox_right "$1"
	${EndIf}  
  FunctionEnd
 
  Function OnClick_CopyLeft
	Pop $R0
	SendMessage $ListBox_right ${LB_GETCURSEL} 0 0 $0
	${If} $0 >= 0
		System::Call user32::SendMessage(i$ListBox_right,i${LB_GETTEXT},i$0,t.r1)
		${NSD_LB_AddString} $ListBox_left "$1"
	${EndIf}
  FunctionEnd
!endif ;COPY_BUTTONS
 
;Section
Section
	#empty
SectionEnd