program Project1;

{ Types and Structures Definition }
type
  WNDCLASSEX = packed record
    cbSize: LongWord;
    style: LongWord;
    lpfnWndProc: Pointer;
    cbClsExtra: Integer;
    cbWndExtra: Integer;
    hInstance: LongWord;
    hIcon: LongWord;
    hCursor: LongWord;
    hbrBackground: LongWord;
    lpszMenuName: PAnsiChar;
    lpszClassName: PAnsiChar;
    hIconSm: LongWord;
  end;

POINT = packed record
    X: Longint;
    Y: Longint;
  end;

MSG = packed record
    hwnd: LongWord;
    message: LongWord;
    wParam: Longint;
    lParam: Longint;
    time: LongWord;
    pt: POINT;
  end;

{ Application Specific Variables and constants }
const
  szBuf = 255;                               // Size of buffer used to handle strings
  WndClsSize = SizeOf(WNDCLASSEX);           // Size of WNDCLASSEX Structure
  wnd_class: PChar = 'TMainWindow';          // Main window class name.
  wnd_title: PChar = 'Closer to the Metal';  // Main window caption.
var
  wcx      : WNDCLASSEX;                     // Main window structure
  msgbuf   : MSG;                            // Message structure
  hwnd     : LongWord;                       // A window handle

{ Windows Specific Constants }
const
  { Class styles }
  CS_VREDRAW = LongWord(1);
  CS_HREDRAW = LongWord(2);
  CS_GLOBALCLASS = $4000;

{ Color Types }
  COLOR_WINDOW = 5;

{ Window Styles }
  WS_OVERLAPPED  = 0;
  WS_CAPTION     = $C00000;      { WS_BORDER or WS_DLGFRAME  }
  WS_SYSMENU     = $80000;
  WS_THICKFRAME  = $40000;
  WS_MINIMIZEBOX = $20000;
  WS_MAXIMIZEBOX = $10000;
  WS_VISIBLE     = $10000000;

{ Common Window Styles }
  WS_OVERLAPPEDWINDOW = (WS_VISIBLE or WS_OVERLAPPED or WS_CAPTION
    or WS_SYSMENU or WS_THICKFRAME or WS_MINIMIZEBOX or WS_MAXIMIZEBOX);

{ Messages }
  WM_DESTROY  = $0002;

