DrBonzo
28th October 2011 18:12 UTC
having trouble with NSD_OnNotify with ListBox
I'm trying to respond to clicks on a listbox. Here's the setup:
nsDialogs::Create /NOUNLOAD 1018
Pop $ListBoxPage
${NSD_CreateListBox} 0 20 100% 80% "Backup folders"
Pop $ListBox
Call PopulateListBox
${NSD_OnNotify} $ListBox ListClicked
nsDialogs::Show
The list box is getting populated, but ListClicked is never getting called.
What am I missing?
Anders
29th October 2011 17:55 UTC
Not every notification works for every control. OnNotify hooks WM_NOTIFY and a listbox does not use that message IIRC
DrBonzo
31st October 2011 14:49 UTC
Thanks, Anders, for your reply.
Yes, indeed, listboxes neither generate nor receive WM_NOTIFY messages for selection changes. I had been encouraged by another thread (http://forums.winamp.com/showthread....ght=lbs_notify) mentioning LBS_NOTIFY, but that poster was looking for OnChange notifications.
The MSDN dox say that the list box's *parent* ($ListBoxPage in my example) receives selection change notifications and I've verified with Spy++ that, in fact, this notification is in the form of a WM_COMMAND message with a wNotifyCode (HIWORD of wParam) of LBN_SELCHANGE.
So it looks like I need to subclass $ListBoxPage. I've found WndSubclass - http://nsis.sourceforge.net/WndSubclass_plug-in (yours, Anders?), which looks like it might do the trick. If so, I'll post the results. If not, I'll probably ask for more help...
DrBonzo
31st October 2011 17:18 UTC
Thanks to WndSubclass, here's a working example :
Page custom ListBoxDialogPage
OutFile ListBoxTest.exe
Section "Empty section"
SectionEnd
!include LogicLib.nsh
!include NsDialogs.nsh
!include WinMessages.nsh
!include WndSubclass.nsh
var ListBox
var ListBoxPage
!define __NSD_ListBoxMulti_CLASS LISTBOX
!define __NSD_ListBoxMulti_STYLE ${DEFAULT_STYLES}|${WS_TABSTOP}|${WS_VSCROLL}|${LBS_EXTENDEDSEL}|${LBS_HASSTRINGS}|${LBS_NOTIFY}
!define __NSD_ListBoxMulti_EXSTYLE ${WS_EX_WINDOWEDGE}|${WS_EX_CLIENTEDGE}
!insertmacro __NSD_DefineControl ListBoxMulti
Function PopulateListBox
SendMessage $ListBox ${LB_ADDSTRING} 0 "STR:Abel"
SendMessage $ListBox ${LB_ADDSTRING} 0 "STR:Baker"
SendMessage $ListBox ${LB_ADDSTRING} 0 "STR:Charlie"
FunctionEnd
Function ListClicked
SendMessage $ListBox ${LB_GETCURSEL} 0 0 $0
MessageBox MB_OK "Cursel: $0"
FunctionEnd
Var CommandCaptureVar
!define LBN_SELCHANGE 1
Function CommandCapture
${If} $2 = ${WM_COMMAND}
Var /Global HiWord
IntOp $HiWord $3 >> 16
IntOp $HiWord $HiWord & 0xff
${If} $HiWord = ${LBN_SELCHANGE}
Call ListClicked
${EndIf}
${EndIf}
FunctionEnd
Function ListBoxDialogPage
nsDialogs::Create /NOUNLOAD 1018
Pop $ListBoxPage
${NSD_CreateListBoxMulti} 0 20 100% 80% ""
Pop $ListBox
Call PopulateListBox
${WndSubclass_Subclass} $ListBoxPage CommandCapture $CommandCaptureVar $CommandCaptureVar
nsDialogs::Show
FunctionEnd