Archive: nsdialogs + Trackbar control [NSD_OnNotify problem]


nsdialogs + Trackbar control [NSD_OnNotify problem]
I would like to ask about TrackBar control support in NSIS.
I need to use a trackbar in my nsdialogs based custom page.
I have few problems with it...

Here is how I create the control:

!define TBM_SETPOS 0x0405
!define TBM_GETPOS 0x0400
!define TBM_SETRANGEMIN 0x0407
!define TBM_SETRANGEMAX 0x0408

; Slider
nsDialogs::CreateControl "msctls_trackbar32" "0x50010000|0x00000018" "" 15u 76u 100 20 ""
Pop $Slider1
SendMessage $Slider1 ${TBM_SETRANGEMIN} 1 1 ; Setting Min range (1)
SendMessage $Slider1 ${TBM_SETRANGEMAX} 1 8 ; Setting Max range (8)
${NSD_OnNotify} $Slider1 onNotify_Slider1 ; Using OnNotify

First problem. ${NSD_OnClick} or ${NSD_OnChange$} doeasnt work. Is it possible to make it work?
I want to do some action, when user move the slider.
I am using ${NSD_OnNotify} instead. This works, but there are some problems...
Take a look at this function:

Function onNotify_Slider1

SendMessage $Slider1 ${TBM_GETPOS} 0 0 $1 ; Get Trackbar position

${Select} $1
${Case} "1"
; Do something 1 (I am displaying here an image 1)
${Case} "2"
; Do something 2 (I am displaying here an image 2)
${Case} "n"
; Do something n (I am displaying here an image n)
${EndSelect}

System::Call "gdi32:DeleteObject(i $Image_Var)" ; Here I am freeing used resource for Images

FunctionEnd

The big problem is, that if I move slider of trackbar (few times, from position 1 to 8), installer uses more and more memory.
Even if function "onNotify_Slider1" has no code (is empty), there are some memory leaks or something.
Why? What is the way to use correctly ${NSD_OnNotify}?

OnNotify

nsDialogs::OnNotify control_HWND function_address

Sets a notification callback function for the given control. Whenever the control receives the WM_NOTIFY message, the function will be called and the control's HWND, notification code and a pointer to the MNHDR structure will be waiting on its stack.

Use GetFunctionAddress to get the address of the desired callback function.


Maybe memory problems is result of this MNHDR structure on stack? Maybe I should free this? (how?)
How can I just use OnChange for Trackbar?

Somebody has an idea, example?
Thanks
-Pawel


http://msdn.microsoft.com/en-us/libr...=VS.85%29.aspx

Stu


Stu,
Thanks for tip.
Could you explain it with some code example?
I am afraid I don't know how to use this...
And, if it is used right, is it gonna fix memory problems?


Ps: Stu, I send you private message few days ago. Can you alos take a look at this?


A function that handles the WM_NOTIFY callback cannot be empty, that is why you get leaks. It HAS to pop the 3? parameters off the stack each time it is called.


Originally posted by Afrow UK
http://msdn.microsoft.com/en-us/libr...=VS.85%29.aspx
MSDN claims that message is Vista only, so I don't know why you are linking to it

Ah sorry my bad. See this instead: http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx (the Trackbar Notification Messages section). Unfortunately nsDialogs doesn't appear to handle WM_HSCROLL or WM_VSCROLL. You would probably need to modify the plugin (nsDialogs.c:79) to handle those messages and call onChange (or something).

Stu


@Anders
Pop $0
Pop $1
Pop $2

This do the job. no more memory leaks. Thx.

@Stu
Sounds very clever, but I dont know how to use it :P
I need something in Notify callback, that:
If message = "???" then do some action

-Pawel


That's the first link I posted but as Anders rightly points out is only available on Vista and above.

Stu