The MASM Forum

Miscellaneous => Miscellaneous Projects => Windows Projects => Topic started by: sudoku on April 22, 2024, 04:34:50 AM

Title: 'marquee style' progress bar example
Post by: sudoku on April 22, 2024, 04:34:50 AM
Inspired by a recent thread by NoCforMe (had issues with marquee progress bar), and some assistance from TimoVJL (provided C code example) I have decided to create a 'marquee style" progress bar example, in masm32 code.

include \masm32\include\masm32rt.inc
    DlgProc    proto :dword, :dword, :dword, :dword

.data
    hInstance  dd 0
    hProgress  dd 0
.code
start:
    invoke GetModuleHandle, 0
    mov hInstance, eax
    invoke DialogBoxParamA, hInstance, 1000, 0, addr DlgProc, 0
    invoke ExitProcess, eax

DlgProc proc hWin:dword, uMsg:dword, wParam:dword, lParam:dword
  .if uMsg == WM_INITDIALOG
    invoke GetDlgItem, hWin, 1003
    mov hProgress, eax
    invoke ShowWindow, hProgress, SW_HIDE                      ; hide progress bar until needed
  .elseif uMsg == WM_COMMAND
    .if wParam == 1001
      invoke ShowWindow, hProgress, SW_SHOW                    ; show progress bar
      invoke SendMessage, hProgress, PBM_SETMARQUEE, TRUE, 0    ; animate progress bar
    .elseif wParam == 1002
      invoke SendMessage, hProgress, PBM_SETMARQUEE, FALSE, 0  ; stop progress bar animation
      invoke ShowWindow, hProgress, SW_HIDE                    ; hide progress bar
    .endif
  .elseif uMsg == WM_CLOSE
    invoke EndDialog, hWin, 0
    xor eax, eax
    ret
  .endif
    xor eax, eax
    ret
DlgProc endp

end start

Push the "Start" button to start the progress bar.
Push "Stop" to stop it.

:azn:

Tested on Windows 7 only...
Title: Re: 'marquee style' progress bar example
Post by: jj2007 on April 22, 2024, 06:40:31 AM
Fatal error, "cannot include file 'include'"
Title: Re: 'marquee style' progress bar example
Post by: Vortex on April 22, 2024, 06:49:53 AM
Hi Jochen,

This line in the resource script :

#include "C:/masm32/include/RESOURCE.H"
should be changed to :

#include "\masm32\include\RESOURCE.H"
Title: Re: 'marquee style' progress bar example
Post by: sudoku on April 22, 2024, 06:56:02 AM
Quote from: Vortex on April 22, 2024, 06:49:53 AMHi Jochen,

This line in the resource script :

#include "C:/masm32/include/RESOURCE.H"
should be changed to :

#include "\masm32\include\RESOURCE.H"
:mrgreen:
fixed in the archive as well.
That was resed's fault. lol

I didnt notice since I never had any trouble with it.
Title: Re: 'marquee style' progress bar example
Post by: jj2007 on April 22, 2024, 06:57:36 AM
Exactly, Erol :thumbsup:

Quote from: sudoku on April 22, 2024, 06:56:02 AMThat was resed's fault.

I never used resed. Does it have any advantage over, say, Notepad? And I wouldn't count forward slashes in a Windows environment as an advantage...
Title: Re: 'marquee style' progress bar example
Post by: sudoku on April 22, 2024, 07:02:10 AM
Quote from: jj2007 on April 22, 2024, 06:57:36 AMI never used resed. Does it have any advantage over, say, Notepad? And I wouldn't count forward slashes in a Windows environment as an advantage...
Sure, a nifty wysiwyg dialog editor. Can't do that in notpad.

Yes, the forward slashes are weird. Complain to ketilo next time he pops in for a visit.  :biggrin:
Title: Re: 'marquee style' progress bar example
Post by: NoCforMe on April 22, 2024, 10:00:55 AM
I think the forward slashes are C language lingo, not native Windows pathnames.

I've used resed; pretty nifty li'l tool, but it seems geared towards C, not assembly language. I ended up stealing some of its workings and creating my own tool, DialogGen, which instead of creating a resource (.rc) file that must be compiled by the resource compiler, generates a simple assembly-language include file that you just INCLUDE in your program. It too is WYSIWIG. (I'd post it here but to be honest it's full of bugs, and far too complicated to even have to explain. I use it despite its flaws. Someday maybe I'll fix it ...)

BTW, shouldn't this thread be in the Windows API forum since it deals with a Windows control?
Title: Re: 'marquee style' progress bar example
Post by: jj2007 on April 22, 2024, 04:17:17 PM
Quote from: NoCforMe on April 22, 2024, 10:00:55 AMBTW, shouldn't this thread be in the Windows API forum since it deals with a Windows control?

I tend to share sudoku's view. It's a little project, too small for the Showcase, more like a demo. "Windows questions" creep in, that's normal, but still, I think it fits nicely here :thumbsup:
Title: Re: 'marquee style' progress bar example
Post by: TimoVJL on April 22, 2024, 06:20:58 PM
For just using poasm.exe
ifndef __POASM__
include \masm32\include\masm32rt.inc
else
.model flat, stdcall
ExitProcess    proto :dword
GetModuleHandleA proto :dword
DialogBoxParamA proto :dword, :dword, :dword, :dword, :dword
EndDialog      proto :dword, :dword
GetDlgItem      proto :dword, :dword
ShowWindow      proto :dword, :dword
SendMessageA    proto :dword, :dword, :dword, :dword
SendMessage equ SendMessageA
GetModuleHandle equ GetModuleHandleA
TRUE equ 1
FALSE equ 0
WM_CLOSE equ 10h
WM_INITDIALOG equ 110h
WM_COMMAND equ 111h
SW_HIDE equ 0
SW_SHOW equ 5
PBM_SETMARQUEE equ 1034
endif
Title: Re: 'marquee style' progress bar example
Post by: sudoku on April 22, 2024, 10:40:39 PM
Thanks, Timo. I had never used poasm. What are the advantages over ml?
Title: Re: 'marquee style' progress bar example
Post by: TimoVJL on April 22, 2024, 11:06:28 PM
Quote from: sudoku on April 22, 2024, 10:40:39 PMThanks, Timo. I had never used poasm. What are the advantages over ml?
poasm support invoke in x64 mode.
Pelles C have own IDE, poide, so those users can test code examples with it's debugger, as newer versions have just own debug format only, not CodeView any more.
Title: Re: 'marquee style' progress bar example
Post by: sudoku on April 22, 2024, 11:12:30 PM
When I have some free time, (and remember to do it), I'll check it out.  :thumbsup:
Title: Re: 'marquee style' progress bar example
Post by: Vortex on April 23, 2024, 02:39:28 AM
Hi sudoku,

Some powerful Poasm statements :

QuoteOPTON CSTRINGS:ON C : escape sequences are processed in string literals.
INCBIN : Includes a (binary) file within the file being assembled.
CINCLUDE : Parses a C include file, looking for #define statements.
Title: Re: 'marquee style' progress bar example
Post by: Vortex on April 23, 2024, 05:47:29 AM
Hi sudoku,

Some small recommendations :

- You don't need to hide the progress bar while initializing the dialog box. Specifiying the flag NOT WS_VISIBLE in your resource script will hide the control.

- For better code maintenance, it's preferable to define some equates to replace the identifiers based on ID numbers.

Here is the complete code :

; Original example code by sudoku
; https://masm32.com/board/index.php?topic=11864.0

include \masm32\include\masm32rt.inc

DlgProc PROTO :dword,:dword,:dword,:dword

IDB_START   equ 1001
IDB_STOP    equ 1002
IDC_PBBAR   equ 1003

.data?

hInstance   dd ?
hProgress   dd ?

.code

start:

    invoke  GetModuleHandle,0
    mov     hInstance,eax
    invoke  DialogBoxParam,eax,1000,0,ADDR DlgProc,0
    invoke  ExitProcess,eax

DlgProc PROC hWin:dword,uMsg:dword,wParam:dword,lParam:dword

    .if uMsg == WM_INITDIALOG
   
        invoke  GetDlgItem,hWin,IDC_PBBAR
        mov     hProgress, eax

    .elseif uMsg == WM_COMMAND
   
        .if wParam == IDB_START
       
            invoke  ShowWindow,hProgress,SW_SHOW                   ; show progress bar
            invoke  SendMessage,hProgress,PBM_SETMARQUEE,TRUE,0    ; animate progress bar

        .elseif wParam == IDB_STOP

            invoke  SendMessage,hProgress,PBM_SETMARQUEE,FALSE,0   ; stop progress bar animation
            invoke  ShowWindow,hProgress, SW_HIDE                  ; hide progress bar
           
        .endif
   
    .elseif uMsg == WM_CLOSE
 
        invoke  EndDialog,hWin,0

    .else

        xor     eax,eax
        ret

  .endif
 
    mov     eax,1
    ret
   
DlgProc ENDP

END start

#include "\masm32\include\Resource.h"

#define IDB_START 1001
#define IDB_STOP 1002

1000 DIALOGEX 10,10,141,54
CAPTION "Marquee Style"
FONT 8,"MS Sans Serif",0,0,0
STYLE WS_VISIBLE|WS_OVERLAPPEDWINDOW|DS_CENTER
BEGIN
  CONTROL "Start",IDB_START,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,12,30,54,15
  CONTROL "Stop",IDB_STOP,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,72,30,54,15
  CONTROL "",1003,"msctls_progress32",NOT WS_VISIBLE|PBS_MARQUEE|PBS_SMOOTH,12,9,114,12
END

1 24 "manifest.xml"
Title: Re: 'marquee style' progress bar example
Post by: sudoku on April 23, 2024, 05:55:12 AM
@Vortex:
Does my example not work for you?
Title: Re: 'marquee style' progress bar example
Post by: Vortex on April 23, 2024, 06:03:20 AM
Hi sudoku,

Your example works fine. I only proposed some small improvements.
Title: Re: 'marquee style' progress bar example
Post by: TimoVJL on April 23, 2024, 06:10:29 AM
@Vortex
why not just remove WS_VISIBLE from resource file.

my mistake, WS_VISIBLE is default
Title: Re: 'marquee style' progress bar example
Post by: Vortex on April 23, 2024, 06:19:47 AM
Hi Timo,

If you mean the following :

CONTROL "",1003,"msctls_progress32",PBS_MARQUEE|PBS_SMOOTH,12,9,114,12
I am sorry but this will not work. You can edit the original resource script with Pelles IDE : Setting the property Visible of the progress bar to No will modify the flag to NOT WS_VISIBLE.
Title: Re: 'marquee style' progress bar example
Post by: sudoku on April 23, 2024, 06:30:49 AM
By NOT using SW_HIDE in the intialization, this is the result. Progress bar shows like this upon opening the program, not what is desired.   :rolleyes:
(https://i.postimg.cc/yWXgCCXC/marquee.png) (https://postimg.cc/yWXgCCXC)

What is desired is that nothing shows until 'start' is pressed. And that is what my example does.

Title: Re: 'marquee style' progress bar example
Post by: sudoku on April 23, 2024, 06:38:56 AM
using 'NOT WS_VISIBLE' in the resource file works (without using SW_HIDE in init.), but seems unorthodox.

Deleted comment, as it did not quite sound as I intended, and it may have offended.
Title: Re: 'marquee style' progress bar example
Post by: Vortex on April 23, 2024, 06:55:58 AM
Hello,

QuoteIt's getting to be that a guy can't post a simple working example without a whole lot of drama.

Now, this statement does not welcome the efforts trying to help you. It was probably my fault. :undecided:
Title: Re: 'marquee style' progress bar example
Post by: sudoku on April 23, 2024, 07:04:12 AM
Quote from: Vortex on April 23, 2024, 06:55:58 AMIt was probably my fault.
No Vortex, I didn't mean to give you that impression.  Maybe its all my fault for not seeing the forest through the trees.
I do appreciate the help.
Thanks for the tips, as well  :thumbsup:
Title: Re: 'marquee style' progress bar example
Post by: Vortex on April 23, 2024, 07:07:53 AM
Hi sudoku,

No fiasco and nothing wrong. All of us, we are here to learn and experiment. Never get discouraged. Life means trial and error for all the humans.
Title: Re: 'marquee style' progress bar example
Post by: sudoku on April 23, 2024, 07:08:49 AM
Quote from: Vortex on April 23, 2024, 07:07:53 AMNo fiasco
No, all is well. I am just having a bad couple of days.
Title: marquee progress - custom control
Post by: sudoku on April 23, 2024, 07:19:21 AM
Here is a custom marquee style progress bar control.
There must be a manifest file for the program that you might use it in.

one of hutch's custom control sources was used as a template.
; ########################################################################

MarqueeProgress proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD

;; example
;; invoke MarqueeProgress, hWin, 20, 20, 200, 24, 2004
;; mov hMarquee, eax

MarqueeProgress proc hParent:DWORD, a:DWORD, b:DWORD, wd:DWORD, ht:DWORD, ID:DWORD

    szText mrqClass, "msctls_progress32"

    invoke CreateWindowEx, 0,
            ADDR mrqClass, 0,
            WS_CHILD or WS_VISIBLE or PBS_MARQUEE or PBS_SMOOTH,
            a, b, wd, ht, hParent, ID,
            hInstance, NULL

    ret

MarqueeProgress endp

; ########################################################################

A working example attached. (using generic.exe from masm32 examples)
I will add two buttons later, to work in the same way as my dialog box example.
I had forgotten to add the buttons in this example.
Title: Re: 'marquee style' progress bar example
Post by: NoCforMe on April 23, 2024, 11:38:28 AM
How is that a "custom" control?

A custom control is where you modify the control's default behavior or appearance, most often through the use of owner draw (or subclassing). This is just a stock progress bar, no?