zoukankan      html  css  js  c++  java
  • 汇编 Hello Window [菜鸟]疑问

    Hello Window
      1 .386
    2 .model flat,stdcall
    3 option casemap:none
    4
    5 include user32.inc
    6 includelib user32.lib
    7 includelib kernel32.lib
    8 include kernel32.inc
    9 include gdi32.inc
    10 includelib gdi32.lib
    11 include windows.inc
    12
    13
    14 .data
    15 _swTitle db "测试标题",0
    16 _swContent db "hello Window",0
    17 _className db "MyClass",0
    18
    19 _btntzt db "button",0
    20 _szbutton db "&OK",0
    21 .data?
    22 _hInstance dd ?
    23 _hWinMan dd ?
    24 .const
    25
    26 szText db 'Win32 Assembly, Simple and powerful !',0
    27
    28 .code
    29
    30
    31
    32
    33 ;消息过程
    34 _ProcMain proc uses ebx edi esi hWnd,uMsg,wParam,lParam
    35
    36
    37
    38 ;--------------------------------------------------------------------------------
    39
    40 ;mov eax,uMsg
    41 ;.if eax==WM_CLOSE
    42 ;invoke MessageBox,NULL,offset _swTitle,offset _swContent,MB_OK
    43 ; ret
    44 ;.else
    45 ; invoke DefWindowProc,NULL,uMsg,wParam,lParam
    46 ; ret
    47 ;.endif
    48 ;ret
    49 ;--------------------------------------------------------------------------------
    50
    51 local @stPs:PAINTSTRUCT
    52 local @stRect:RECT
    53 local @hDc
    54
    55 mov eax,uMsg
    56 ;********************************************************************
    57 .if eax == WM_PAINT
    58 invoke BeginPaint,hWnd,addr @stPs
    59 mov @hDc,eax
    60
    61 invoke GetClientRect,hWnd,addr @stRect
    62 invoke DrawText,@hDc,addr szText,-1,\
    63 addr @stRect,\
    64 DT_SINGLELINE or DT_CENTER or DT_VCENTER
    65
    66 invoke EndPaint,hWnd,addr @stPs
    67 ;********************************************************************
    68 .elseif eax == WM_CLOSE
    69 invoke DestroyWindow,_hWinMan
    70 invoke PostQuitMessage,NULL
    71 .elseif eax == WM_CREATE
    72 invoke CreateWindowEx,NULL,offset _btntzt,offset _szbutton,WS_CHILD or WS_VISIBLE,10,10,65,22,hWnd,1,_hInstance,lParam
    73 ;********************************************************************
    74 .else
    75 invoke DefWindowProc,hWnd,uMsg,wParam,lParam
    76 ret
    77 .endif
    78 ;********************************************************************
    79 xor eax,eax
    80 ret
    81
    82 ret
    83 _ProcMain endp
    84 ;后缀EX扩展的意思。代码书写格式为易读性 st结构 h模块 _全局 @局部
    85 _Win32Main proc
    86 LOCAL @stWNDClass:WNDCLASSEX
    87 LOCAL @stMSG:MSG
    88
    89 invoke GetModuleHandle,NULL
    90 mov _hInstance,eax
    91 ;初始化
    92 invoke RtlZeroMemory,addr @stWNDClass,sizeof @stWNDClass
    93
    94 invoke LoadCursor,0,IDC_ARROW ;获取鼠标模块
    95 ;结构
    96 mov @stWNDClass.hCursor,eax
    97 ; push _hInstance;1
    98 ;pop @stWNDClass.hInstance;1
    99
    100 mov @stWNDClass.hInstance,offset _hInstance;2 上面的1 和这里的2 有什么不同 这两句为什么实现的不是一个效果 有什么不同?
    101 mov @stWNDClass.cbSize,sizeof WNDCLASSEX
    102 mov @stWNDClass.hbrBackground,COLOR_WINDOW
    103 mov @stWNDClass.lpszClassName,offset _className
    104 mov @stWNDClass.lpfnWndProc,offset _ProcMain
    105 mov @stWNDClass.style,CS_HREDRAW or CS_VREDRAW
    106
    107 invoke RegisterClassEx,addr @stWNDClass
    108
    109 ;创建窗口
    110 invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset _className,offset _swTitle,WS_OVERLAPPEDWINDOW,\
    111 100,100,444,555,\
    112 NULL,NULL,_hInstance,NULL
    113 mov _hWinMan,eax
    114 ;显示窗口
    115 invoke ShowWindow,_hWinMan,SW_SHOWNORMAL
    116 ;刷新绘制 发送WM_PAINT消息
    117 invoke UpdateWindow,_hWinMan
    118 ;消息循环
    119 ;GetMessage 如果取得的MSG是WM_QUIT EAX就等于0,否则非零
    120 ;PeekMessage 有消息返回非零,否则直接返回EAX等于0
    121 .while TRUE
    122
    123 invoke GetMessage,addr @stMSG,NULL,0,0
    124 .break .if eax==0
    125 invoke TranslateMessage,addr @stMSG
    126 invoke DispatchMessage,addr @stMSG
    127
    128
    129 ;--------------------------------------------------------------------------------
    130
    131 ;invoke PeekMessage,addr @stMSG,NULL,0,0,PM_REMOVE
    132 ;.if eax==0 有消息才去处理,所以这里应该是 .if eax 非空
    133 ; .break .if @stMSG.message==WM_QUIT
    134 ; invoke TranslateMessage,addr @stMSG
    135 ; invoke DispatchMessage,addr @stMSG
    136 ;.else
    137 ;code
    138 ;--------------------------------------------------------------------------------
    139 ;.endif
    140
    141 .endw
    142
    143 ret
    144
    145
    146 _Win32Main endp
    147
    148
    149 start:
    150 Call _Win32Main
    151 invoke ExitProcess,NULL
    152 end start


    诚心学习。希望在学习的道路上,得到点指点。

    1.peekmessage 我这样写和getMessage 功能上没什么差别呀。为什么就不行?

    2.在消息过程里面,为什么一定要处理WM_PAINT?在注册WINDOW后,不是已经创建了一个444 555 大小的窗口嘛?

  • 相关阅读:
    pip升级报错AttributeError: 'NoneType' object has no attribute 'bytes'
    在Windows中安装MySQL
    nginx配置成功,浏览器无法访问
    mysql 安装完以后没有mysql服务
    对字符串的切片操作
    linux下anaconda的安装和使用
    python学习笔记
    python学习笔记2018-9-18
    python学习笔记2018-9-17
    电脑必须用U盘引导盘才能进系统解决办法
  • 原文地址:https://www.cnblogs.com/yueyue184/p/2270246.html
Copyright © 2011-2022 走看看