News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

recolor my stockobject

Started by Younth, September 13, 2009, 03:36:44 AM

Previous topic - Next topic

Younth

Hi !
There is a little problem in my process,i used a local variable (asd) to determine how to recolor my stockobject,but It seems not effective at all
here the codes:

_ShowTimec   proc uses ebx _hWnd,_hDC, asd:DWORD
      local   @stTime:SYSTEMTIME

      pushad
      invoke   GetLocalTime,addr @stTime
      invoke   _CalcClockParam
                     .if asd==1
         invoke   GetStockObject,LTGRAY_BRUSH
                               .else
                                   invoke      GetStockObject,BLACK_BRUSH
                               .endif
      invoke   SelectObject,_hDC,eax
      invoke   _DrawDot,_hDC,360/12,3   ;draw12 big points
      invoke   _DrawDot,_hDC,360/60,1   ;drawing 60 little points
                     .if asd==1
       invoke   CreatePen,PS_SOLID,1,0
                               .else
                                 invoke      CreatePen,PS_SOLID,1,245
                               .endif
      invoke   SelectObject,_hDC,eax
      invoke   DeleteObject,eax
      movzx   eax,@stTime.wSecond
      mov   ecx,360/60
      mul   ecx         ;seconddegree = second * 360/60
      invoke   _DrawLine,_hDC,eax,15
      .if asd==1
      invoke   CreatePen,PS_SOLID,2,0
                                .else
                                 invoke      CreatePen,PS_SOLID,2,245
                               .endif

      invoke   SelectObject,_hDC,eax
      invoke   DeleteObject,eax
      movzx   eax,@stTime.wMinute
      mov   ecx,360/60
      mul   ecx         ;minute =minute* 360/60
      invoke   _DrawLine,_hDC,eax,20
      .if asd==1
      invoke   CreatePen,PS_SOLID,5,0
                                .else
                                    invoke      CreatePen,PS_SOLID,5,245
                                 .endif

      invoke   SelectObject,_hDC,eax
      invoke   DeleteObject,eax
      movzx   eax,@stTime.wHour
      .if   eax >=   12
         sub   eax,12
      .endif
      mov   ecx,360/12
      mul   ecx
      movzx   ecx,@stTime.wMinute
      shr   ecx,1
      add   eax,ecx
      invoke   _DrawLine,_hDC,eax,30  ;hoursdegree=(hours%12)\12*360+分/60*30
      invoke   GetStockObject,NULL_PEN
      invoke   SelectObject,_hDC,eax
      invoke   DeleteObject,eax
      popad
      ret

_ShowTimec   endp


the codes in WinProc

local asd:DWORD
MOV asd,1

.if eax==WM_CHAR
                  push wParam
                  pop  @char
            .if wParam==99             ;char "c"
                     .if asd==1
                     mov asd,0
                     .else
                     mov asd,1
                     .endif
                   invoke   BeginPaint,hWinMain,addr @stPS
                   invoke _ShowTimec,hWinMain,eax,asd
                   invoke   EndPaint,hWinMain,addr @stPS
            .endif
and i'm sure on the other place,i have never changed or used this local variable(asd)
when i bulid them all, there was no warnings or errors
who can help me ?

sinsi

Because it's a local variable, once your wndproc returns it is gone. Use a global variable (in .data or .data?) and it will keep its value in between calls to your wndproc.
Light travels faster than sound, that's why some people seem bright until you hear them.

Younth

 Yeah ! You're quite right
I fogot the winproc is just a function ,too. the gloable asd make it works .the real main function (like the main() in C or C++) is controled by these codes
:
.while   TRUE
         invoke   GetMessage,addr @stMsg,NULL,0,0
         .break   .if eax   == 0
         invoke   TranslateMessage,addr @stMsg
         invoke   DispatchMessage,addr @stMsg
      .endw

Is that right ?
Thank you ,sinsi, and  also your answering so soon ! haha  :clap:

sinsi

Yes, that is your process's message loop (message pump), you tell the window manager to 'dispatch' the message to the wndproc of the right one of your windows.
Light travels faster than sound, that's why some people seem bright until you hear them.