📄 treedemo.asm
字号:
title TreeDemo
comment '*==============================*'
comment '* Programed by Ewayne Wagner *'
comment '* E-MAIL: yooper@kalamazoo.net *'
comment '*==============================*'
.586
.model flat, stdcall
option casemap:none ; Case sensitive
include \MASM32\include\Windows.inc
include \MASM32\include\user32.inc
include \MASM32\include\kernel32.inc
include \MASM32\include\gdi32.inc
include \MASM32\include\comctl32.inc
include \MASM32\include\comdlg32.inc
include \MASM32\include\advapi32.inc
includelib \MASM32\lib\user32.lib
includelib \MASM32\lib\kernel32.lib
includelib \MASM32\lib\gdi32.lib
includelib \MASM32\lib\comctl32.lib
includelib \MASM32\lib\comdlg32.lib
includelib \MASM32\lib\advapi32.lib
;===================================================
; PROTO, MACRO, and Data section
;===================================================
WinMain PROTO :DWORD, :DWORD, :DWORD, :DWORD
SplitBarProc PROTO :DWORD, :DWORD, :DWORD, :DWORD
.const
IDM_EXIT equ 2001
TVM_SETBKCOLOR equ TV_FIRST + 29
TVM_SETTEXTCOLOR equ TV_FIRST + 30
TVM_SETLINECOLOR equ TV_FIRST + 40
TVM_SETINSERTMARKCOLOR equ TV_FIRST + 37
.data
ClassName db 'TreeDemo',0
AppName db 'TreeDemo',0
RichEdit db 'RichEdit20A',0
RichEdDLL db 'RICHED20.DLL',0
TreeClass db 'SysTreeView32',0
ListClass db 'SysListView32',0
StatClass db 'msctls_statusbar32',0
StaticClass db 'STATIC',0
MenuName db 'MainMenu',0
Parent1 db 'Tree',0
Parent2 db 'Does Nothing',0
Child1 db 'Listview',0
Child2 db 'Edit Control',0
Child3 db 'Statusbar',0
Child4 db 'Status 2',0
Child5 db 'Status 3',0
Child6 db 'Clear All',0
Child7 db 'Nothing',0
szColName db 'Items',0
szItem1 db 'Item 1',0
szItem2 db 'Item 2',0
szDay db 'Have A Nice Day !!',0
szNull db 0
First db 1
Split1 dd 0, 159, 130, 161
Split2 dd 129, 0, 131, 241
.data?
hInst dd ?
CommandLine dd ?
hREdDll dd ?
MainExit dd ?
hWnd dd ?
MenuCnt dd ?
hWndStat dd ?
hWndTree dd ?
hWndList dd ?
hREdit dd ?
hImageList dd ?
hParent dd ?
hChild1 dd ?
hChild2 dd ?
hChild3 dd ?
hChild4 dd ?
hChild5 dd ?
hChild6 dd ?
hSplitBar dd ?
BarType dd ?
hBR dd ?
sbParts dd 4 dup(?)
;---------- [Structures] ----------
tvis TV_INSERTSTRUCT <?>
.code
;===================================================
; Program initialization section
;===================================================
start:
INVOKE GetModuleHandle, NULL
mov hInst, eax
INVOKE GetCommandLine
mov CommandLine, eax
call InitCommonControls
;---------- [Load the Riched20.dll] ----------
INVOKE LoadLibrary, addr RichEdDLL
mov hREdDll, eax
.if !eax
; INVOKE MessageBox, NULL, addr szError1, addr szAppName, MB_OK or MB_ICONERROR
jmp Exit
.endif
INVOKE WinMain, hInst ,NULL, CommandLine, SW_SHOWDEFAULT
mov MainExit, eax
INVOKE FreeLibrary, hREdDll
Exit:
INVOKE ExitProcess, MainExit
;===================================================
; WinMain procedure
;===================================================
WinMain proc uses ebx hinst:DWORD, hPrevInst, CmdLine, CmdShow
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_BYTEALIGNCLIENT or CS_BYTEALIGNWINDOW
mov wc.lpfnWndProc, offset WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground, COLOR_BTNFACE+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
;---------- [Center the window] ----------
INVOKE GetSystemMetrics, SM_CXSCREEN
sub eax, 353
shr eax, 1
push eax
INVOKE GetSystemMetrics, SM_CYSCREEN
sub eax, 300
shr eax, 1
pop ebx
;---------- [Create the Main Window] ----------
INVOKE CreateWindowEx, WS_EX_CLIENTEDGE, addr ClassName,\
addr AppName, WS_OVERLAPPEDWINDOW,\
ebx, eax, 353, 311, NULL, NULL, hInst, NULL
mov hWnd, eax
INVOKE ShowWindow, hWnd, SW_SHOWNORMAL
INVOKE UpdateWindow, hWnd
;---------- [Message loop] ----------
.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
;===================================================
; WinProc procedure
;===================================================
WndProc proc uses esi edi ebx hwnd:DWORD, wMsg, wParam, lParam
LOCAL rect:RECT
LOCAL lvc:LV_COLUMN
LOCAL lvi:LV_ITEM
LOCAL tvi:TV_ITEM
LOCAL xPos:DWORD, yPos, hBitmap
LOCAL szWork1[64]:BYTE
;---------- [Create the Control(s) and one time stuff] ----------
.if wMsg == WM_CREATE
;---------- [Create the status bar window] ----------
INVOKE CreateWindowEx, 0, addr StatClass, 0,\
WS_CHILD or WS_BORDER or WS_VISIBLE or SBS_SIZEGRIP,\
0, 0, 0, 0, hwnd, 0, hInst, 0
mov hWndStat, eax
;---------- [Create the control windows] ----------
INVOKE CreateWindowEx, WS_EX_CLIENTEDGE, addr TreeClass, 0,\
WS_CHILD or WS_VISIBLE or TVS_HASLINES or TVS_HASBUTTONS or\
TVS_LINESATROOT or WS_CLIPSIBLINGS,\
0, 0, 130, 160, hwnd, 44, hInst, NULL
test eax, eax
jz Ret0
mov hWndTree, eax
INVOKE SendMessage, hWndTree, TVM_SETBKCOLOR, 0, 00e1f0ffh
; INVOKE SendMessage, hWndTree, TVM_SETTEXTCOLOR, 0, 00ffffe0h
; INVOKE SendMessage, hWndTree, TVM_SETLINECOLOR, 0, 00ffffe0h
; INVOKE SendMessage, hWndTree, TVM_SETINSERTMARKCOLOR, 0, 00ffffe0h
INVOKE CreateWindowEx, WS_EX_CLIENTEDGE, addr ListClass, NULL,\
WS_CHILD or WS_VISIBLE or LVS_REPORT or LVS_SHAREIMAGELISTS or LVS_SORTASCENDING,\
0, 160, 130, 51, hwnd, 45, hInst, NULL
test eax, eax
jz Ret0
mov hWndList, eax
; INVOKE SendMessage, hWndList, LVM_SETTEXTCOLOR, 0, 00000000h
INVOKE SendMessage, hWndList, LVM_SETBKCOLOR, 0, 00ffffe0h
INVOKE SendMessage, hWndList, LVM_SETTEXTBKCOLOR, 0, 00ffffe0h
INVOKE CreateWindowEx, WS_EX_CLIENTEDGE, addr RichEdit, NULL,\
WS_CHILD or WS_VISIBLE or ES_MULTILINE or\
ES_NOHIDESEL or ES_SAVESEL or ES_SELECTIONBAR or\
WS_HSCROLL or ES_AUTOHSCROLL or\
WS_VSCROLL or ES_AUTOVSCROLL or WS_CLIPSIBLINGS,\
131, 0, 211, 241, hwnd, 46, hInst, NULL
test eax, eax
jz Ret0
mov hREdit, eax
INVOKE SendMessage, hREdit, EM_SETBKGNDCOLOR, 0, 00f0fff0h
;---------- [Get the Imagelist] ----------
INVOKE ImageList_Create, 16, 16, ILC_COLOR16, 5, 10
mov hImageList, eax
INVOKE LoadBitmap, hInst, 900
mov hBitmap,eax
INVOKE ImageList_Add, hImageList, hBitmap, NULL
INVOKE DeleteObject, hBitmap
;---------- [Remove the comment if you want images for the Tree] ----------
; INVOKE SendMessage, hWndTree, TVM_SETIMAGELIST, 0, hImageList
;---------- [Fill the tree] ----------
INVOKE SendMessage, hWndTree, TVM_DELETEITEM, 0, TVI_ROOT
mov tvis.hParent, NULL
mov tvis.hInsertAfter, TVI_ROOT
mov tvis.item.imask, TVIF_TEXT or TVIF_IMAGE or TVIF_SELECTEDIMAGE
mov tvis.item.pszText, offset Parent1
mov tvis.item.iImage, 0
mov tvis.item.iSelectedImage, 1
INVOKE SendMessage, hWndTree, TVM_INSERTITEM, 0, addr tvis
mov hParent, eax
mov tvis.hParent, eax
mov tvis.hInsertAfter, TVI_LAST
mov tvis.item.pszText, offset Child1
INVOKE SendMessage, hWndTree, TVM_INSERTITEM, 0, addr tvis
mov hChild1, eax
mov tvis.item.pszText, offset Child2
INVOKE SendMessage, hWndTree, TVM_INSERTITEM, 0, addr tvis
mov hChild2, eax
mov tvis.item.pszText, offset Child3
INVOKE SendMessage, hWndTree, TVM_INSERTITEM, 0, addr tvis
mov hChild3, eax
mov tvis.hParent, eax
mov tvis.item.pszText, offset Child4
INVOKE SendMessage, hWndTree, TVM_INSERTITEM, 0, addr tvis
mov hChild4, eax
mov tvis.item.pszText, offset Child5
INVOKE SendMessage, hWndTree, TVM_INSERTITEM, 0, addr tvis
mov hChild5, eax
mov eax, hParent
mov tvis.hParent, eax
mov tvis.item.pszText, offset Child6
INVOKE SendMessage, hWndTree, TVM_INSERTITEM, 0, addr tvis
mov hChild6, eax
mov tvis.hParent, NULL
mov tvis.hInsertAfter, TVI_ROOT
mov tvis.item.imask, TVIF_TEXT or TVIF_IMAGE or TVIF_SELECTEDIMAGE
mov tvis.item.pszText, offset Parent2
INVOKE SendMessage, hWndTree, TVM_INSERTITEM, 0, addr tvis
mov tvis.hParent, eax
mov tvis.item.pszText, offset Child7
INVOKE SendMessage, hWndTree, TVM_INSERTITEM, 0, addr tvis
INVOKE SendMessage, hWndTree, TVM_EXPAND, TVE_EXPAND, hParent
INVOKE SendMessage, hWndTree, TVM_SORTCHILDREN, 0, hParent
INVOKE SendMessage, hWndTree, TVM_SELECTITEM, TVGN_CARET, NULL ;hParent
;---------- [Create the column for the Listview] ----------
mov lvc.imask, LVCF_TEXT or LVCF_WIDTH
mov lvc.pszText, offset szColName
mov lvc.lx, 125
INVOKE SendMessage, hWndList, LVM_INSERTCOLUMN, 0, addr lvc
;---------- [Move and Size the Control(s)] ----------
.elseif wMsg == WM_SIZE
;---------- [Size the Statusbar Control] ----------
mov eax, lParam ; Get width
and eax, 0ffffh ; Lowword
shr eax, 2 ; /4
mov ecx, eax ; Save factor
mov sbParts, eax ; Make part 1 1/4 the width
add eax, ecx
mov [sbParts+4], eax ; and also part2, .. etc
add eax, ecx
mov [sbParts+8], eax
mov [sbParts+12], -1 ; The last part extends to the end
INVOKE SendMessage, hWndStat, SB_SETPARTS, 4, addr sbParts
INVOKE MoveWindow, hWndStat, 0, 0, 0, 0, TRUE
INVOKE GetWindowRect, hWndStat, addr rect ; Rectangle of statusbar
mov eax, rect.bottom
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -