The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: agathon on April 26, 2005, 11:01:01 AM

Title: Progress bar
Post by: agathon on April 26, 2005, 11:01:01 AM
Hi,

I have attempted to add a progress bar to a monte carlo simulation application without success. After a diligent search and reference to Iczelion's tutorial 18, I am stumped.
******************************************************************************************************************************
...
      include \MASM32\INCLUDE\comctl32.inc
...
      includelib \MASM32\LIB\comctl32.lib
...
ProgressClass   db "msctls_progress32",0
...
        invoke InitCommonControls
...
    .elseif uMsg == WM_CREATE
...
      invoke CreateWindowEx,NULL,ADDR ProgressClass,NULL,WS_CHILD+WS_VISIBLE,\
                            10,250,600,25,hWnd,1,hInstance,NULL
      mov   hPrg, eax
      cmp eax, 0
      jne f00
      invoke display_int, 1001, hEdit11
  f00:
...
    mov eax, Tnum
    shl eax, 16
    invoke SendMessage, hPrg, PBM_SETRANGE, 0, eax
    invoke SendMessage, hPrg, PBM_SETSTEP,  1, 0
...
    invoke SendMessage, hPrg, PBM_STEPIT,  0, 0
...

************************************************************************************************************************
My application assembles and links without error, but on execution, CreateWindowEx returns 0 in all attempts.

The progress bar, unsurprisingly, does not appear in the app window.

Iczelion's sample code assembles, links and executes correctly.

What is up?

Cordially,
RWM
Title: Re: Progress bar
Post by: agathon on April 26, 2005, 04:16:52 PM
Ok,

hWnd in the CreateWindowEx call was incorrect. The status bar works as designed.

Cordially,
RWM
Title: Re: Progress bar
Post by: pbrennick on April 26, 2005, 04:28:27 PM
agathon ,

I am glad you were able to work it out.  Without the source there was no way that I could help you.

Paul
Title: Re: Progress bar
Post by: xandaz on March 29, 2010, 10:15:02 PM
   Hey guys. i'm having some trouble myself with progress bars. Creates fine and works fine if i don't reffer the theme's visual style in the manifest. But when i do - in the example i was making the bar was supposed to go back and forth as it reaching eather of ends - the bar goes back and forth in what seems to be random behaviour. What do the ranges stand for? Why do i need a min and a max value for range? can't i just use a max ?


.data

; ++++ Process Related Stuff ++++

hInstance       DWORD           ?
CommandLine     LPSTR           ?

; ++++ Main Window Vars & Others ++++

hMainWindow     dd              ?
MainWindowClass db              'MainWindowClass',0
MainWindowName  db              'Progress Bar Example',0
MainWindowWidth dd              400
MainWindowHeight        dd      150

; ++++ Progress Bar Vars & Others ++++

ProgressClass   db      'msctls_progress32',0
hProgress       dd      ?
ProgressWidth   dd      ?
ProgressHeight  dd      32
MaxRange        dd      0fffh
MinRange        dd      0ffh
BarWidth        dd      ?

; ++++ Status Window Stuff ++++

hStatus         dd      ?
StatusString    db      'Pressione qualquer tecla para incrementar/decrementar barra',0

DirFlag         dd      TRUE

.code
        start:
                invoke  GetModuleHandle,NULL
                mov     hInstance,eax
                invoke  GetCommandLine
                mov     CommandLine,eax
                invoke  InitCommonControls
                invoke  WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
                invoke  ExitProcess,eax

WinMain PROC    hInst:DWORD,hPrevInst:DWORD,CmdLine:DWORD,CmdShow:DWORD

        local   wc:WNDCLASSEX
        local   msg:MSG

        mov     wc.cbSize,sizeof wc
        mov     wc.style,CS_HREDRAW+CS_VREDRAW
        mov     wc.lpfnWndProc,offset WndProc
        mov     wc.lpszMenuName,NULL
        mov     wc.lpszClassName,offset MainWindowClass
        mov     wc.cbClsExtra,NULL
        mov     wc.cbWndExtra,NULL
        mov     wc.hbrBackground,COLOR_WINDOW
        push    hInst
        pop     wc.hInstance
        invoke  LoadIcon,NULL,IDI_APPLICATION
        mov     wc.hIcon,eax
        mov     wc.hIconSm,eax
        invoke  LoadCursor,NULL,IDC_ARROW
        mov     wc.hCursor,eax
        invoke  RegisterClassEx,addr wc
        invoke  CreateWindowEx,NULL,addr MainWindowClass,addr MainWindowName,WS_TILEDWINDOW,\
                NULL,NULL,MainWindowWidth,MainWindowHeight,NULL,NULL,hInstance,NULL
        mov     hMainWindow,eax
        invoke  ShowWindow,eax,SW_SHOWNORMAL
        invoke  UpdateWindow,hMainWindow

start_loop:
        invoke  PeekMessage,addr msg,NULL,NULL,NULL,PM_NOREMOVE
        or      eax,eax
        jz      do
skip:
        invoke  GetMessage,addr msg,NULL,0,0
        cmp     al,0
        je      nxt
        invoke  TranslateMessage,addr msg
        invoke  DispatchMessage,addr msg
        jmp     start_loop
do:
        call    BarProc
        jmp     start_loop
nxt:
        mov     eax,msg.wParam
        ret

WinMain endp

WndProc PROC    hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

        local   rect:RECT

        .if     uMsg==WM_DESTROY

                invoke  DestroyWindow,hProgress
                invoke  PostQuitMessage,NULL

        .elseif uMsg==WM_CREATE
       
                mov     edi,lParam
                assume  edi:PTR CREATESTRUCT

                .if     [edi].hWndParent==NULL
               
                        invoke  GetClientRect,hWnd,addr rect
                        sub     rect.right,40
                        invoke  CreateWindowEx,WS_EX_CLIENTEDGE,addr ProgressClass,NULL,WS_VISIBLE+WS_CHILD+PBS_SMOOTH+PBS_SMOOTHREVERSE,\
                                20,20,rect.right,ProgressHeight,hWnd,NULL,hInstance,NULL
                        mov     hProgress,eax
                        push    rect.right
                        pop     BarWidth       
                        sub     BarWidth,2
                        invoke  SendMessage,hProgress,PBM_SETRANGE32,MinRange,MaxRange
                             
                .endif   
        .else

        invoke  DefWindowProc,hWnd,uMsg,wParam,lParam
        ret

.endif

xor     eax,eax
ret

WndProc endp

BarProc         PROC

        mov     eax,DirFlag
        cmp     eax,TRUE
        jne     @@3
        invoke  SendMessage,hProgress,PBM_GETPOS,NULL,NULL
        cmp     eax,MaxRange
        jne     @@1
        mov     DirFlag,FALSE
        jmp     @@2
@@1:
        inc     eax
        invoke  SendMessage,hProgress,PBM_SETPOS,eax,NULL
        jmp     end_bp
@@3:
        invoke  SendMessage,hProgress,PBM_GETPOS,NULL,NULL
        cmp     eax,MinRange
        jne     @@2
        mov     DirFlag,TRUE
        jmp     @@1
@@2:   
        dec     eax
        invoke  SendMessage,hProgress,PBM_SETPOS,eax,NULL
end_bp:       
        ret

BarProc         endp

Can anyone look into this? thanks guys
i'll check laterz for reply.
best from X
Title: Re: Progress bar
Post by: xandaz on March 31, 2010, 01:11:36 AM
    About the my last post , i've been stepping the code with olly and there's a wm_timer timer and wm_paint constatelly being send to or by the progressbar control. Can someone pls explain this behaviour?
   Thanks for the help guys.
   Bye and best regards from X
Title: Re: Progress bar
Post by: redskull on March 31, 2010, 01:28:08 AM
What you are talking about is a "marquee style" progress bar, in Windows-speak.  You use the PBS_MARQUEE style, and then just set the speed with PBM_SETMARQUEE.  That absolves you of having to deal with 'min', 'max', and 'increment'.  However, from user-interface standpoint, consider that these provide absolutely no information to the user, and are probably better replaced by a "normal" one.

-r

PS - Is this a record for reopening old threads?
Title: Re: Progress bar
Post by: xandaz on April 01, 2010, 09:28:25 PM
   I used PBM_STEPIT with Stepping = 1 and works more or less fine, except it goes very fast forward and very slowly backwards. Any onw knows why?
   Bests from X.