The MASM Forum

General => The Campus => Topic started by: hfheatherfox07 on August 21, 2012, 01:36:55 PM

Title: Timer Problems
Post by: hfheatherfox07 on August 21, 2012, 01:36:55 PM
I am Trying to make this text flicker ...it works than Doesn't ...what am I missing ?
I am trying to make text flash :biggrin:

Also If I wanted to set the timer of a button how to do that?

you have:
Set timer
and
WM_TIMER

So how to set trimmer of a button? I tried adding WM_NOTIFY
Title: Re: Timer Problems
Post by: MichaelW on August 21, 2012, 03:34:57 PM
I still don't understand the reason for painting in a separate procedure that is not called from the WM_PAINT handler. Per Microsoft, "An application should not call BeginPaint except in response to a WM_PAINT message." This may be the reason for the strange behavior you are seeing in your thread here:

http://masm32.com/board/index.php?topic=592.msg4871#msg4871


;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================

IDC_SHOW equ 1000
IDC_HIDE equ 1001

;==============================================================================
    .data
        hFont dd 0
        fShow dd 0
        fOn   dd 0
        str1  db "my other brother darryl",0
    .code

;==============================================================================

;------------------------------------------------------------------
; This is a modification of the MakeFont procedure from the MASM32
; examples, with the height and width specifications replaced with
; a point size specification.
;------------------------------------------------------------------

MakeFont proc pointSize:dword,weight:dword,italic:dword,lpFontName:dword

    invoke GetDC, 0
    invoke GetDeviceCaps, eax, LOGPIXELSY
    mul   pointSize
    xor   edx, edx
    mov   ecx, 72
    div   ecx

    invoke CreateFont,eax,0,NULL,NULL,weight,italic,NULL,NULL,
                      DEFAULT_CHARSET,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,
                      PROOF_QUALITY,DEFAULT_PITCH or FF_DONTCARE,
                      lpFontName
    ret

MakeFont endp

;==============================================================================

IDC_SHOW  equ 1000
IDC_CLEAR equ 1001

;==============================================================================

DlgProc proc uses ebx hwndDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    LOCAL ps:PAINTSTRUCT, rc:RECT, hdc:HDC

    SWITCH uMsg

        CASE WM_INITDIALOG

            invoke MakeFont, 24, FW_NORMAL, TRUE, chr$("Arial Narrow")
            mov hFont, eax

            invoke SetTimer, hwndDlg, 1, 30, NULL

        CASE WM_TIMER

            not fOn
            invoke InvalidateRect, hwndDlg, NULL, TRUE

        CASE WM_PAINT

            invoke BeginPaint, hwndDlg, ADDR ps
            invoke SetTextColor, ps.hdc, 000000ffh
            invoke SelectObject, ps.hdc, hFont
            push eax
            .IF fShow && fOn
                invoke SetBkMode, ps.hdc, TRANSPARENT
                invoke TextOut, ps.hdc, 42, 50, ADDR str1, SIZEOF str1 - 1
            .ENDIF
            pop eax
            invoke SelectObject, ps.hdc, eax
            invoke EndPaint, hwndDlg, ADDR ps

        CASE WM_COMMAND

            SWITCH wParam
                CASE IDC_SHOW
                    mov fShow, -1
                    invoke InvalidateRect, hwndDlg, NULL, TRUE
                CASE IDC_HIDE
                    mov fShow, 0
                    invoke InvalidateRect, hwndDlg, NULL, TRUE
                CASE IDCANCEL
                    invoke EndDialog, hwndDlg, 0
            ENDSW

        CASE WM_CLOSE

            invoke DeleteObject, hFont

            invoke KillTimer, hwndDlg, 1

            invoke EndDialog, hwndDlg, 0

    ENDSW

    return 0

DlgProc endp

;==============================================================================
start:
;==============================================================================

    Dialog "Test", "MS Sans Serif",10, \
           WS_OVERLAPPED or WS_SYSMENU or WS_CLIPCHILDREN or DS_CENTER, \
           2,0,0,150,100,1024
    DlgButton "&Show",WS_TABSTOP,35,60,25,10,IDC_SHOW
    DlgButton "&Hide",WS_TABSTOP,85,60,25,10,IDC_HIDE
    CallModalDialog 0,0,DlgProc,0
    exit

