32-bit assembly in windows -- General dialog box in Chapter 8th

Source: Internet
Author: User

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;

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 'Enter the saved file name', 0
SzFormatColor db 'your selected color value: % 08x', 0
SzFormatFont db' your choice: ', 0dh, 0ah, 'font name: % s', 0dh, 0ah
Db 'font color value: % 08x, font size: % d', 0
SzFormatFind db 'You have pressed the "% s" button', 0dh, 0ah, 'query string: % s', 0dh, 0ah
Db' replacement string: % s', 0
SzFormatPrt db 'the selected printer: % s', 0
SzCaption db 'execution result', 0
SzFindNext db' find the next ', 0
SzReplace db 'offset', 0
SzReplaceAll db 'replace all ', 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 maid 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 "General dialog box example"
FONT 9, ""
{
}

IDM_MAIN menu discardable
BEGIN
Popup "file (& F )"
BEGIN
Menuitem "open a file (& O)...", IDM_OPEN
Menuitem "save the file as (& C)...", IDM_SAVEAS
Menuitem separator
Menuitem "page settings (& P)...", IDM_PAGESETUP
Menuitem separator
Menuitem "exit (& X)", IDM_EXIT
END
Popup "View (& V )"
BEGIN
Menuitem "search string (& S)...", IDM_FIND
Menuitem "replace string (& R)...", IDM_REPLACE
Menuitem separator
Menuitem "select font (& F)...", IDM_SELFONT
Menuitem "select color (& B)...", IDM_SELCOLOR
END
END

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.