win32汇编环境,窗口程序中复杂列表框的应用举例
;运行效果
;双击到根目录后
;win32汇编环境,窗口程序中复杂列表框的应用举例
;在窗口程序中生成复杂列表框,增加子项,删除某项,取得指定项内容,在列表框内展示某文件夹内的文件列表,选定某文件夹后双击打开,返回上层目录再打开等
;直接抄进RadAsm可编译运行。重点部分加备注。
;以下是ASM文件
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
include kernel32.inc
include gdi32.inc
include shlwapi.inc
includelib kernel32.lib
includelib user32.lib
includelib gdi32.lib
includelib shlwapi.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.DATA
ClassName db "SimpleWinClass",0
AppName db "窗口程序的模版",0
szButtonClassName db "button",0 ;按钮类名
szListBoxClassName db "LISTBOX",0 ;列表框类名
szCaption db "提示",0
szCheckTitle db "当前文件夹的文件列表",0
szAddLib01 db "刘备",0
szAddLib02 db "关羽",0
szAddLib03 db "张飞",0
szAddLib04 db "孙策",0
szAddLib05 db "吕布",0
szFormat db '总项数是 %d',0
szFormat01 db '盘符是是 %s',0
szButtonTitle01 db "新增孙策",0
szButtonTitle02 db "删除选中项",0
szButtonTitle03 db "将吕布插入第2项",0
szButtonTitle04 db "得到总项数",0
szButtonTitle05 db "得到所选多项的名称",0
szPath db '*.*',0
szPreFolders db '[..]',0
szCheshi db 'd:\*.*',0
szMessage db '选择结果:%s',0
szTitle db '您的选择',0
szSelect db '您选择了以下的项目:'
szReturn db 0dh,0ah,0
.DATA?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hID_GROUP HWND ? ;组框控件句柄
hListBox01 HWND ? ;列表框控件句柄变量
hButton01 HWND ? ;按钮控件句柄变量
hButton02 HWND ?
hButton03 HWND ?
hButton04 HWND ?
hButton05 HWND ?
szBuffer db 256 dup (?) ;全局字符数组,用来保存路径用
.const
; Equ 等值定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
IDC_LBO1 equ 10 ;列表框控件标识符
ButtonID01 equ 11 ;按钮控件标识符
ButtonID02 equ 12
ButtonID03 equ 13
ButtonID04 equ 14
ButtonID05 equ 15
.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 hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,NULL
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,NULL, ADDR ClassName,ADDR AppName,WS_OVERLAPPEDWINDOW,100,100,260,370, NULL,NULL,hInst, NULL
mov hwnd,eax
invoke ShowWindow, hwnd,CmdShow
invoke UpdateWindow, hwnd
invoke GetCurrentDirectory,sizeof szBuffer,addr szBuffer ;将当前文件夹路径先保存下来
.while TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.break .if (!eax)
invoke TranslateMessage, ADDR msg
invoke Dispatc