News:

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

Main Menu

GetOpenFileName problem on right clic just exit

Started by TouEnMasm, May 13, 2013, 10:35:15 PM

Previous topic - Next topic

TouEnMasm


I have a problem with this dialog.When i right clic on a selected file,instead of show the context menu,the dialog just exit.
Any idea,the dialog is not bugged.

WinDialogOuvrirFichier PROC uses edi hwnd:DWORD,Longname:DWORD,TaillenomLong:DWORD,\
shortname:DWORD,TailleNomCourt:DWORD
LOCAL    ofn:OPENFILENAME
LOCAL  InitialDirectory[MAX_PATH]
LOCAL   lpstrInitialDir:DWORD
LOCAL   Pointefullname:DWORD
LOCAL   phrase[LimiteMaxPhrase]:BYTE
Local   adrtampon:DWORD
LOCAL   pointeur:DWORD
LOCAL   Nbfiches:DWORD
LOCAL   retour:DWORD
ZEROLOCALES retour

INVOKE     HeapAlloc, Hdefheap,HEAP_ZERO_MEMORY ,\
4000  ;pour noms de chemin tab
.if eax == 0
jmp FindeWinDialogOuvrirFichier
.endif
mov     adrtampon, eax

mov al,byte ptr [RepertoirePrj]
.if al != 0
invoke lstrcpy,addr InitialDirectory,addr RepertoirePrj
lea eax,InitialDirectory ;effacer a chaque fermeture projet
mov lpstrInitialDir,eax ;s'ouvre dans le réperoire projet s'il existe
.else
invoke lstrcpy,addr InitialDirectory,addr DefautRepertoire
lea eax,InitialDirectory
mov lpstrInitialDir,eax
.endif

;---------- [Set the OPENFILENAME attributes] ----------
mov     ofn.lStructSize, sizeof ofn
PuPo    ofn.hwndOwner,hwnd
PuPo    ofn.hInstance, Hinst
mov     ofn.lpstrFilter, offset szFilter ;les filtres *.* ...
PuPo    ofn.lpstrFile,adrtampon     ;Longname
PuPo    ofn.nMaxFile, 4000 ;TaillenomLong
PuPo    ofn.lpstrFileTitle,shortname
PuPo    ofn.nMaxFileTitle,TailleNomCourt
PuPo ofn.lpstrInitialDir,lpstrInitialDir ;adresse répertoire projet ou nul
mov     ofn.lpstrTitle, offset szOpenTitle
mov ofn.nFilterIndex,2 ;N° Filtre a appliquer base 1
;------------ permission de créer un fichier vide ------------
;OFN_NOCHANGEDIR a creuser
mov     ofn.Flags, OFN_PATHMUSTEXIST or OFN_FILEMUSTEXIST or OFN_CREATEPROMPT or \
OFN_ALLOWMULTISELECT or OFN_EXPLORER
INVOKE     GetOpenFileName, addr ofn  ;boite de dialogue ouvrir fichier
.if eax == 0
jmp FindeWinDialogOuvrirFichier
.endif
;---------- cuted ---------------
;-----------------------------------
FindeWinDialogOuvrirFichier:
       ret
WinDialogOuvrirFichier endp
Fa is a musical note to play with CL

fearless

Here is an example i used in the ZlibExtractGUI demo. Only difference i can see that maybe might make a difference is the use of the OFN_EXPLORER with the OFN_ALLOWMULTISELECT flag. Looking at the documentation (skimming over it actually) i get the sense that it needs a callback function (lpfnHook) to process this info. Might be the simple right click is passed to this, not specified callback, and it causes the dialog to disappear? Try it without the OFN_EXPLORER and OFN_ALLOWMULTISELECT flags to see if it makes any difference to the default context menu handling. If its working without those two flags, then it might be related to that. Apart from that i dont see any obvious issues with the code.


.data
BrowseFile                        BROWSEFILEINFO <>
; all other variables (CurrentFilename, ZipFileFilter, ZipBrowseFileTitle etc) are set here for global use, rather than local use in the OpenZipFile function.

.code
OpenZipFile PROC hWin:HWND
    LOCAL ZLERet:DWORD
    ; browse for zip file, get filename, save it, read it in list mode, fill listview with info, set statusbar info
   
    ; Nullify string to hold filename
    Invoke RtlZeroMemory, Addr CurrentFilename, SIZEOF CurrentFilename

    ;Setup BrowseFile structure before GetOpenFileName
    push hWin
    pop BrowseFile.hwndOwner
    mov BrowseFile.lpstrFilter, Offset ZipFileFilter
    mov BrowseFile.lpstrFile, Offset CurrentFilename
    mov BrowseFile.lpstrTitle, Offset ZipBrowseFileTitle
    mov BrowseFile.nMaxFile, SIZEOF CurrentFilename
    mov BrowseFile.lpstrDefExt, 0
    mov BrowseFile.lStructSize, SIZEOF BrowseFile
    Invoke GetOpenFileName, Addr BrowseFile
    .IF eax !=0
        ;Invoke MessageBox, NULL, Addr CurrentFilename, CTEXT("ZipFile"), MB_OK
        Invoke ListViewClearAll, hLV
        Invoke SendMessage, hLV, WM_SETREDRAW, FALSE, 0
        Invoke ZL_SetProcessInfoCallback, Addr ZLCallBackListFiles
        Invoke ZL_Extract, ZLE_MODE_LIST, Addr CurrentFilename, NULL, NULL, NULL
        mov ZLERet, eax
        Invoke InvalidateRect, hLV, NULL, TRUE
        Invoke RedrawWindow, hWnd, NULL, NULL, RDW_UPDATENOW
        Invoke SendMessage, hLV, WM_SETREDRAW, TRUE, 0

        .IF ZLERet == ZLE_ERR_INVALID_ZIP
            Invoke CloseZipFile, hWin
            Invoke MessageBox, NULL, CTEXT("File is not a zip archive."), CTEXT("ZlibExtractGUI Error"), MB_OK
        .ENDIF
    .ENDIF   
    ret

OpenZipFile endp

TouEnMasm


I have tried it without those options,same thing.The debugger show nothing.
I have tried the dialog in another executable ,the right clic work.
Fa is a musical note to play with CL

fearless

mmm very strange indeed :D

Maybe paramaters? an Addr instruction missing maybe in the one that doesnt work vs the one that does? I know ive missed that a few times in searching for reasons why something was crashing. Other than that, maybe something to do with a manifest? does the working one have one included with it and the other one doesnt, perhaps? Or perhaps a difference in some initialized .data variable set up correctly in the working one vs missed out in the other one? Cant think of anything else to suggest at the moment.

dedndave

OFN_FILEMUSTEXIST or OFN_CREATEPROMPT
those 2 don't really make sense together
one says "the file must exist"
the other says "if it doesn't exist...."

also, there will be issues with OFN_CREATEPROMPT when used with OFN_ALLOWMULTISELECT
only 1 selected file may not already exist

and, of course, if you use OFN_ALLOWMULTISELECT, you may need a bigger buffer   :P

dedndave

with GetOpenFileName and GetSaveFileName, there are endless combinations and caveats - lol
you have to go through the description for every OPENFILENAME structure member
read carefully - make sure pointers are valid
an invalid pointer/flag combo is the most likely cause for a silent crash

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646839%28v=vs.85%29.aspx

i notice you haven't done that because you populate the hInstance member   :P

TouEnMasm


Founded for what,something was not correct on the stack.
Fa is a musical note to play with CL