.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
include kernel32.inc
include gdi32.inc
includelib user32.lib
includelib kernel32.lib
includelib gdi32.lib
ICO_MAIN equ 1000h
DLG_MAIN equ 1
IDB_1 equ 1
IDB_2 equ 2
IDC_ONTOP equ 101
IDC_SHOWBMP equ 102
IDC_ALOW equ 103
IDC_MODALFRAME equ 104
IDC_THICKFRAME equ 105
IDC_TITLETEXT equ 106
IDC_CUSTOMTEXT equ 107
IDC_BMP equ 108
IDC_SCROLL equ 109
IDC_VALUE equ 110
.data?
hInstance dd ?
hBmp1 dd ?
hBmp2 dd ?
dwPos dd ?
.const
szText1 db 'Hello, World!',0
szText2 db '嘿,你看到标题栏变了吗?',0
szText3 db '自定义',0
.code
_ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam,lParam
LOCAL @szBuffer[128]: byte
mov eax, wMsg
.if eax == WM_CLOSE
invoke EndDialog, hWnd, NULL
.elseif eax == WM_INITDIALOG
invoke LoadIcon, hInstance, ICO_MAIN
invoke SendMessage, hWnd, WM_SETICON, ICON_BIG, eax
;初始化组合框
invoke SendDlgItemMessage, hWnd, IDC_TITLETEXT, CB_ADDSTRING, 0, addr szText1
invoke SendDlgItemMessage, hWnd, IDC_TITLETEXT, CB_ADDSTRING, 0, addr szText2
invoke SendDlgItemMessage, hWnd, IDC_TITLETEXT, CB_ADDSTRING, 0, addr szText3
invoke SendDlgItemMessage, hWnd, IDC_TITLETEXT, CB_SETCURSEL, 0, 0
;设置组合框初始时候选中第一个下拉项
invoke GetDlgItem,hWnd,IDC_CUSTOMTEXT
invoke EnableWindow,eax,FALSE
;初始化复选框
invoke CheckDlgButton, hWnd, IDC_SHOWBMP, BST_CHECKED
invoke CheckDlgButton, hWnd, IDC_ALOW, BST_CHECKED
;初始化单选框
invoke CheckDlgButton, hWnd, IDC_THICKFRAME, BST_CHECKED
;加载图片1和图片2
invoke LoadBitmap, hInstance, IDB_1
mov hBmp1, eax
invoke LoadBitmap, hInstance, IDB_2
mov hBmp2, eax
;初始化滚动条
invoke SendDlgItemMessage, hWnd, IDC_SCROLL, SBM_SETRANGE, 0, 100
;--------------------------
;组合框功能:设置标题
;--------------------------
.elseif eax == WM_COMMAND
mov eax, wParam
.if ax == IDCANCEL
invoke EndDialog, hWnd, NULL
.elseif ax == IDC_TITLETEXT
shr eax,16
.if ax == CBN_SELENDOK
invoke SendDlgItemMessage, hWnd, IDC_TITLETEXT, CB_GETCURSEL, 0, 0
.if eax == 2
invoke GetDlgItem, hWnd, IDC_CUSTOMTEXT
invoke EnableWindow, eax, TRUE
.else
mov ebx, eax
invoke SendDlgItemMessage, hWnd, IDC_TITLETEXT, CB_GETLBTEXT, ebx, addr @szBuffer
invoke SetWindowText, hWnd, addr @szBuffer
invoke GetDlgItem, hWnd, IDC_CUSTOMTEXT
invoke EnableWindow, eax, FALSE
.endif
.endif
;--------------------------
;组合框--自定义设置标题
;--------------------------
.elseif ax == IDC_CUSTOMTEXT
invoke GetDlgItemText, hWnd, IDC_CUSTOMTEXT, addr @szBuffer, sizeof @szBuffer
invoke SetWindowText, hWnd, addr @szBuffer
;--------------------------
;复选框--置顶
;--------------------------
.elseif ax == IDC_ONTOP
invoke IsDlgButtonChecked, hWnd, IDC_ONTOP
.if eax == BST_CHECKED
invoke SetWindowPos, hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE
.else
invoke SetWindowPos, hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE
.endif
;--------------------------
;复选框--显示图片
;--------------------------
.elseif ax == IDC_SHOWBMP
;invoke IsDlgButtonChecked, hWnd, IDC_SHOWBMP
;.if eax == BST_UNCHECKED
; invoke GetDlgItem, hWnd, IDC_BMP
; invoke ShowWindow, eax, SW_HIDE
;.else
; invoke GetDlgItem, hWnd, IDC_BMP
; invoke ShowWindow, eax, SW_SHOW
;.endif
invoke GetDlgItem, hWnd, IDC_BMP ;这种方法不好理解~,我觉得SW_VISIBLE这个属性值在资源文件中就已经给定了,
mov ebx, eax ;那就是说返回值固定了,但是事实上这个函数的返回值却可以变
invoke IsWindowVisible, ebx
.if eax
invoke ShowWindow, ebx, SW_HIDE
.else
invoke ShowWindow, ebx, SW_SHOW
.endif
;--------------------------
;复选框--允许更换图片
;--------------------------
.elseif ax == IDC_ALOW
;invoke IsDlgButtonChecked, hWnd, IDC_ALOW
;.if eax == BST_CHECKED
; invoke GetDlgItem, hWnd, IDOK
; invoke EnableWindow, eax, TRUE
;.elseif eax == BST_UNCHECKED
; invoke GetDlgItem, hWnd, IDOK
; invoke EnableWindow, eax, FALSE
;.endif
invoke IsDlgButtonChecked, hWnd, IDC_ALOW ;这个方法好,不过要动一下脑子!上面的方法有点死,也能实现功能
.if eax == BST_CHECKED
mov ebx, TRUE
.else
mov ebx, FALSE
.endif
invoke GetDlgItem, hWnd, IDOK
invoke EnableWindow, eax, ebx
;--------------------------
;单选框--模态边框与可变边框
;--------------------------
;这个功能不会写~~~例子中的不明白什么意思
;********************************************************************
.elseif ax == IDC_MODALFRAME
invoke GetWindowLong,hWnd,GWL_STYLE
and eax,not WS_THICKFRAME
invoke SetWindowLong,hWnd,GWL_STYLE,eax
.elseif ax == IDC_THICKFRAME
invoke GetWindowLong,hWnd,GWL_STYLE
or eax,WS_THICKFRAME
invoke SetWindowLong,hWnd,GWL_STYLE,eax
;********************************************************************
;--------------------------
;更换图片
;--------------------------
.elseif ax == IDOK
mov eax, hBmp1
xchg eax, hBmp2
mov hBmp1, eax
invoke SendDlgItemMessage, hWnd, IDC_BMP, STM_SETIMAGE, IMAGE_BITMAP, eax
.endif
;--------------------------
;滚动条
;--------------------------
.elseif eax == WM_HSCROLL
mov eax,wParam
.if ax == SB_LINERIGHT
inc dwPos
.elseif ax == SB_PAGERIGHT
add dwPos, 10
.elseif ax == SB_LINELEFT
dec dwPos
.elseif ax == SB_PAGELEFT
sub dwPos, 10
.elseif ax == SB_THUMBPOSITION || ax == SB_THUMBTRACK
mov eax, wParam
shr eax, 16
mov dwPos, eax
.endif
cmp dwPos, 0
jge @F
mov dwPos, 0
@@:
cmp dwPos, 100
jle @F
mov dwPos, 100
@@:
invoke SetDlgItemInt, hWnd, IDC_VALUE, dwPos, FALSE
invoke SendDlgItemMessage, hWnd, IDC_SCROLL, SBM_SETPOS, dwPos, TRUE
;***************************
.else
mov eax, FALSE
ret
.endif
mov eax,TRUE
ret
_ProcDlgMain endp
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke DialogBoxParam, hInstance, DLG_MAIN, NULL, offset _ProcDlgMain, NULL
invoke ExitProcess, NULL
end start
这个对话框包括3部分内容:1.资源文件的定义、2.图片等需要用到的材料、3.程序编写