Use Open dialog box in assembly

Source: Internet
Author: User

If the filename cannot be obtained from the command-line arguments, we can use a common dialog box (Open File dialog) to ask the user to select a file to obtain the file object to manipulate.

---------------------------------------------------------------------
; file name: 16.asm, displaying an open dialog box
.386
. Model Flat, StdCall
Option Casemap:none
Include Windows.inc
Include Kernel32.inc
Include User32.inc
Include Comdlg32.inc
Includelib Kernel32.lib
Includelib User32.lib
Includelib Comdlg32.lib
. Data
Ofn openfilename <0> Open File dialog box to use this structure
szFileName DB 256 dup (0)
Szfilterstring db ' executable file (*.exe) ', 0, ' *.exe ', 0,0; file filter string
Szmytitle db ' Please select the file to open ', 0
Szmessagetitle db ' The file you selected is ', 0
. Code
Getfilenamefromdialog proc
mov ofn.lstructsize,sizeof ofn; size of structure
mov ofn.lpstrfilter,offset szfilterstring; file filter
mov ofn.lpstrfile,offset szfilename; location of file name
mov ofn.nmaxfile,256; maximum length of file name
mov ofn. Flags,ofn_filemustexist or Ofn_hidereadonly or ofn_longnames
mov ofn.lpstrtitle,offset szmytitle; " Open the title of the dialog box
Invoke Getopenfilename,addr ofn; Show Open dialog box
Ret
Getfilenamefromdialog ENDP
Start:
Call Getfilenamefromdialog
. if eax!=0; If you choose to have a file, display it
Invoke Messageboxa,null,addr szfilename,addr Szmessagetitle,null
. endif
Invoke Exitprocess,null; End Program
End Start
--------------------------------------------------------------------------

The interface of the program at run time:

The display after selecting a file

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.