1.C++程序:
#include<Windows.h>
#include<commdlg.h>
char szFilter1[2][16] = { "Excutable Files", "*.exe;*.com" };
char szFileNameOpen2[MAX_PATH] = { 0 };
int main(int argc, char *argv[])
{
OPENFILENAME openFile = { 0 };
openFile.lStructSize = sizeof(OPENFILENAME);
openFile.hwndOwner = NULL;
openFile.hInstance = (HINSTANCE)GetModuleHandle(NULL);
openFile.lpstrFilter = (LPCSTR)szFilter1;
openFile.lpstrFile = szFileNameOpen2;
openFile.nMaxFile = MAX_PATH;
openFile.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
GetOpenFileName(&openFile);
return 0;
}
2.汇编程序:
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
include kernel32.inc
include gdi32.inc
include comctl32.inc
include comdlg32.inc
include advapi32.inc
include shell32.inc
include masm32.inc
include netapi32.inc
include winmm.inc
include ws2_32.inc
includelib comctl32.lib
includelib comdlg32.lib
includelib gdi32.lib
includelib user32.lib
includelib kernel32.lib
includelib advapi32.lib
includelib shell32.lib
includelib masm32.lib
includelib netapi32.lib
includelib winmm.lib
includelib ws2_32.lib
.data
szFilter1 db 'Executable Files',0,'*.exe;*.com',0
szFileNameOpen2 db MAX_PATH dup(0)
.code
_openFile proc
local @stOp:OPENFILENAME
invoke RtlZeroMemory,addr @stOp,sizeof @stOp
mov @stOp.lStructSize, sizeof @stOp
invoke GetModuleHandle,NULL
mov @stOp.hInstance,eax
mov @stOp.lpstrFilter,offset szFilter1
mov @stOp.lpstrFile,offset szFileNameOpen2
mov @stOp.nMaxFile,MAX_PATH
mov @stOp.Flags,OFN_FILEMUSTEXIST or OFN_HIDEREADONLY or OFN_PATHMUSTEXIST
invoke GetOpenFileName,addr @stOp
ret
_openFile endp
start:
invoke _openFile
invoke MessageBox,NULL,addr szFileNameOpen2,NULL,MB_OK
invoke ExitProcess,0
end start