Basically I want to put the percentage number in a progressbar whilst the bar is filling up. I have searched Google and have come up with a blank, there was a post on this site, but it appears not have been resolved....
So, here's what I have done so far :
I use the DrawText to set the text which appears to work, until the progressbar moves over the text and wipes it out !
.elseif uMsg==WM_PAINT
invoke BeginPaint,hwndProgress, addr ps
invoke GetClientRect,hwndProgress, addr rect
invoke SetBkMode,ps.PAINTSTRUCT.hdc,TRANSPARENT
invoke SetTextColor, ps.PAINTSTRUCT.hdc,ID_RED_COLOR
mov esi,eax
invoke DrawText, ps.PAINTSTRUCT.hdc,addr szTestString,-1,addr ps.PAINTSTRUCT.rcPaint,DT_CENTER or DT_VCENTER or DT_SINGLELINE
invoke EndPaint, hwndProgress,addr ps
Any idea's what I am doing wrong ?
I then thought about creating a Progressbar out of a Static control set to BitMap, but this got me nowhere over a very long period of time........
So if anyone can point me in the right direction, would be grateful.
Thanks in advance...
The snippet is not sufficient to judge what's wrong - complete code would be much better. So I can only ask:
- have you tried DefWindowProc before painting?
- what are you returning?
ok, here's the main module. The Progressbar.inc just has declares etc.
-------------------------------
.386
.model flat,stdcall
option casemap:none
include Progressbar.inc
.code
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke GetCommandLine
invoke InitCommonControls
mov iccex.dwSize,sizeof INITCOMMONCONTROLSEX ;prepare common control structure
mov iccex.dwICC,ICC_DATE_CLASSES
invoke InitCommonControlsEx,addr iccex
invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
invoke ExitProcess,eax
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style,CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc,OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,DLGWINDOWEXTRA
push hInst
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW
mov wc.lpszMenuName,OFFSET MenuName
mov wc.lpszClassName,OFFSET ClassName
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 CreateDialogParam,hInstance,addr DlgName,NULL,addr WndProc,NULL
invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWnd
.while TRUE
invoke GetMessage,addr msg,NULL,0,0
.BREAK .if !eax
invoke TranslateMessage,addr msg
invoke DispatchMessage,addr msg
.endw
mov eax,msg.wParam
ret
WinMain endp
WndProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL buffer[256]:BYTE
LOCAL rect:RECT
local ps: PAINTSTRUCT
mov eax,uMsg
.if eax==WM_INITDIALOG
push hWin
pop hWnd
;/* progressbar setup */
invoke GetDlgItem,hWin,IDC_PGB1 ;1001
mov hwndProgress,eax
mov eax,TotalQuestions
mov CurrentStep,eax
shl eax,16
invoke SendMessage,hwndProgress,PBM_SETRANGE,0,eax
invoke SendMessage,hwndProgress,PBM_SETSTEP,1,0
; invoke SendMessage,hwndProgress,PBM_SETBKCOLOR,0, 0ffffFFh ;COLOR_WINDOW
; invoke SendMessage,hwndProgress,PBM_SETBARCOLOR,0, 0ff0000h
invoke GetDlgItem,hWin,IDC_BTN1 ;start button 2001
mov hBTN1,eax
invoke GetDlgItem,hWin,IDC_BTN2 ;Pause button 2002
mov hBTN2,eax
.elseif eax==WM_COMMAND
mov eax,wParam
and eax,0FFFFh
.if eax==IDC_BTN1
invoke SendMessage,hwndProgress,PBM_STEPIT,0,0
.endif
.elseif eax==WM_PAINT
invoke BeginPaint,hwndProgress, addr ps
invoke GetClientRect,hwndProgress, addr rect
invoke SetBkMode,ps.PAINTSTRUCT.hdc,TRANSPARENT
invoke SetTextColor, ps.PAINTSTRUCT.hdc,ID_RED_COLOR
mov esi,eax
invoke DrawText, ps.PAINTSTRUCT.hdc,addr szTestString,-1,addr ps.PAINTSTRUCT.rcPaint,DT_CENTER or DT_VCENTER or DT_SINGLELINE
invoke EndPaint, hwndProgress,addr ps
; invoke DefWindowProc,hWin,uMsg,wParam,lParam
; ret
.elseif eax==WM_CLOSE
invoke DestroyWindow,hWin
.elseif eax==WM_DESTROY
invoke PostQuitMessage,NULL
.else
invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret
.endif
xor eax,eax
ret
WndProc endp
end start
-------------------------------
Thanks
Try shifting the invoke DefWindowProc,hWin,uMsg,wParam,lParam before the BeginPaint. And return zero:
xor eax, eax
ret
The logic is: Windows needs to paint the area, so let it do the job with DefWindowProc, then afterwards add your own stuff.