8 Replies - 1284 Views - Last Post: 20 September 2012 - 05:07 PM

#1 Latias  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 28-June 12

how to use slider from toolbox

Posted 11 September 2012 - 01:36 PM

he!

surprising enough i didnt found anything about how to use a slider in masm.
what i want to do is when the user moves with the slider then a operation should be execute like changing the windows volume.

to make sure what i mean with slider here is a printscreen

Attached image(s)

  • Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: how to use slider from toolbox

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: how to use slider from toolbox

Posted 11 September 2012 - 03:11 PM

The control you are after is called a Trackbar.

As I tell everyone starting out with Windows Programming, MSDN is your best friend. I use the Platform SDK, has documentation for all the controls I need.

Attached Image

If your using the MASM32 package, there is an example in \masm32\examples\bcraven\controls.

Did a quick search on "Trackbar sample masm" and got

http://www.asmcommun.../testdepartment - Part 12 this is a great page with many samples.

The trackbar is not a hard control to use. Try some of the samples, and when you get stuck, post the code you are having trouble with.
Was This Post Helpful? 1
  • +
  • -

#3 Latias  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 28-June 12

Re: how to use slider from toolbox

Posted 14 September 2012 - 08:30 AM

ups didnt know it is called trackbar

i will try some ways cand when i stuck i will post here the source for help
thank you very much master
Was This Post Helpful? 0
  • +
  • -

#4 Latias  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 28-June 12

Re: how to use slider from toolbox

Posted 14 September 2012 - 12:25 PM

so i checked it out did extacly what they did in the examples but it doesnt work when i try to get the position of the trackbar into a label

so when the user slides with the trackbar the percent you be shown in the label, like 0% or 100%

this is the code i have

        project PROTO :DWORD,:DWORD,:DWORD,:DWORD
        SetControlsPosition PROTO :DWORD
    
; --------------------------------------------------------
    
.data
        hInstance dd ?
        NewPosition dd 0
        dlgname db "CONTROLS",0

.data?
        icex INITCOMMONCONTROLSEX <> ;structure for Controls
.code
    
start:
    
   
        invoke GetModuleHandle,NULL
        mov hInstance,eax
        mov icex.dwSize,sizeof INITCOMMONCONTROLSEX
        mov icex.dwICC,0FFFFh
        invoke InitCommonControlsEx,ADDR icex
        invoke DialogBoxParam,hInstance,ADDR dlgname,0,ADDR project,0
        invoke ExitProcess,eax
    
project proc hWin:DWORD,uMsg:DWORD,aParam:DWORD,bParam:DWORD
    
    LOCAL Ps:PAINTSTRUCT
    
        .if uMsg == WM_INITDIALOG
        		invoke SendDlgItemMessage,hWin,1001,UDM_SETRANGE32,0,100

        .elseif uMsg == WM_HSCROLL
                        mov eax,aParam
                        and eax,0FFFFh  
                        .if eax == TB_THUMBPOSITION ; Same as SB_THUMBPOSITION
                            mov eax,aParam
                            shr eax,16
                            mov NewPosition,eax
                            invoke SetControlsPosition,hWin
                        .elseif eax == TB_THUMBTRACK ; Same as SB_THUMBTRACK
                            mov eax,aParam
                            shr eax,16
                            mov NewPosition,eax
                            invoke SetControlsPosition,hWin
                        .elseif eax == SB_LINEUP
                            .if NewPosition != 0
                                dec NewPosition
                            .endif
                            invoke SetControlsPosition,hWin
                        .elseif eax == SB_LINEDOWN
                            .if NewPosition != 100
                                inc NewPosition
                            .endif 
                            invoke SetControlsPosition,hWin
                        .endif
    
        .elseif uMsg == WM_VSCROLL
                        mov eax,aParam
                        and eax,0FFFFh  
                        .if eax == TB_THUMBPOSITION
                            mov eax,aParam
                            shr eax,16
                            mov NewPosition,eax
                            invoke SetControlsPosition,hWin
                        .elseif eax == TB_THUMBTRACK
                            mov eax,aParam
                            shr eax,16
                            mov NewPosition,eax
                            invoke SetControlsPosition,hWin
                        .elseif eax == SB_LINEUP
                            .if NewPosition != 0
                                dec NewPosition
                            .endif
                            invoke SetControlsPosition,hWin
                        .elseif eax == SB_LINEDOWN
                            .if NewPosition != 100
                                inc NewPosition
                            .endif 
                            invoke SetControlsPosition,hWin
                        .endif
                        
                            
        .elseif uMsg == WM_CLOSE
                        invoke EndDialog,hWin,NULL
    
        .endif
    
        xor eax,eax
        ret
    
