iczelion tut11[2]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 jimgreen 的 blog

 

例子:

下例中,我们演示了当用户选择"file->open"时,将弹出一个打开文件对话框,当用户选择了某个文件打开时,会弹出一个对话框,告知要打开的文件的全路径名,文件名和文件扩展名。

.386
.model flat,stdcall
option casemap:none
winmain proto :dword,:dword,:dword,:dword
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\comdlg32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\comdlg32.lib

.const
idm_open equ 1
idm_exit equ 2
maxsize equ 260
outputsize equ 512

.data
classname db "simplewinclass",0
appname  db "our main window",0
menuname db "firstmenu",0
ofn   openfilename <>
filterstring db "all files",0,"*.*",0
             db "text files",0,"*.txt",0,0
buffer db maxsize dup(0)
ourtitle db "-=our first open file dialog box=-: choose the file to open",0
fullpathname db "the full filename with path is: ",0
fullname  db "the filename is: ",0
extensionname db "the extension is: ",0
outputstring db outputsize dup(0)
crlf db 0dh,0ah,0

.data?
hinstance hinstance ?
commandline lpstr ?

.code
start:
    invoke getmodulehandle, null
    mov    hinstance,eax
    invoke getcommandline
    mov commandline,eax

    invoke winmain, hinstance,null,commandline, sw_showdefault
    invoke exitprocess,eax

winmain proc hinst:hinstance,hprevinst:hinstance,cmdline:lpstr,cmdshow:dword
    local wc:wndclassex
    local msg:msg
    local hwnd:hwnd
    mov   wc.cbsize,sizeof wndclassex
    mov   wc.style, cs_hredraw or cs_vredraw
    mov   wc.lpfnwndproc, offset wndproc
    mov   wc.cbclsextra,null
    mov   wc.cbwndextra,null
    push  hinst
    pop   wc.hinstance
    mov   wc.hbrbackground,color_window+1
    mov   wc.lpszmenuname,offset menuname
    mov   wc.lpszclassname,offset classname
    invoke loadicon,null,idi_application
    mov   wc.hicon,eax
    mov   wc.hiconsm,eax
    invoke loadcursor,null,idc_arrow
    mov   wc.hcursor,eax
    invoke registerclassex, addr wc
    invoke createwindowex,ws_ex_clientedge,addr classname,addr appname,\
           ws_overlappedwindow,cw_usedefault,\
           cw_usedefault,300,200,null,null,\
           hinst,null
    mov   hwnd,eax
    invoke showwindow, hwnd,sw_shownormal
    invoke updatewindow, hwnd
    .while true
        invoke getmessage, addr msg,null,0,0
        .break .if (!eax)
        invoke translatemessage, addr msg
        invoke dispatchmessage, addr msg
    .endw
    mov     eax,msg.wparam
    ret
winmain endp

wndproc proc hwnd:hwnd, umsg:uint, wparam:wparam, lparam:lparam
    .if umsg==wm_destroy
        invoke postquitmessage,null
    .elseif umsg==wm_command
        mov eax,wparam
        .if ax==idm_open
            mov ofn.lstructsize,sizeof ofn
            push hwnd

本文关键:iczelion asm
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top