When using GetOpenFileName, everything seems to work fine except for the case when the user types in a bad file name. This causes a message box to pop up saying "This file does not exist. Create the file?"

I want it to create the popup that says: "File Not Found Please verify that the correct file name was given"


invoke GetOpenFileName,ofn_lStructSize
Posted on 2003-09-16 11:03:48 by msmith
Posted on 2003-09-16 11:40:44 by roticv

Thanks for the suggestion, but if you look at my code, you will see that I already have OFN_FILEMUSTEXIST.
Posted on 2003-09-16 11:47:26 by msmith
I think he is saying you need to OR the two values together, not add them. ie, replace your + signs with the OR bitwise operator
Posted on 2003-09-16 11:54:06 by Snoopy2K
If the user specifies a file that does not exist, this flag causes the dialog box to prompt the user for permission to create the file. If the user chooses to create the file, the dialog box closes and the function returns the specified name; otherwise, the dialog box remains open.

Posted on 2003-09-16 11:57:34 by JohnFound

I don't know if you were aware of it or not, but ADDing and ORing
constants that have one bit turned on produces exactly the same result.


I have tried it with and without OFN_CREATEPROMPT. It alsmost looks like I have it turned on when I don't. I checked the FASM includes in this area vs the MASM ones and it appears that the FASM constants I'm using are correct. So the problem still remains.
Posted on 2003-09-16 13:27:52 by msmith
You have to add OFN_PATHMUSTEXIST:
OFN_EXPLORER is necessary only if you use a hook procedure

By default, the Open and Save As dialog boxes use the Explorer-style user interface regardless of whether this flag is set. This flag is necessary only if you provide a hook procedure or custom template, or set the OFN_ALLOWMULTISELECT flag.
Posted on 2003-09-16 15:09:23 by greenant
Hi greenant.

The set of flags you suggest is exactly to set I was using before I ever sent my post. It gives the same <unwanted> result that I am getting. The reason I have the current set was that I copied it from fasm's AsmWork code. I copied it from there because Tomasz's code works the way I want mine to work.

It seems that there is some parameter (other than ofn_FLAGS) in the ofn structure that actually controls what msg pops up with an invalid file.
Posted on 2003-09-16 15:22:47 by msmith
This is a procedure I wrote some months ago an this works for me. It says "bad file, ..."
BrowseForFile proc hWnd:HWND, idControl:DWORD, pszFilter:DWORD

LOCAL buffer[1024] : BYTE

invoke GetDlgItemText, hWnd, idControl, addr buffer, sizeof buffer

invoke RtlZeroMemory, addr ofn, sizeof ofn ;Zeroes OFN
mov ofn.lStructSize, sizeof ofn
mov eax, hWnd
mov ofn.hwndOwner, eax
mov eax, pszFilter
mov ofn.lpstrFilter, eax
mov ofn.nFilterIndex, 1
lea eax, [buffer]
mov ofn.lpstrFile, eax
mov ofn.nMaxFile, sizeof buffer
invoke GetOpenFileName, addr ofn
.if eax == TRUE
invoke SetDlgItemText, hWnd, idControl, ofn.lpstrFile
BrowseForFile endp
Posted on 2003-09-16 15:26:48 by greenant
Hi msmith,

you can use the following hook procedure for your GetOpenFileName function. Do not use the OFN_FILEMUSTEXIST flag with this hook.
OFNHookProc Proc hOFDlg:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

mov eax,lParam
mov ecx,[eax].OFNOTIFY.hdr.code
mov eax,[eax].OFNOTIFY.lpOFN
mov ecx,[eax].OPENFILENAME.lpstrFile
invoke FindFirstFile,ecx,ADDR wfd
; The file does not exist and the Open dialog will
; stay open, display your error dialog here
invoke SetWindowLong,hOFDlg,DWL_MSGRESULT,TRUE
mov eax,TRUE
; Default processing
invoke FindClose,eax
mov eax, 0

xor eax,eax

OFNHookProc endp
Posted on 2003-09-16 16:55:16 by donkey
Hi Donkey

As I understand your solution, we are notified when the OK button is pressed and then we take appropriate action. This is fine, and I may wind up doing that.

What concerns me is why I can't have it happen automatically like AsmWork and PFE and others. There are no hooks in the AsmWork source.

I am trying to find out how to set the ofn structure to work like AsmWork and others. As near as I can see, I am setting up things in a like manner, but still getting the wrong (undesired) popup.
Posted on 2003-09-16 17:36:10 by msmith
Hi msmith,

Well, if there is a way I can't find it in the OPENFILENAME structure. My geuss is that they hooked the dialog and passed a pointer to the error message in the lCustData field, but I have never seen the code. The only thing with hooking the dialog is for some reason the Places Bar does not show. I suppose there is a new field for 2K/Xp that deals with that.
Posted on 2003-09-16 17:49:44 by donkey
Hi Donkey,

I think I'm having a hard time explaining this situation.

I think it is really much simpler than all of you trying to help me understand.

I will try to make it more plain.

1. Program PFE (fairly old program from England??)

2. Program AsmWork (fairly new program from Poland)

Both of these programs have an open file dialog that popup with the following message when an invalid file is entered:

File Not Found Please verify that the correct file name was given

The message box and the message are identical in each case. The writers probably don't know each other. The programs are probably more than 6 years apart. Yet they have exactly the same popup. This leads me to believe that the message box is part of the API.

3. My test program ( test program to exercise dialogs)

This program works fine except then when an invalid file is typed in and OK is clicked I get a popup that says:

This file does not exist. Create the file?

I don't want this popup. I want the one that is shown in 1 and 2 above.

I don't have the source code to PFE, but the source code to AsmWork has no hooks.

I just want to know what has to be set into the ofn struct to acheive the results of 1 and 2 above.
Posted on 2003-09-16 18:50:39 by msmith
Hi msmith,

I geuss I should have checked more closely, my GetOpenFilename without the hook has that message as well. I am using the following flags:
Posted on 2003-09-16 19:13:20 by donkey
Hi Donkey,

Which message are you saying you have?
Posted on 2003-09-16 19:53:57 by msmith
Hi msmith,

This is the dialog that appears:
Posted on 2003-09-16 20:04:07 by donkey
Hi Donkey,

Your set of flags work fine here also.

These flags also work fine:


It may be possible that the problem is related to the machine I am using at work.

This machine and the one I used at work today are both Win98.

I will try it on NT and XP later.

Thanks to all for the help!
Posted on 2003-09-16 20:37:48 by msmith
I just tried it on XPHome and it works fine.


Even without the OFN_EXPLORER, it still gives an "Explorer-looking" dialog with My Computer etc. on the left side.
Posted on 2003-09-16 21:00:08 by msmith
Yeah, I think that XP wil default to the explorer style, they all should. There is an extra flag on the 2K/Xp version of the structure (DWORD appended to the end of the structure) that allows you to turn off the "Places Bar". I really dislike that thing.
Posted on 2003-09-16 21:14:29 by donkey
Neither my fasm or masm includes have OFN_EX_NOPLACESBAR.

Does anyone know the value of this constant?
Posted on 2003-09-16 21:35:39 by msmith