News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Problems with OPENFILENAME

Started by xandaz, January 04, 2022, 06:23:30 AM

Previous topic - Next topic

xandaz

    Hi guys. Is there any specific condition for the lpstrFile member of OPENFILENAME to not show the PATH? It just shows the filename. Does it assume the current directory as ROOT? Thanks for the help in advance

xandaz

    Sreangelly, the ANSI version of the GetSaveFileName seems to show Path\Filename on both members: lpstrFile and lpstrFileTitle.

xandaz

   So...I got the problem solved. Having some members of OPENFILENAME unset causes errors. In this case was that i didn't set the lpstrFileTitle member and so the lpstrFile member didn't show the path. Always learning. ty

Greenhorn

This one works fine for me ...


.data?
g_ofn OPENFILENAME { }

.code


;//////////////////////////////////////////////////////////////////////////////
;//
;//  Procedure: ShowOpenFileDlg
;//
;//  Purpose: Gets the file name to open.
;//
;//
ShowOpenFileDlg proc FRAME hwnd:HWND, pstrFileName:LPTSTR, pstrTitleName:LPTSTR

local szFilter[MAX_PATH + 4]: TCHAR
local szBuffer[MAX_PATH + 4]: TCHAR
local szInitDir[MAX_PATH + 4]: TCHAR


ZeroMemory (&g_ofn, sizeof(OPENFILENAME))
ZeroMemory (&szBuffer, MAX_PATH + 4)

LoadString (g_hInstance, IDS_OPENDLG_FILTER, &szFilter, MAX_PATH)
mov  szFilter[rax*sizeof(TCHAR)+sizeof(TCHAR)], 0

;// Set the initial directory to the last file's path
_tcscpy (&szInitDir, pstrFileName)

_tcsrchr (&szInitDir, '\')
.if (rax)
mov  rcx, rax
add  rcx, sizeof (TCHAR)
.else
lea  rcx, szInitDir
.endif
mov  (TCHAR ptr [rcx]), 0000h

mov  g_ofn.lStructSize,     sizeof(OPENFILENAME)
mov  g_ofn.hwndOwner,       hwnd
mov  g_ofn.hInstance,       g_hInstance
mov  g_ofn.lpstrFilter,     &szFilter
mov  g_ofn.lpstrFile,       &szBuffer
mov  g_ofn.lpstrFileTitle,  pstrTitleName
mov  g_ofn.lpstrInitialDir, &szInitDir

mov  g_ofn.nFilterIndex,  1
mov  g_ofn.nMaxFile,      _MAX_PATH
mov  g_ofn.nMaxFileTitle, _MAX_FNAME + _MAX_EXT

;// flags to control appearance of open-file dialog
mov  g_ofn.Flags,   OFN_EXPLORER or \
OFN_ENABLESIZING or \
OFN_PATHMUSTEXIST or \
OFN_FILEMUSTEXIST

.if (GetOpenFileName (&g_ofn))
_tcscpy (pstrFileName, g_ofn.lpstrFile)
mov  rax, TRUE
.endif
ret
ShowOpenFileDlg endp

;//////////////////////////////////////////////////////////////////////////////
;//
;//  Procedure: ShowSaveFileDlg
;//
;//  Purpose: Gets the file name to save.
;//
;//OPENFILENAME_SIZE_VERSION_400
ShowSaveFileDlg proc FRAME hwnd:HWND, pstrFileName:LPTSTR, pstrTitleName:LPTSTR

local szFilter[MAX_PATH + 4]: TCHAR


ZeroMemory (&g_ofn, sizeof(g_ofn))

LoadString (g_hInstance, IDS_OPENDLG_FILTER, &szFilter, MAX_PATH)
mov  szFilter[rax*sizeof(TCHAR)+sizeof(TCHAR)], 0

mov  g_ofn.lStructSize,    sizeof(OPENFILENAME)
mov  g_ofn.hwndOwner,      hwnd
mov  g_ofn.hInstance,      g_hInstance
mov  g_ofn.lpstrFilter,    &szFilter
mov  g_ofn.lpstrFile,      pstrFileName
mov  g_ofn.lpstrFileTitle, pstrTitleName
;// mov  g_ofn.lpfnHook,       &SaveHookProc ;// This doesn't work with Vista/Win7-style dialog! Use IFileDialogCustomize instead!
;// mov  g_ofn.lpTemplateName, MAKEINTRESOURCE(IDD_SAVEFILE)

mov  g_ofn.nFilterIndex,  1
mov  g_ofn.nMaxFile,      _MAX_PATH
mov  g_ofn.nMaxFileTitle, _MAX_FNAME + _MAX_EXT

;// flags to control appearance of open-file dialog
mov  g_ofn.Flags,   OFN_EXPLORER        or \
OFN_ENABLESIZING    or \
OFN_OVERWRITEPROMPT or \
OFN_EXTENSIONDIFFERENT;// or OFN_ENABLETEMPLATE or OFN_ENABLEHOOK
;//mov  g_ofn.FlagsEx, OFN_EX_NOPLACESBAR

GetSaveFileName (&g_ofn)
ret
ShowSaveFileDlg endp


Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

xandaz

    Ty Greenhorn for answering and Happy New Year.