;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
comdlg.asm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.386
.model flat, stdcall
option casemap : none
include windows.inc
include user32.inc
include kernel32.inc
include Comdlg32.inc
includelib user32.lib
includelib kernel32.lib
includelib Comdlg32.lib
ICO_MAIN equ 1000
DLG_MAIN equ 1000
IDM_MAIN equ 1000
IDM_OPEN equ 1101
IDM_SAVEAS equ 1102
IDM_PAGESETUP equ 1103
IDM_EXIT equ 1104
IDM_FIND equ 1201
IDM_REPLACE equ 1202
IDM_SELFONT equ 1203
IDM_SELCOLOR equ 1204
.data?
hInstance dd ?
hWinMain dd ?
dwFontColor dd ?
dwBackColor dd ?
dwCustColors dd ?
stLogFont LOGFONT <?>
szFileName db MAX_PATH dup (?)
szBuffer db 1024 dup (?)
idFindMessage dd ?
stFind FINDREPLACE <?>
szFindText db 100 dup (?)
szReplaceText db 100 dup (?)
.const
FINDMSGSTRING db 'commdlg_FindReplace', 0
szSaveCaption db '请输入保存的文件名', 0
szFormatColor db '您选择的颜色值: %08x', 0
szFormatFont db '您的选择: ', 0dh, 0ah, '字体名称: %s', 0dh, 0ah
db '字体颜色值: %08x, 字体大小: %d', 0
szFormatFind db '您按下了"%s"按钮', 0dh, 0ah, '查找字符串: %s', 0dh, 0ah
db '替换字符串: %s', 0
szFormatPrt db '您选择的打印机: %s', 0
szCaption db '执行结果', 0
szFindNext db '查找下一个', 0
szReplace db '替换', 0
szReplaceAll db '全部替换', 0
szFilter db 'Text Files(*.txt)', 0, '*.txt', 0
db 'All Files(*.*)', 0, '*.*', 0, 0
szDefExt db 'txt', 0
.code
_PageSetup proc
local @stPS : PAGESETUPDLG
invoke RtlZeroMemory, addr @stPS, sizeof @stPS
mov @stPS.lStructSize, sizeof @stPS
push hWinMain
pop @stPS.hwndOwner
invoke PageSetupDlg, addr @stPS
.if eax && @stPS.hDevMode
mov eax, @stPS.hDevMode
mov eax, [eax]
invoke wsprintf, addr szBuffer, addr szFormatPrt, eax
invoke MessageBox, hWinMain, addr szBuffer, addr szCaption, MB_OK
.endif
ret
_PageSetup endp
_SaveAs proc
local @stOF : OPENFILENAME
invoke RtlZeroMemory, addr @stOF, sizeof @stOF
mov @stOF.lStructSize, sizeof @stOF
push hWinMain
pop @stOF.hwndOwner
mov @stOF.lpstrFilter, offset szFilter
mov @stOF.lpstrFile, offset szFileName
mov @stOF.nMaxFile, MAX_PATH
mov @stOF.Flags, OFN_PATHMUSTEXIST
mov @stOF.lpstrDefExt, offset szDefExt
mov @stOF.lpstrTitle, offset szSaveCaption
invoke GetSaveFileName, addr @stOF
.if eax
invoke MessageBox, hWinMain, addr szFileName, addr szCaption, MB_OK
.endif
ret
_SaveAs endp
_OpenFile proc
local @stOF : OPENFILENAME
invoke RtlZeroMemory, addr @stOF, sizeof @stOF
mov @stOF.lStructSize, sizeof @stOF
push hWinMain
pop @stOF.hwndOwner
mov @stOF.lpstrFilter, offset szFilter
mov @stOF.lpstrFile, offset szFileName
mov @stOF.nMaxFile, MAX_PATH
mov @stOF.Flags, OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST
invoke GetOpenFileName, addr @stOF
.if eax
invoke MessageBox, hWinMain, addr szFileName, addr szCaption, MB_OK
.endif
ret
_OpenFile endp
_ChooseColor proc
local @stCC : CHOOSECOLOR
invoke RtlZeroMemory, addr @stCC, sizeof @stCC
mov @stCC.lStructSize, sizeof @stCC
push hWinMain
pop @stCC.hwndOwner
push dwBackColor
pop @stCC.rgbResult
mov @stCC.Flags, CC_RGBINIT or CC_FULLOPEN
mov @stCC.lpCustColors, offset dwCustColors
invoke ChooseColor, addr @stCC
.if eax
push @stCC.rgbResult
pop dwBackColor
invoke wsprintf, addr szBuffer, addr szFormatColor, dwBackColor
invoke MessageBox, hWinMain, addr szBuffer, addr szCaption, MB_OK
.endif
ret
_ChooseColor endp
_ChooseFont proc
local @stCF : CHOOSEFONT
invoke RtlZeroMemory, addr @stCF, sizeof @stCF
mov @stCF.lStructSize, sizeof @stCF
push hWinMain
pop @stCF.hwndOwner
mov @stCF.lpLogFont, offset stLogFont
push dwFontColor
pop @stCF.rgbColors
mov @stCF.Flags, CF_SCREENFONTS or CF_INITTOLOGFONTSTRUCT or CF_EFFECTS
invoke ChooseFont, addr @stCF
.if eax
push @stCF.rgbColors
pop dwFontColor
mov eax, @stCF.iPointSize
shl eax, 1
invoke wsprintf, addr szBuffer, addr szFormatFont, addr stLogFont.lfFaceName, dwFontColor, eax
invoke MessageBox, hWinMain, addr szBuffer, addr szCaption, MB_OK
.endif
ret
_ChooseFont endp
_ProcDlgMain proc uses ebx edi esi, hWnd, uMsg, wParam, lParam
local @szBuffer[128] : byte
mov eax, uMsg
.if eax == WM_CLOSE
invoke EndDialog, hWnd, NULL
.elseif eax == WM_INITDIALOG
mov eax, hWnd
mov hWinMain, eax
mov stFind.hwndOwner, eax
mov stFind.lStructSize, sizeof stFind
mov stFind.Flags, FR_DOWN
mov stFind.lpstrFindWhat, offset szFindText
mov stFind.wFindWhatLen, sizeof szFindText
mov stFind.lpstrReplaceWith, offset szReplaceText
mov stFind.wReplaceWithLen, sizeof szReplaceText
invoke RegisterWindowMessage, addr FINDMSGSTRING
mov idFindMessage, eax
.elseif eax == WM_COMMAND
mov eax, wParam
.if ax == IDM_EXIT
invoke EndDialog, hWnd, NULL
.elseif ax == IDM_OPEN
invoke _OpenFile
.elseif ax == IDM_SAVEAS
call _SaveAs
.elseif ax == IDM_PAGESETUP
invoke _PageSetup
.elseif ax == IDM_FIND
and stFind.Flags, not FR_DIALOGTERM
invoke FindText, addr stFind
.elseif ax == IDM_REPLACE
and stFind.Flags, not FR_DIALOGTERM
invoke ReplaceText, addr stFind
.elseif ax == IDM_SELCOLOR
invoke _ChooseColor
.elseif ax == IDM_SELFONT
invoke _ChooseFont
.endif
.elseif eax == idFindMessage
xor ecx, ecx
.if stFind.Flags & FR_FINDNEXT
mov ecx, offset szFindNext
.elseif stFind.Flags & FR_REPLACE
mov ecx, offset szReplace
.elseif stFind.Flags & FR_REPLACEALL
mov ecx, offset szReplaceAll
.endif
.if ecx
invoke wsprintf, addr szBuffer, addr szFormatFind, ecx, addr szFindText, addr szReplaceText
invoke MessageBox, hWinMain, addr szBuffer, addr szCaption, MB_OK
.endif
.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
///
comdlg.rc
///
#include <resource.h>
#define ICO_MAIN 1000
#define DLG_MAIN 1000
#define IDM_MAIN 1000
#define IDM_OPEN 1101
#define IDM_SAVEAS 1102
#define IDM_PAGESETUP 1103
#define IDM_EXIT 1104
#define IDM_FIND 1201
#define IDM_REPLACE 1202
#define IDM_SELFONT 1203
#define IDM_SELCOLOR 1204
ICO_MAIN ICON "main.ico"
DLG_MAIN DIALOG 193, 180, 310, 134
MENU IDM_MAIN
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "通用对话框示例"
FONT 9, "宋体"
{
}
IDM_MAIN menu discardable
BEGIN
popup "文件(&F)"
BEGIN
menuitem "打开文件(&O)...", IDM_OPEN
menuitem "文件另存为(&C)...", IDM_SAVEAS
menuitem separator
menuitem "页面设置(&P)...", IDM_PAGESETUP
menuitem separator
menuitem "退出(&X)", IDM_EXIT
END
popup "查看(&V)"
BEGIN
menuitem "查找字符串(&S)...", IDM_FIND
menuitem "替换字符串(&R)...", IDM_REPLACE
menuitem separator
menuitem "选择字体(&F)...", IDM_SELFONT
menuitem "选择颜色(&B)...", IDM_SELCOLOR
END
END