| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1728 人关注过本帖
标题:郁闷了好几天了——关于罗云彬的win32的书的第七章那个时钟的程序
只看楼主 加入收藏
新手小生
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-2-16
结帖率:0
收藏
已结贴  问题点数:20 回复次数:7 
郁闷了好几天了——关于罗云彬的win32的书的第七章那个时钟的程序
我看到了GDI那一章了,里面有一个Clock.asm的程序,我照着上面得程序(Clock.asm)写了一遍,但是运行了却得不到那个钟的效果,我又把我的程序和光盘中的源代码对了一遍又一遍,都是一样的,但是我的结果却是这样的(论坛中不能贴图,我可以把我的那个.exe放在附件里,大家看看这个效果),可是重新编译光盘中的例子,却得到正确的结果,不知道为什么有没有高手能为小弟指点一下迷津,以下是我的源码


.386
.model    flat,stdcall
option    casemap:none

include        windows.inc
include        gdi32.inc
includelib    gdi32.lib
include        user32.inc
includelib    user32.lib
include        kernel32.inc
includelib    kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ICO_MAIN    equ    1000
ID_TIMER    equ    1
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        .data?
hInstance    dd    ?
hWinMain    dd    ?
dwCenterX    dd    ?
dwCenterY    dd    ?
dwRadius    dd    ?
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        .const
szClassName    db    'Clock',0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        .code
_CalcClockParam    proc
        local    @stRect:RECT

        invoke    GetClientRect,hWinMain,addr @stRect
        mov    eax,@stRect.right
        sub    eax,@stRect.left
        mov    ecx,@stRect.bottom
        sub    ecx,@stRect.top

        .if    ecx > eax
            mov    edx,eax
            sub    ecx,eax
            shr    ecx,1
            mov    dwCenterX,0
            mov    dwCenterY,ecx
        .else
            mov    edx,ecx
            sub    eax,ecx
            shr    eax,1
            mov    dwCenterX,eax
            mov    dwCenterY,0
        .endif
        shr    edx,1
        add    dwRadius,edx
        add    dwCenterX,edx
        add    dwCenterY,edx
        ret

_CalcClockParam    endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_dwPara180    dw    180
_CalcX        proc    _dwDegree,_dwRadius
        local    @dwReturn

        fild    dwCenterX
        fild    _dwDegree
        fldpi
        fmul
        fild    _dwPara180
        fdivp    st(1),st
        fsin
        fild    _dwRadius
        fmul
        fadd
        fistp    @dwReturn
        mov    eax,@dwReturn
        ret

_CalcX        endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_CalcY        proc    _dwDegree,_dwRadius
        local    @dwReturn

        fild    dwCenterY
        fild    _dwDegree
        fldpi
        fmul
        fild    _dwPara180
        fdivp    st(1),st
        fcos
        fild    _dwRadius
        fmul
        fsubp    st(1),st
        fistp    @dwReturn
        mov    eax,@dwReturn
        ret

_CalcY        endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_DrawDot    proc    _hDC,_dwDegreeInc,_dwRadius
        local    @dwNowDegree,@dwR
        local    @dwX,@dwY

        mov    @dwNowDegree,0
        mov    eax,dwRadius
        sub    eax,10
        mov    @dwR,eax
        .while    @dwNowDegree <= 360
            finit

            invoke    _CalcX,@dwNowDegree,@dwR
            mov    @dwX,eax
            invoke    _CalcY,@dwNowDegree,@dwR
            mov    @dwY,eax

            mov    eax,@dwX
            mov    ebx,eax
            mov    ecx,@dwY
            mov    edx,ecx
            sub    eax,_dwRadius
            add    ebx,_dwRadius
            sub    ecx,_dwRadius
            add    edx,_dwRadius
            invoke    Ellipse,_hDC,eax,ecx,ebx,edx

            mov    eax,_dwDegreeInc
            add    @dwNowDegree,eax
        .endw
        ret

_DrawDot    endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_DrawLine    proc    _hDC,_dwDegree,_dwRadiusAdjust
        local    @dwR
        local    @dwX1,@dwY1,@dwX2,@dwY2

        mov    eax,dwRadius
        sub    eax,_dwRadiusAdjust
        mov    @dwR,eax

        invoke    _CalcX,_dwDegree,@dwR
        mov    @dwX1,eax
        invoke    _CalcY,_dwDegree,@dwR
        mov    @dwY1,eax
        add    _dwDegree,180
        invoke    _CalcX,_dwDegree,10
        mov    @dwX2,eax
        invoke    _CalcY,_dwDegree,10
        mov    @dwY2,eax
        invoke    MoveToEx,_hDC,@dwX1,@dwY1,NULL
        invoke    LineTo,_hDC,@dwX2,@dwY2
        ret

_DrawLine    endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ShowTime    proc    _hWnd,_hDC
        local    @stTime:SYSTEMTIME

        pushad
        invoke    GetLocalTime,addr @stTime
        invoke    _CalcClockParam

        invoke    GetStockObject,BLACK_BRUSH
        invoke    SelectObject,_hDC,eax
        invoke    _DrawDot,_hDC,360/12,3
        invoke    _DrawDot,_hDC,360/60,1

        invoke    CreatePen,PS_SOLID,1,0
        invoke    SelectObject,_hDC,eax
        invoke    DeleteObject,eax
        movzx    eax,@stTime.wSecond
        mov    ecx,360/60
        mul    ecx
        invoke    _DrawLine,_hDC,eax,15

        invoke    CreatePen,PS_SOLID,2,0
        invoke    SelectObject,_hDC,eax
        invoke    DeleteObject,eax
        movzx    eax,@stTime.wMinute
        mov    ecx,360/60
        mul    ecx
        invoke    _DrawLine,_hDC,eax,20

        invoke    CreatePen,PS_SOLID,3,0
        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

        invoke    GetStockObject,NULL_PEN
        invoke    SelectObject,_hDC,eax
        invoke    DeleteObject,eax
        popad
        ret

