Page 1 of 1
Posted: Fri Jun 28, 2002 1:42 pm
by BackupUser
Restored from previous forum. Originally posted by ebs.
Since I get such good answers here, I have two more questions!
1) Is there any way (PB, Windows API, etc.) to read the filename that is currently highlighted in the OpenFileRequester? I don't mean after the file is selected (by double-clicking or clicking "OK"), but WHILE the dialog is open? I am trying to make a custom file open dialog for image files with a preview, so I need to know the currently selected file, if possible.
2) Is there any documentation on the two libraries in the UserLibraries directory - ComDX and HiResTimer? If not, can somebody give me a quick lesson on how to use them?
Thanks,
Eric
Posted: Fri Jun 28, 2002 2:42 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.
I think you must use the API to do that: GetOpenFileName_(@ofn.OPENFILENAME), and enable the hook function. Haven't tested it, but it should work.
Bye,
El_Choni
Posted: Fri Jun 28, 2002 2:45 pm
by BackupUser
Restored from previous forum. Originally posted by ebs.
El_Choni,
Can you explain a bit more?
Eric
I think you must use the API to do that: GetOpenFileName_(@ofn.OPENFILENAME), and enable the hook function. Haven't tested it, but it should work.
Bye,
El_Choni
Posted: Fri Jun 28, 2002 5:19 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.
Hi,
I've extracted this from a bigger app, so it main contain some useless code, but it does the job:
Code: Select all
Global openfile.s, strTitle.s, CurrentDir.s, extension.s
Dim ext.s(4)
Global ext
SaveFilter.s = "Windows BMP Image (*.bmp)|*.bmp|Xpm image (*.xpm)|*.xpm"
!mov eax, [v_SaveFilter]
!filterloop:
!inc eax
!cmp byte [eax], 0
!je .endfilter
!cmp byte [eax], "|"
!jne filterloop
!mov byte [eax], 0
!jmp filterloop
!.endfilter:
!mov word [eax], 0
Global ofn.OPENFILENAME
ofn\lStructSize = SizeOf(OPENFILENAME)
ofn\hInstance = hInstance
ofn\lpstrFilter = @SaveFilter
ofn\lpstrCustomFilter = 0
ofn\nMaxCustFilter = 0
ofn\nFilterIndex = 0
; some dialog constants, only CDN_SELCHANGE is used in this example
#CDN_FIRST = -601
#CDN_LAST = -699
#CDN_INITDONE = #CDN_FIRST
#CDN_SELCHANGE = #CDN_FIRST-1
#CDN_FOLDERCHANGE = #CDN_FIRST-2
#CDN_SHAREVIOLATION = #CDN_FIRST-3
#CDN_HELP = #CDN_FIRST-4
#CDN_FILEOK = #CDN_FIRST-5
#CDN_TYPECHANGE = #CDN_FIRST-6
#CDN_INCLUDEITEM = #CDN_FIRST-7
Structure OFNOTIFY
hdr.l
lpOFN.l
pszFile.l
EndStructure
Procedure HookFunction(hWnd, uMsg, wParam, lParam)
result = 0
Select uMsg
Case #WM_NOTIFY
*msg.NMHDR = lParam
Select *msg\code
Case #CDN_SELCHANGE
hParent = GetParent_(hWnd)
AllocateMemory(0, 1024, 0)
If SendMessage_(hParent, #CDM_GETFILEPATH, 1024, MemoryID())
currentfile.s = PeekS(MemoryID())
MessageRequester("Current file name:", currentfile, 0)
result = 1
EndIf
FreeMemory(0)
Case #CDN_TYPECHANGE
; ; etc.
EndSelect
Case #WM_GETDLGCODE
; do what you want here
EndSelect
ProcedureReturn result
EndProcedure
Procedure Load()
result = 0
ofn\lpstrCustomFilter = 0
ofn\nMaxCustFilter = 0
ofn\nFilterIndex = 0
FileName = AllocateMemory(0, 512, 0)
If Len(openfile)>0
CopyMemory(@openfile, FileName, Len(openfile)-4)
CopyMemory(@ext(0), FileName+Len(openfile)-4, 5)
EndIf
ofn\lpstrFile = FileName
ofn\nMaxFile = 512
ofn\lpstrFileTitle = 0
ofn\nMaxFileTitle = 0
If Len(CurrentDir)>0
ofn\lpstrInitialDir = @CurrentDir
EndIf
strTitle.s = "Save image file"
ofn\lpstrTitle = @strTitle
ofn\Flags = #OFN_EXPLORER|#OFN_OVERWRITEPROMPT|#OFN_ENABLEHOOK
ofn\nFileOffset = 0
ofn\nFileExtension = 0
ofn\lpstrDefExt = 0
ofn\lpfnHook = @HookFunction()
If GetOpenFileName_(@ofn)
openfile = PeekS(ofn\lpstrFile)
CurrentDir = Left(openfile, ofn\nFileOffset)
If Len(openfile)>0
extension = ext(ofn\nFilterIndex-1)
If LCase(Right(openfile, 4)) extension
If ofn\nFileExtension = 0
If Right(openfile, 1) = "."
openfile+Right(extension, 3)
Else
openfile+extension
EndIf
EndIf
EndIf
If extension=".bmp" Or extension=".xpm"
If OpenFile(0, openfile)
MessageRequester("Message:", "File "+openfile+" opened.", 0)
result = 1
EndIf
EndIf
EndIf
FreeMemory(0)
EndIf
ProcedureReturn result
EndProcedure
If OpenWindow(0, 128, 128, 320, 256, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget, "Open file dialog example")
If CreateGadgetList(WindowID())
ButtonGadget(0, 4, 4, 128, 32, "Click me")
EndIf
Repeat
WindowEvent = WaitWindowEvent()
Select WindowEvent
Case #PB_EventGadget
Load()
Case #PB_EventCloseWindow
Quit = 1
EndSelect
Until Quit
EndIf
End
Hope it's useful for you. Bye,
El_Choni
Posted: Fri Jun 28, 2002 6:17 pm
by BackupUser
Restored from previous forum. Originally posted by Franco.
@ El_Choni
excellent hint. Thanks.
@ Eric
...I am trying to make a custom file open dialog for image files with a preview, so I need to know the currently selected file, if possible.
I don't know how, but if you look at the OpenFile Requester of the free 'IrfanView' Image file viewer, you will see that there must be a API possibility to achieve a preview inside the Windows OpenFile Requester.
If this Requester is custom made, instead of a manipulated Windows Requester, than Irfan did a good job for the same look and feel.
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
Posted: Fri Jun 28, 2002 6:31 pm
by BackupUser
Restored from previous forum. Originally posted by ebs.
El_Choni,
THANK YOU for the example! It gets me a lot of the way there. With your help, I should be able to open a preview image (in another window) when the user selects a filename.
Franco,
I agree. IrfanView definitely manages to subclass the standard Windows file open dialog, and I've also seen an example done in Visual Basic (very involved!). Since I won't be able to spend a long time on it, I'll probably settle for a separate preview window. But I'll keep looking!
Regards,
Eric