;==============================================================================
end start
Title: Re: Timer Problems
Post by: hfheatherfox07 on August 21, 2012, 03:37:27 PM
Thank You !
I am using the WM_PAINT handler For something else....Drawing other text  ;)
Title: Re: Timer Problems
Post by: MichaelW on August 21, 2012, 03:43:11 PM
Why can't you do both from your WM_PAINT handler?
Title: Re: Timer Problems
Post by: hfheatherfox07 on August 21, 2012, 03:47:40 PM
I did not think that was possible if you are drawing 2 or 3 texts on the same screen
That would definitely would have made my life easier....

They are different font sizes and colours on different size on the screen :(
Title: Re: Timer Problems
Post by: hfheatherfox07 on August 21, 2012, 04:15:58 PM
Quote from: MichaelW on August 21, 2012, 03:34:57 PM
I still don't understand the reason for painting in a separate procedure that is not called from the WM_PAINT handler. Per Microsoft, "An application should not call BeginPaint except in response to a WM_PAINT message." This may be the reason for the strange behavior you are seeing in your thread here:

http://masm32.com/board/index.php?topic=592.msg4871#msg4871


I did Not think you can combine these two...that have different fonts and font sizes ..also on a bigger screen
have one central text and maybe more with buttons ( to signify response to something user did)
I do not see how to do with out procs or threads
Title: Re: Timer Problems
Post by: hfheatherfox07 on August 21, 2012, 04:49:43 PM
How would you just flash that text on the screen
With out buttons?with out a proc ?
I don't see it?
Maybe it getting late it is 245 am ....
I will have a fresh look in the morning :)
Title: Re: Timer Problems
Post by: dedndave on August 21, 2012, 11:38:05 PM
during WM_PAINT, you can select font #1, background color #1, foreground color #1, draw text,
then select font #2, background color #2, foreground color #2, then draw some more text
you can mix as many fonts and colors as you like

attached is a little program that flashes, which shows the use of SetTimer, KillTimer, and WM_TIMER

in your case, you will want to handle WM_TIMER by changing some attribute, like color, then
forcing an update with either InvalidateRect/UpdateWindow or with RedrawWindow
that will cause WM_PAINT to be sent
Title: Re: Timer Problems
Post by: hfheatherfox07 on August 21, 2012, 11:44:56 PM
Thanks dedndave

If you look at the "Combine these 2.zip" that Is what kind of stuff I am trying to combine .....
I will look at your example and try and make it work for me  8)
Title: Re: Timer Problems
Post by: hfheatherfox07 on August 22, 2012, 02:21:57 AM
When I try to use just a timer with no buttons it dose not work ... even if in the timer proc I invalidate the rect
I am probably missing something very small  ::)

Title: Re: Timer Problems
Post by: dedndave on August 22, 2012, 03:06:55 AM
take a closer look at my timer example   :P

1) i do not use a dword for either the event ID, nor the elapse time - i use EQUates

2) i do not store the value returned by SetTimer
although, you could check it for zero, meaning the timer wasn't created
(your code overwrites the ID - oops)

3) your timer is being created, and is running
and - you invalidate the rectangle
however, you haven't changed anything to make it do something different
change the text - change a color value - change something that will be visible
THEN, invalidate the rectangle

4) after invalidating the rectangle, use UpdateWindow to tell the OS to send a paint message
i sometimes prefer RedrawWindow, because it is a single function call
Title: Re: Timer Problems
Post by: hfheatherfox07 on August 22, 2012, 04:57:20 PM
@ dedndave
That was the Best explanation I got for timer  :t

I was not kidding when I said "I am probably missing something very small  ::)"

I marvel at my own stupidity some times  :redface:

All I had to do is Initiate the timer after I set it ....LOL

; setup Timer
INVOKE  SetTimer,hWnd,IDT_TIME,TIMER_ELAPSE,NULL

; Initiate Timer
mov fShow, -1
invoke InvalidateRect, hWnd, NULL, TRUE



:redface: :redface: :redface:
Title: Re: Timer Problems
Post by: hfheatherfox07 on August 23, 2012, 06:29:11 AM
Quote from: MichaelW on August 21, 2012, 03:43:11 PM
Why can't you do both from your WM_PAINT handler?

You are so right ... I got hung up on the procs......  :icon_redface: :icon_redface: :icon_redface: