鱼C论坛

 找回密码
 立即注册
查看: 3770|回复: 6

为什么win32汇编写的helloword程序不显示窗口,只在后台运行!?

[复制链接]
发表于 2013-1-27 16:10:44 | 显示全部楼层 |阅读模式
5鱼币
很简单的问题,麻烦大家帮忙看一下。搞定了5鱼币作为答谢,~


FirstWindow.rar

1.55 KB, 下载次数: 14

最佳答案

查看完整内容

犯了一些比较简单的错误,例如字符串在汇编代码是单引号,不是双引号等,贴我视频中的源码供参考:
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2013-1-27 16:10:45 | 显示全部楼层
犯了一些比较简单的错误,例如字符串在汇编代码是单引号,不是双引号等,贴我视频中的源码供参考:

  1. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  2. ; Sample code for < Win32ASM Programming 2nd Edition>
  3. ; by 罗云彬, http://asm.yeah.net
  4. ; change by 小甲鱼, http://www.fishc.com
  5. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  6. ; FirstWindow.asm
  7. ; 窗口程序的模板代码
  8. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  9. ; 使用 nmake 或下列命令进行编译和链接:
  10. ; ml /c /coff FirstWindow.asm
  11. ; Link /subsystem:windows FirstWindow.obj
  12. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  13.                 .386
  14.                 .model flat,stdcall
  15.                 option casemap:none
  16. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  17. ; Include 文件定义
  18. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  19. include                windows.inc
  20. include                gdi32.inc
  21. includelib        gdi32.lib
  22. include                user32.inc
  23. includelib        user32.lib
  24. include                kernel32.inc
  25. includelib        kernel32.lib
  26. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  27. ; 数据段
  28. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  29.                 .data?
  30. hInstance        dd                ?
  31. hWinMain        dd                ?

  32.                 .const
  33. szClassName                db        'MyClass',0
  34. szCaptionMain        db        'My first Window !',0
  35. szText                        db        'Welcome to fishc.com!',0
  36. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  37. ; 代码段
  38. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  39.                 .code
  40. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  41. ; 窗口过程
  42. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  43. _ProcWinMain        proc        uses ebx edi esi hWnd,uMsg,wParam,lParam
  44.                 local        @stPs:PAINTSTRUCT
  45.                 local        @stRect:RECT
  46.                 local        @hDc

  47.                 mov        eax,uMsg
  48. ;********************************************************************
  49.                 .if        eax ==        WM_PAINT
  50.                         invoke        BeginPaint,hWnd,addr @stPs
  51.                         mov        @hDc,eax

  52.                         invoke        GetClientRect,hWnd,addr @stRect
  53.                         invoke        DrawText,@hDc,addr szText,-1,\
  54.                                 addr @stRect,\
  55.                                 DT_SINGLELINE or DT_CENTER or DT_VCENTER

  56.                         invoke        EndPaint,hWnd,addr @stPs
  57. ;********************************************************************
  58.                 .elseif        eax ==        WM_CLOSE
  59.                         invoke        DestroyWindow,hWinMain
  60.                         invoke        PostQuitMessage,NULL
  61. ;********************************************************************
  62.                 .else
  63.                         invoke        DefWindowProc,hWnd,uMsg,wParam,lParam
  64.                         ret
  65.                 .endif
  66. ;********************************************************************
  67.                 xor        eax,eax
  68.                 ret

  69. _ProcWinMain        endp
  70. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  71. _WinMain        proc
  72.                 local        @stWndClass:WNDCLASSEX
  73.                 local        @stMsg:MSG

  74.                 invoke        GetModuleHandle,NULL
  75.                 mov        hInstance,eax
  76.                 invoke        RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
  77. ;********************************************************************
  78. ; 注册窗口类
  79. ;********************************************************************
  80.                 invoke        LoadCursor,0,IDC_ARROW
  81.                 mov        @stWndClass.hCursor,eax
  82.                 push        hInstance
  83.                 pop        @stWndClass.hInstance
  84.                 mov        @stWndClass.cbSize,sizeof WNDCLASSEX
  85.                 mov        @stWndClass.style,CS_HREDRAW or CS_VREDRAW
  86.                 mov        @stWndClass.lpfnWndProc,offset _ProcWinMain
  87.                 mov        @stWndClass.hbrBackground,COLOR_WINDOW + 1
  88.                 mov        @stWndClass.lpszClassName,offset szClassName
  89.                 invoke        RegisterClassEx,addr @stWndClass
  90. ;********************************************************************
  91. ; 建立并显示窗口
  92. ;********************************************************************
  93.                 invoke        CreateWindowEx,WS_EX_CLIENTEDGE,offset szClassName,offset szCaptionMain,\
  94.                         WS_OVERLAPPEDWINDOW,\
  95.                         100,100,600,400,\
  96.                         NULL,NULL,hInstance,NULL
  97.                 mov        hWinMain,eax
  98.                 invoke        ShowWindow,hWinMain,SW_SHOWNORMAL
  99.                 invoke        UpdateWindow,hWinMain
  100. ;********************************************************************
  101. ; 消息循环
  102. ;********************************************************************
  103.                 .while        TRUE
  104.                         invoke        GetMessage,addr @stMsg,NULL,0,0
  105.                         .break        .if eax        == 0
  106.                         invoke        TranslateMessage,addr @stMsg
  107.                         invoke        DispatchMessage,addr @stMsg
  108.                 .endw
  109.                 ret

  110. _WinMain        endp
  111. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  112. start:
  113.                 call        _WinMain
  114.                 invoke        ExitProcess,NULL
  115. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  116.                 end        start
复制代码


评分

参与人数 1贡献 +5 收起 理由
s0512 + 5 热爱鱼C^_^

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-1-27 16:13:46 | 显示全部楼层
着急啊,谢谢各位
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-1-28 09:48:30 | 显示全部楼层

你视频里的源代码我都有………………我把双引号改为单引号还是有错啊,有个人告诉我是窗口过程中的错误,我实在看不出来

评分

参与人数 1鱼币 +1 收起 理由
メ㊣逆ご帅☆ + 1 我调试了半天也没搞定。反正知道 CreateWin.

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-1-28 12:20:54 | 显示全部楼层
错误找到了,是窗口过程的 xor eax ,eax 这个语句应该去掉,谢谢各位!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-1-28 12:27:52 | 显示全部楼层
小甲鱼 发表于 2013-1-27 16:10
犯了一些比较简单的错误,例如字符串在汇编代码是单引号,不是双引号等,贴我视频中的源码供参考:

弱弱地告诉小鲫鱼,单引号和双引号都行:)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-1-28 16:40:44 | 显示全部楼层
大笨钟 发表于 2013-1-28 12:27
弱弱地告诉小鲫鱼,单引号和双引号都行:)

哈哈,我自己犯了习惯性错误~
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-3 02:18

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表