project endp
    
SetControlsPosition proc hWin:DWORD
       invoke SendDlgItemMessage,hWin,1001,UDM_SETPOS32,0,NewPosition
        ret
SetControlsPosition endp
    
end start

Was This Post Helpful? 0
  • +
  • -

#5 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: how to use slider from toolbox

Posted 14 September 2012 - 05:14 PM

Not exactly sure what you want, but I think this should do it. As I don't have your RC file or WAP project file, change your dialog id to 1000, your trackbar to 1001, add a static control somewhere and give it an id of 1002, when we set the trackbar buddy to use the static control, it will position it to the right of the trackbar. When you move the slider, it will update the buddy control with its position.

include masm32rt.inc


        project PROTO :DWORD,:DWORD,:DWORD,:DWORD
        SetControlsPosition PROTO :DWORD
    
; --------------------------------------------------------
.data?
hInstance       dd  ?      ; this can be here
NewPosition     dd  ?    ; and this too.
icex            INITCOMMONCONTROLSEX <> ;structure for Controls
.code
    
start:
   
        invoke GetModuleHandle,NULL
        mov hInstance,eax
        mov icex.dwSize,sizeof INITCOMMONCONTROLSEX
        mov icex.dwICC,0FFFFh
        invoke InitCommonControlsEx,ADDR icex
        invoke DialogBoxParam,hInstance,1000,0,ADDR project,0
        invoke ExitProcess,eax
    
project proc uses esi hWin:DWORD,uMsg:DWORD,aParam:DWORD,bParam:DWORD
    
    LOCAL Ps:PAINTSTRUCT
    
        .if uMsg == WM_INITDIALOG    
            mov     cx, 100 ; max trackbar pos
            ror     ecx, 16
            mov     cx, 0   ; min trackbar pos
            invoke  SendDlgItemMessage, hWin, 1001, TBM_SETRANGE, TRUE, ecx
        	
        	invoke  GetDlgItem, hWin, 1002
            invoke  SendDlgItemMessage, hWin, 1001, TBM_SETBUDDY,FALSE, eax
            
            mov     esi, 90
            NextTick:
                invoke  SendDlgItemMessage, hWin, 1001, TBM_SETTIC, 0, esi
                sub     esi, 10
                jnz     NextTick
                
        .elseif uMsg == WM_HSCROLL
                        mov eax,aParam
                        and eax,0FFFFh  
                        .if eax == TB_THUMBPOSITION ; Same as SB_THUMBPOSITION
                            mov eax,aParam
                            shr eax,16
                            mov NewPosition,eax
                            invoke SetControlsPosition,hWin
                        .elseif eax == TB_THUMBTRACK ; Same as SB_THUMBTRACK
                            mov eax,aParam
                            shr eax,16
                            mov NewPosition,eax
                            invoke SetControlsPosition,hWin
                        .elseif eax == SB_LINEUP
                            .if NewPosition != 0
                                dec NewPosition
                            .endif
                            invoke SetControlsPosition,hWin
                        .elseif eax == SB_LINEDOWN
                            .if NewPosition != 100
                                inc NewPosition
                            .endif 
                            invoke SetControlsPosition,hWin
                        .endif
    
        .elseif uMsg == WM_VSCROLL
                        mov eax,aParam
                        and eax,0FFFFh  
                        .if eax == TB_THUMBPOSITION
                            mov eax,aParam
                            shr eax,16
                            mov NewPosition,eax
                            invoke SetControlsPosition,hWin
                        .elseif eax == TB_THUMBTRACK
                            mov eax,aParam
                            shr eax,16
                            mov NewPosition,eax
                            invoke SetControlsPosition,hWin
                        .elseif eax == SB_LINEUP
                            .if NewPosition != 0
                                dec NewPosition
                            .endif
                            invoke SetControlsPosition,hWin
                        .elseif eax == SB_LINEDOWN
                            .if NewPosition != 100
                                inc NewPosition
                            .endif 
                            invoke SetControlsPosition,hWin
                        .endif
                        
                            
        .elseif uMsg == WM_CLOSE
                        invoke EndDialog,hWin,NULL
    
        .else
            xor     eax, eax ; return FALSE for unhandled messages
            ret
        .endif
        ; A dialog message handler is not the same as a window.
        mov     eax, TRUE ; return TRUE for handled messages
        ret
    
project endp
    
SetControlsPosition proc hWin:DWORD
    invoke  SetDlgItemInt, hWin, 1002, NewPosition, FALSE
;       invoke SendDlgItemMessage,hWin,1002,UDM_SETPOS32,0,NewPosition
        ret
SetControlsPosition endp
    
end start

Was This Post Helpful? 1
  • +
  • -

#6 Latias  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 28-June 12

Re: how to use slider from toolbox

Posted 15 September 2012 - 02:06 AM

thank you much master working now :bananaman:
Was This Post Helpful? 0
  • +
  • -

#7 Latias  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 28-June 12

Re: how to use slider from toolbox

Posted 18 September 2012 - 01:37 AM

just 1 question trough
why do you add AND EAX,0FFFFh in the code? i know it converts its value to binary but what is the effect for the scrollbar?


.elseif uMsg == WM_HSCROLL
044
                        mov eax,aParam
045
                        and eax,0FFFFh


and why SHR EAX,16 ? what does it mean for the scrollbar?

This post has been edited by Latias: 18 September 2012 - 01:50 AM

Was This Post Helpful? 0
  • +
  • -

#8 Latias  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 28-June 12

Re: how to use slider from toolbox

Posted 20 September 2012 - 01:57 PM

please explain it to me why i have to add AND EAX,0FFFFh and SHR EAX,16 in the code :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#9 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: how to use slider from toolbox

Posted 20 September 2012 - 05:07 PM

Quote

i know it converts its value to binary
No, not really. ALL numbers are already binary, the CPU only knows binary.

A quick query of the PSDK for WM_HSCROLL notification explains it.

Quote

wParam
The low-order word specifies a scroll bar value that indicates the user's scrolling request. This word can be one of the following values.

The high-order word specifies the current position of the scroll box if the low-order word is SB_THUMBPOSITION or SB_THUMBTRACK; otherwise, this word is not used.


So, to get the low word of wParam, we mask out high word.
FFFF = 1111111111111111

So, if I move the trakcbar with the mouse, these are the numbers that my window proc receives for WM_HSCROLL/wParam:
aParam = 5 (Trackbar.asm, 54)
aParam = 65541 (Trackbar.asm, 54)
aParam = 131077 (Trackbar.asm, 54)
aParam = 131076 (Trackbar.asm, 54)
aParam = 8 (Trackbar.asm, 54)


Let's take 65541 which is 10000000000000101, you with me? We are interested in the message which is in the low word of 65541 so we and it with FFFF (65535)
10000000000000101 ∧
01111111111111111
-----------------
00000000000000101 (5) = SB_THUMBTRACK

AND uses a simple truth table
1 ∧ 1 = 1
1 ∧ 0 = 0
0 ∧ 0 = 0
0 ∧ 1 = 0

There are other ways to separate the high and low words, but this is used often.

Again, a quick search of the PSDK for TBM_SETRANGE:
lResult = SendMessage(    // returns LRESULT in lResult
        (HWND) hWndControl,       // handle to destination control
        (UINT) TBM_SETRANGE,    // message ID
        (WPARAM) wParam,          // = (WPARAM) (BOOL) fRedraw
        (LPARAM) lParam              // = (LPARAM) MAKELONG (lMinimum, lMaximum)
        );

So the trackbar gets its min and max values from a packed DWORD
mov cx, 100 ; max trackbar pos
ror ecx, 16
mov cx, 0 ; min trackbar pos
Move the value 100 into cx (the low word of ecx) and rotate it right 16 bytes gives you 6553600, we really don't need mov cx, 0 as you can see it is already 0, it is to make sure it is zero and not garbage.
Change the numbers and zero out ecx first to make it clearer:
            xor     ecx, ecx
            mov     cx, 1000
            PrintDec ecx
            ror     ecx, 16
            mov     cx, 50  
            PrintDec ecx

ecx = 1000 (Trackbar.asm, 41)
ecx = 65536050 (Trackbar.asm, 44)


Try this:
Open your calc in windows and press ALT + 3 for programmer view. Enter a number and look at the binary rep of that number. Press RoR 16 times and watch what happens each time. The documentation for the mnuemonics discusses all this. Read it!
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1