_ShowTime    endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcWinMain    proc    uses ebx edi esi,hWnd,uMsg,wParam,lParam
        local    @stPs:PAINTSTRUCT
        
        mov    eax,uMsg
        .if    eax == WM_TIMER
            invoke InvalidateRect,hWnd,NULL,TRUE
        .elseif    eax == WM_PAINT
            invoke    BeginPaint,hWnd,addr @stPs
            invoke    _ShowTime,hWnd,eax
            invoke    EndPaint,hWnd,addr @stPs
        .elseif    eax == WM_CREATE
            invoke    SetTimer,hWnd,ID_TIMER,1000,NULL
        .elseif eax == WM_CLOSE
            invoke    KillTimer,hWnd,ID_TIMER
            invoke    DestroyWindow,hWinMain
            invoke    PostQuitMessage,NULL

        .else
            invoke    DefWindowProc,hWnd,uMsg,wParam,lParam
            ret
        .endif
        xor    eax,eax
        ret

_ProcWinMain    endp

_WinMain    proc
        local    @stWndClass:WNDCLASSEX
        local    @stMsg:MSG

        invoke    GetModuleHandle,NULL
        mov    hInstance,eax

        invoke    RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
        invoke    LoadIcon,hInstance,ICO_MAIN
        mov    @stWndClass.hIcon,eax
        mov    @stWndClass.hIconSm,eax
        invoke    LoadCursor,0,IDC_ARROW
        mov    @stWndClass.hCursor,eax

        push    hInstance
        pop    @stWndClass.hInstance
        mov    @stWndClass.cbSize,sizeof WNDCLASSEX
        mov    @stWndClass.style,CS_HREDRAW or CS_VREDRAW
        mov    @stWndClass.lpfnWndProc,offset _ProcWinMain
        mov    @stWndClass.hbrBackground,COLOR_WINDOW+1
        mov    @stWndClass.lpszClassName,offset szClassName
        invoke    RegisterClassEx,addr @stWndClass

        invoke    CreateWindowEx,WS_EX_CLIENTEDGE,\
                    offset szClassName,offset szClassName,\
                    WS_OVERLAPPEDWINDOW,\
                    100,100,250,270,\
                    NULL,NULL,hInstance,NULL
        mov    hWinMain,eax
        invoke    ShowWindow,hWinMain,SW_SHOWNORMAL
        invoke    UpdateWindow,hWinMain
        .while    TRUE
            invoke GetMessage,addr @stMsg,NULL,0,0
            .break .if eax == 0
            invoke TranslateMessage,addr @stMsg
            invoke DispatchMessage,addr @stMsg
        .endw
        ret
_WinMain    endp

start:
        call    _WinMain
        invoke    ExitProcess,NULL
        end    start
Clock.rar (2.28 KB)
搜索更多相关主题的帖子: 时钟 罗云彬 
2010-02-16 20:32
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:10 
Clock.rar (7.75 KB)


这个是原版 没问题~

您的是不是改过~
2010-02-17 00:20
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
       add    dwRadius,edx

貌似这个的问题~
2010-02-17 00:35
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
我又把我的程序和光盘中的源代码对了一遍又一遍,都是一样的

对了一遍又一遍 也不保证全对~~~~~

反正您的程序和第二版的不一样

       add    dwRadius,edx

这里是mov  不是加 要是加 当然会变大了 呵呵

最后 祝学习愉快  还有 要学会自己debug


2010-02-17 00:40
你们都要疼我哦
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:火星
等 级:贵宾
威 望:49
帖 子:1296
专家分:2746
注 册:2008-7-13
收藏
得分:10 
初始化后是正常的,马上又变了。说明问题由消息循环引起,应该窗口过程里面找原因。
从START开始,_WinMain 里一直到UpdateWindow都是正常的,因为这些都是 一次性 执行的,没重复。 第一次绘制没问题,说明问题出在重绘上,重绘由定时器引起,消息处理中InvalidateRect函数引发无效区域,产生WM_PAINT消息,强制绘制无效区域,
问题又到了_ShowTime过程里面,所以可继续在_ShowTime和参数的获得上找原因。
那你要是问第一次绘制不也是调用了_ShowTime了吗,为什么没出问题。。。 这个我也不知道了,因为这章我也没看,都是些半径角度啥的,头晕。

小妹,哥哥看你骨骼清奇,绝非凡人,将来必成大业,不如这样,你先把裤裤脱了,待哥哥为你开启灵窍,然后我们一起努力钻研如何
2010-02-17 04:12
新手小生
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-2-16
收藏
得分:0 
多谢几位斑竹的细心指点,是“add    dwRadius,edx”这个地方有问题,我已经把错误改过来了,再次真诚的感谢大家,祝大家新年快乐!
2010-02-17 10:11
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
以下是引用你们都要疼我哦在2010-2-17 04:12:35的发言:

初始化后是正常的,马上又变了。说明问题由消息循环引起,应该窗口过程里面找原因。
从START开始,_WinMain 里一直到UpdateWindow都是正常的,因为这些都是 一次性 执行的,没重复。 第一次绘制没问题,说明问题出在 ...

我以为就我一人没看~~~~
2010-02-17 19:07
新手小生
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-2-16
收藏
得分:0 
呵呵,差点忘记了,应该特别要感谢zklhp斑竹把那个打错的语句指出来。
2010-02-18 09:19
快速回复:郁闷了好几天了——关于罗云彬的win32的书的第七章那个时钟的程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024909 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved