5 Replies - 814 Views - Last Post: 20 September 2012 - 01:59 PM

#1 Latias  Icon User is offline

  • D.I.C Head

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

whats wrong in this code?

Posted 18 September 2012 - 01:21 PM

hey masters i got a code for a progressbar, but the problem is that it doesnt work always smootly. somethimes it will shows a messagebox tha the progress is finished but not the whole progressbar is filled then

here is the code

.386
.model flat, stdcall
option casemap:none

include		windows.inc
include 		user32.inc
includelib 	user32.lib
include 		kernel32.inc
includelib 	kernel32.lib
include 		comctl32.inc
includelib 	comctl32.lib
include 		masm32.inc
includelib 	masm32.lib


DlgProc Proto :DWORD, :DWORD, :DWORD, :DWORD

.Const
IDC_PROGRESS	equ 1017
IDC_STATUS		equ 2
IDC_TIMER		equ 3

.data
Message			db "Finished!",0
TimerID			dd 0
Percent			db ' % done.',0

.data?
hInstance			HINSTANCE ?
hwndProgress		dd ?
hwndStatus		dd ?
CurrentStep		dd ?
Done			dd ?

.Code
Start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke GetCommandLine
invoke DialogBoxParam, hInstance, 1001, NULL, Addr DlgProc, NULL
invoke ExitProcess,0

DlgProc Proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

LOCAL	buffer[256]:BYTE

	
	.if uMsg == WM_INITDIALOG
		mov eax, wParam
		invoke GetDlgItem,hWnd,1002 ; progressbar setup
		mov hwndProgress,eax
		
		mov CurrentStep,1000
		shl eax,16	;/* Shift Logical Left , Usage:SHL     dest,count */
		invoke SendMessage,hwndProgress,PBM_SETRANGE,0,eax
		invoke SendMessage,hwndProgress,PBM_SETSTEP,10,0
		
		xor Done,0 ; Percent static setup

		invoke SetTimer,hWnd,IDC_TIMER,100,NULL 		; setup timer
		mov TimerID,eax
		
	.elseif uMsg == WM_TIMER
		invoke SendMessage,hwndProgress,PBM_STEPIT,0,0
		sub CurrentStep,10
		
		add Done,1 ; Static update 
		invoke dwtoa,Done,addr buffer
		invoke lstrcat,addr buffer, offset Percent
		invoke SendDlgItemMessage,hWnd,1004,WM_SETTEXT,0,addr buffer
		
		.if CurrentStep == 0
			invoke KillTimer,hWnd,TimerID
			mov TimerID,0
			invoke SendMessage,hwndStatus,SB_SETTEXT,0,offset Message
			invoke MessageBox,hWnd,offset Message,offset Message,MB_OK+MB_ICONINFORMATION
			invoke SendMessage,hwndStatus,SB_SETTEXT,0,0
			invoke SendMessage,hwndProgress,PBM_SETPOS,0,0
		.endif
			

	.elseif uMsg == WM_CLOSE
		.if TimerID!=0
			invoke KillTimer,hWnd,TimerID
		.endif
		invoke DestroyWindow,hWnd
	
		ret
	.endif
	xor    eax,eax
	ret
DlgProc endp

End Start


Is This A Good Question/Topic? 0
  • +

Replies To: whats wrong in this code?

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




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

Re: whats wrong in this code?

Posted 18 September 2012 - 03:30 PM

Look at this very carefully and tell me what is wrong:
		mov eax, wParam
		invoke GetDlgItem,hWnd,1002 ; progressbar setup
		mov hwndProgress,eax
		
		mov CurrentStep,1000
		shl eax,16	;/* Shift Logical Left , Usage:SHL     dest,count */
		invoke SendMessage,hwndProgress,PBM_SETRANGE,0,eax


First, why are you moving wParam into eax and never use it?

Now for your problem, what does GetDlgItem return in eax? So, whatever handle is in eax, you are now doing shl eax,16 and setting that as the progressbars min and max range!

mov CurrentStep,1000
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!
; What should go here?
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!
shl eax,16	;/* Shift Logical Left , Usage:SHL     dest,count */
invoke SendMessage,hwndProgress,PBM_SETRANGE,0,eax


I get this number: 150732800 when I run your code AS IS!!! Now I know that is NOT what you want the min and max value of your progressbar to be.
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: whats wrong in this code?

Posted 19 September 2012 - 12:52 AM

ups Getdlgitem returns in eax the handle

; What should go here >>> i don't know, i guessed mov eax,100 but that doesnt work at all

This post has been edited by Latias: 19 September 2012 - 12:53 AM

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: whats wrong in this code?

Posted 19 September 2012 - 06:13 AM

this looks to be working, can you tell me if this is valid?

DlgProc Proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

LOCAL	buffer[256]:BYTE

	
	.if uMsg == WM_INITDIALOG
		mov eax, wParam
		invoke GetDlgItem,hWnd,1002 ; progressbar setup
		mov hwndProgress,eax
		mov eax,1000
		mov CurrentStep,1000
		shl eax,16	;/* Shift Logical Left , Usage:SHL     dest,count */
		invoke SendMessage,hwndProgress,PBM_SETRANGE,0,eax
		invoke SendMessage,hwndProgress,PBM_SETSTEP,10,0
		
		xor Done,0 ; Percent static setup


Was This Post Helpful? 0
  • +
  • -

#5 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




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

Re: whats wrong in this code?

Posted 19 September 2012 - 05:30 PM

Does it work? If so, then it is valid.

You don't need line 7
 mov eax, wParam


You don't need line 16
xor Done,0 ; Percent static setup

Any variables in the .data? section are initialized to zero when your program is loaded. Your program is just starting in response to WM_INITDIALOG so the value will be 0 for Done. If you had a button that performs some operation that updated the progress bar, you would zero out Done at that point.
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: whats wrong in this code?

Posted 20 September 2012 - 01:59 PM

yes looks to be working nicely thanks again my master you rock :punk:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1