winapi - 在汇编中注册ClassEx

标签 winapi assembly masm32

我正在尝试手动调用 RegisterClassEx Windows API,而不在 .data 部分使用 WNDCLASS 结构,我需要仅使用 push 指令创建此结构。

有人可以帮我吗?

非常感谢

最佳答案

事实上,您可以轻松地做您想做的事。您只需要小心地正确计算结构中每个元素的地址即可。但这也是一项简单的任务...;)

请查看我所做的代码:

WinMain:
    push ebp
    mov ebp, esp
    add esp, -50h

    push 7F00h
    push 0h
    call LoadIconA

    mov ebx, eax

    push 7F00h
    push 0h
    call LoadCursorA
    ;eax = return of LoadCursorA
    ;ebx = return of LoadIconA

    mov dword ptr ss:[ebp-30h], 30h                 ;WNDCLASSEX.cbSize,           dd    WNDCLASSEX_size
    mov dword ptr ss:[ebp-2Ch], 3h                  ;WNDCLASSEX.style,            dd    CS_VREDRAW + CS_HREDRAW
    mov dword ptr ss:[ebp-28h], WndProc             ;WNDCLASSEX.lpfnWndProc,      dd    WndProc
    mov dword ptr ss:[ebp-24h], 0h                  ;WNDCLASSEX.cbClsExtra,       dd    NULL
    mov dword ptr ss:[ebp-20h], 0h                  ;WNDCLASSEX.cbWndExtra,       dd    NULL
    mov dword ptr ss:[ebp-1Ch], 0h                  ;WNDCLASSEX.hInstance,        dd    NULL
    mov dword ptr ss:[ebp-18h], ebx                 ;WNDCLASSEX.hIcon,            dd    return of LoadIconA
    mov dword ptr ss:[ebp-14h], eax                 ;WNDCLASSEX.hIconSm,          dd    return of LoadCursorA
    mov dword ptr ss:[ebp-10h], 06h                 ;WNDCLASSEX.hbrBackground,    dd    COLOR_BTNFACE + 1
    mov dword ptr ss:[ebp-0Ch], 0h                  ;WNDCLASSEX.lpszMenuName,     dd    NULL
    mov dword ptr ss:[ebp-08h], offset WndProc      ;WNDCLASSEX.lpszClassName,    dd    offset of ClassName
    mov dword ptr ss:[ebp-04h], ebx                 ;WNDCLASSEX.hCursor,          dd    return of LoadIconA

    lea eax,[ebp-30h]
    push eax
    call RegisterClassEx

您只需将其放在调用 CreateWindow 之前即可。

有任何疑问就喊吧。

PS.: 请记住,WndProc 是汇编程序的循环过程

关于winapi - 在汇编中注册ClassEx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4014264/

相关文章:

斐波那契汇编程序

汇编语言介绍

c - 使用 WM_NCHITTEST 时捕获鼠标左键时出现问题

assembly - 如何将较小的值弹出到寄存器中

assembly - 我们何时以及为何签署扩展并使用带有 mul/div 的 cdq?

windows - 在 win xp 上组装 COM 可执行文件

windows - 如何更改 MASM32 中的链接器设置

c++ - WinApi:CW_USEDEFAULT 与 CW_DEFAULT

windows - WideCharToMultiByte 何时 lpUsedDefaultChar 为 true?

c# - 适用于 Windows 桌面的最佳计时器是什么?