{ Windows API's }
function GetModuleHandle(lpModuleName: PChar): HMODULE;
  stdcall; external 'kernel32.dll' name 'GetModuleHandleA';

procedure ExitProcess(uExitCode: LongWord);
  stdcall; external 'kernel32.dll' name 'ExitProcess';

function DefWindowProc(hWnd: LongWord; Msg: LongWord;
  wParam: Longint; lParam: Longint): Longint;
  stdcall; external 'user32.dll' name 'DefWindowProcA';

function RegisterClassEx(const WndClass: WNDCLASSEX): Word;
  stdcall; external 'user32.dll' name 'RegisterClassExA';

function CreateWindowEx(dwExStyle: LongWord; lpClassName: PChar;
  lpWindowName: PChar; dwStyle: LongWord;
  X, Y, nWidth, nHeight: Integer; hWndParent: LongWord;
  hMenu: LongWord; hInstance: LongWord; lpParam: Pointer): LongWord;
  stdcall; external 'user32.dll' name 'CreateWindowExA';

function GetMessage(var lpMsg: MSG; hWnd: LongWord;
  wMsgFilterMin, wMsgFilterMax: LongWord): LongBool;
  stdcall; external 'user32.dll' name 'GetMessageA';

function DispatchMessage(const lpMsg: MSG): Longint;
  stdcall; external 'user32.dll' name 'DispatchMessageA';

procedure PostQuitMessage(nExitCode: Integer);
  stdcall; external 'user32.dll' name 'PostQuitMessage';

{ Windows Procedure }
function WindowProc(hWnd, Msg: LongWord; wParam, lParam: Longint): Longint; stdcall;
asm
    // The inline assembler will take care of setting the stack,
    // preserving the registers and returning.
    mov    EAX, [Msg]
    // WM_DESTROY:
    cmp     EAX, WM_DESTROY
    je      @@m_destroy
    // All Other Messages:
    jmp     @@defwndproc
@@m_destroy:
    push    0
    call    PostQuitMessage // Quit.
    jmp     @@return
@@defwndproc:
    push    [lParam]
    push    [wParam]
    push    [Msg]
    push    [hWnd]
    call    DefWindowProc
    jmp     @@finish
@@return:
    xor     eax,eax
@@finish:
end;

{ Main Program Block }
asm
  // GetModuleHandle with a NULL pointer gives us the instance handle
  // of the EXE file. This is the module that will "own" the window class.
    push    0
    call    GetModuleHandle

// Define our window properties:
    mov     [wcx.cbSize], WndClsSize;
    mov     [wcx.style], CS_VREDRAW or CS_HREDRAW or CS_GLOBALCLASS
    mov     [wcx.lpfnWndProc], offset WindowProc
    mov     [wcx.cbClsExtra], 0
    mov     [wcx.cbWndExtra], 0
    mov     eax, hInstance
    mov     [wcx.hInstance], EAX
    mov     [wcx.hIcon], 0
    mov     [wcx.hCursor], 0
    mov     [wcx.hbrBackground], COLOR_WINDOW + 1
    mov     dword ptr [wcx.lpszMenuName], 0
    mov     dword ptr [wcx.lpszClassName], offset wnd_class
    mov     [wcx.hIconSm], 0

mov     EAX, wnd_class
    mov     [wcx.lpszClassName], EAX

// Register window class:
    push    offset wcx
    call    RegisterClassEx

// Create window:
    push    0                       // lpParam
    push    [wcx.hInstance]         // hInstance
    push    0                       // hMenu
    push    0                       // hWndParent
    push    200                     // nHeight
    push    200                     // nWidth
    push    100                     // y (top)
    push    100                     // x (left)
    push    WS_OVERLAPPEDWINDOW     // dwStyle
    mov     EAX, wnd_title          // lpWindowName
    push    EAX
    mov     EAX, wnd_class          // lpClassName
    push    EAX
    push    0                       // dwExStyle
    call    CreateWindowEx
    mov     hwnd, EAX

// Message Loop/Pump:
@@msg_loop:
    push    0                       // wMsgFileterMax
    push    0                       // wMsgFilterMin
    push    0                       // hWnd  (0 = all windows)
    push    offset msgbuf           // lpMsg
    call    GetMessage
    cmp     eax, 0                  // Returns 0 (zero) if WM_QUIT
    jz      @@end_loop
    push    offset msgbuf
    call    DispatchMessage
    jmp     @@msg_loop
@@end_loop:

// Terminating the program:
    push    0                       // Error return code.
    call    ExitProcess
end.

http://blog.csdn.net/diligentcatrich/article/details/9497503

delphi写的整合汇编与api的简单的窗口程序的更多相关文章

  1. Win32汇编学习(3):简单的窗口

    这次我们将写一个 Windows 程序,它会在桌面显示一个标准的窗口,以此根据代码来学习如何创建一个简单的窗口. 理论: Windows 程序中,在写图形用户界面时需要调用大量的标准 Windows ...

  2. win32汇编简单实现窗口程序

    .386 .model flat,stdcall option casemap:none ;========================== ;include部分 include windows. ...

  3. (Delphi)第一个Windows 32 API的窗口程序

    program Project1; uses Winapi.Windows, Winapi.messages; {$R *.res} const className = 'MyDelphiWindow ...

  4. Win32编程API 基础篇 -- 2.一个简单的窗口 根据英文教程翻译

    一个简单的窗口 例子:简单的窗口 有时人们在IRC提问,”我应该怎样制作一个窗口”...嗯,这恐怕不是完全这么简单好回答!其实这并不难一旦你明白你在做什么,但在你得到一个可展示的窗口之前还有一些事情需 ...

  5. Nginx+Lua+Redis整合实现高性能API接口 - 网站服务器 - LinuxTone | 运维专家网论坛 - 最棒的Linux运维与开源架构技术交流社区! - Powered by Discuz!

    Nginx+Lua+Redis整合实现高性能API接口 - 网站服务器 - LinuxTone | 运维专家网论坛 - 最棒的Linux运维与开源架构技术交流社区! - Powered by Disc ...

  6. Delphi写的DLL,OCX中多线程一个同步问题

    Delphi写的DLL,OCX中如果使用了TThread.Synchronze(Proc),可能导致线程死锁,原因是无法唤醒EXE中主线程, Synchronze并不会进入EXE主线程消息队列. 下面 ...

  7. 用delphi写多屏幕程序

    http://blog.csdn.net/zyyjc/article/details/6530728 别现在有些POS机是双屏幕的(比如卡西瓦POS机),一个屏幕可以当顾客显示屏用,当闲时也可以显示一 ...

  8. springboot学习-jdbc操作数据库--yml注意事项--controller接受参数以及参数校验--异常统一管理以及aop的使用---整合mybatis---swagger2构建api文档---jpa访问数据库及page进行分页---整合redis---定时任务

    springboot学习-jdbc操作数据库--yml注意事项--controller接受参数以及参数校验-- 异常统一管理以及aop的使用---整合mybatis---swagger2构建api文档 ...

  9. 32位汇编第二讲,编写窗口程序,加载资源,响应消息,以及调用C库函数

    32位汇编第二讲,编写窗口程序,加载资源,响应消息,以及调用C库函数 (如果想看所有代码,请下载课堂资料,里面有所有代码,这里会讲解怎么生成一个窗口程序) 一丶32位汇编编写Windows窗口程序 首 ...

随机推荐

  1. struts项目中添加的jar包

    一般我们使用struts时,添加的jar如下: commons-fileupload-1.2.1.jar commons-io-1.3.2.jar freemarker-2.3.16.jar java ...

  2. javascript 数据结构和算法读书笔记 > 第三章 列表

    1. 结构分析 列表首先要有以下几个属性: listSize 长度 pos 当前位置 dataStore 数据 我们要通过以下方法对上面三个属性进行操作: length() 获取长度 | getPos ...

  3. python-base64编码与解码

    base64编码原理: 例如: 实例一: #-*- coding: UTF-8 -*- ' __date__ = '2015/12/23' import base64 code = "aGV ...

  4. python--getitme\setitem 支持索引与分片

    1.想要自己定义的python对象支持索引与分片操作就要重载__getitem__\__setitem__这两个方法. 2.__getitme__(self,index) 这里的index参数可能类型 ...

  5. HTML5 javascript实现音乐播放器

    准备毕业了,感觉好多东西都没学会,太多太多想学的知识,有种求知若渴的状态. 四年的大学就剩下一个多月了,无论将来多么困难,这条路是自己选的,走就要走的精彩! 自学了一点javascript.php,做 ...

  6. MFC网页

    写网页, 选择MFC,MFC应用程序,其他默认,单击确定 项目类型,选Offce,其他默认,单击下一步 默认,单击下一步 文件拓展名,输入html,其他默认,单击下一步 数据库支持,默认,单击下一步 ...

  7. 用Meta 取消流量器缓存实现每次访问都刷新页面方便调试

    如果想禁止浏览器从本地缓存中调阅页面,可以设置网页不保存在缓存中,每次访问都刷新页面,下面是Meta在这方便的用法,需要的朋友可以参考下: <!-- 禁止浏览器从本地缓存中调阅页面.--> ...

  8. 使用after伪类清除浮动

    使用after伪类清除浮动 .department li:after{ content:"."; height:0; visibility:hidden; display:bloc ...

  9. sql server操作2:查询数据库语句大全【转】

    注:以下操作均建立在上篇文章sql Server操作1的数据基础之上 一.实验目的 熟悉SQL语句的基本使用方法,学习如何编写SQL语句来实现查询 二.实验内容和要求 使用SQL查询分析器查询数据,练 ...

  10. 用事件与CSS改变按钮不同状态下的颜色

    目标效果: 表单的群发按钮,在鼠标悬停时为深蓝色,鼠标离开时为淡蓝色. HTML代码: <button id="submitBtn"  class="btn&quo ...