in the Ofhook procedure, the #wm_notify lparam is an OFNOTIFY structure, with the lpOFN member set to an OPENFILENAME structure.
so when i do this:
Case #WM_NOTIFY
*of.OFnotify=lParam
Select *of\hdr\code
Case #CDN_SELCHANGE
*ofn.OPENFILENAME=*of\lpOFN
Debug PeekL(*ofn\lStructSize) ;;this returns 76
Debug PeekL(*ofn\hwndOwner) ;;;this crashes the **** out of PB
debug peeks(*ofn\lpstrFile);;this crashes HARD
Debug SizeOf(OPENFILENAME) ;this return , yup, 76
what i am trying to do is keep track of the size of the string with all the files selected, and if need be, reallocating the buffer size for the return string of GetOpenFilname_(). it makes NO SENSE that the structure size member of the OPENFILENAME structure is intact, but ALL OTHER parameters crash and burn. no sense.
here is modified code from Sparkie i have been working with.
Code: Select all
;/=============================================================
;/ Code : Custom OpenFileRequester that allows view change
;/ Author : Sparkie
;/ Date : 03/18/06
;/ PB Version: PB 4.00 Beta7
;/ OS Support: Windows 2000/XP/Server 2003
;/=============================================================
If OSVersion() < #PB_OS_Windows_2000
MessageRequester("Sorry", "This requires a minimum of Win 2000", #MB_ICONERROR)
End
EndIf
;/===============================================
;/ Image plugins
;/===============================================
UseJPEGImageDecoder()
UsePNGImageDecoder()
UseTIFFImageDecoder()
;/===============================================
;/ Globals
;/===============================================
;...Ouyr custom message for resizing our OpenFileRequester
Global Dlg_Move = RegisterWindowMessage_(@"Dlg_Move")
;/===============================================
;/ Constants / Enumerations
;/===============================================
;...OpenFileRequester constants
#CDN_INITDONE = #CDN_FIRST - 0
#CDN_SELCHANGE = #CDN_FIRST - 1
#CDN_FOLDERCHANGE = #CDN_FIRST - 2
#OFN_ENABLESIZING = $800000
#OFR_View_Report = $702C
#OFR_View_List = $702B
#OFR_View_Largeicon = $7029
#OFR_View_Thumbnail = $702D
#OFR_View_Thumbnail_2K = $7031
#OFR_View_Tile = $702E
;...Window Enumeration
Enumeration
#Window_0 = 1
EndEnumeration
;...Menu Enumeration
Enumeration
#Menu_Main
EndEnumeration
;...Menu Item Enumeration
Enumeration
#Editor_0
#Menu_Thumb
#Menu_Report
#Menu_List
#Menu_Large
#Menu_Tile
#Menu_Exit
EndEnumeration
;/===============================================
;/ Procedure - Placeholder for view style
;/===============================================
Procedure GetView(viewStyle)
Shared theView
If viewStyle
theView = viewStyle
EndIf
ProcedureReturn theView
EndProcedure
Global *mparam
*mparam=AllocateMemory(2000)
*nparam=AllocateMemory(5000)
;/===============================================
;/ Procedure - Sets view on Dialog init
;/===============================================
Structure OFnotify
hdr.NMHDR;
lpOFN.OPENFILENAME ;
pszFile.l
EndStructure
Procedure OF_HookFunc(hDlg, msg, wParam, lParam)
Select msg
Case Dlg_Move
;...Let's resize the dialog window
hwnd = GetParent_(hDlg)
MoveWindow_(hwnd, 0, 0, wParam, lParam, 1)
Case #WM_INITDIALOG
PostMessage_(hDlg, Dlg_Move, 600, 500)
Case #WM_NOTIFY
*of.OFnotify=lParam
;*pnmhdr.NMHDR = lParam
Select *of\hdr\code
Case #CDN_SELCHANGE
*ofn.OPENFILENAME=*of\lpOFN
Debug PeekL(*ofn\lStructSize)
Debug PeekL(*ofn\hwndOwner)
Debug SizeOf(OPENFILENAME)
;SendMessage_(GetParent_(hDlg),#CDM_GETSPEC,2000,*mparam)
Case #CDN_FOLDERCHANGE
;--> Set our view choice here
openUsing = GetView(0)
If OSVersion() = #PB_OS_Windows_2000 And openUsing = #OFR_View_Thumbnail
openUsing = #OFR_View_Thumbnail_2K
EndIf
hParent = FindWindowEx_(GetParent_(hDlg), 0, "SHELLDLL_DefView", #Null)
SendMessage_(hParent, #WM_COMMAND, openUsing, 0)
EndSelect
EndSelect
ProcedureReturn 0
EndProcedure
;/===============================================
;/ Procedure - Custom OopenFileRequester
;/===============================================
Procedure.s MyOpenFileRequester(title$, defaultDir$, pattern$, patternPosition, view, multiSelect)
Shared *selectedFile
;...For filter to function properly, we need
;...to replace | with null Chr(0) directly in memory
;...Filter must end with 2 null chars
pattern$ + "||"
l = Len(pattern$)
For n = 0 To l - 1
If PeekB(@pattern$ + n) = Asc("|")
PokeB(@pattern$ + n, $0)
EndIf
Next n
;...Buffer to hold selected file name(s)
If *selectedFile = 0
*selectedFile = AllocateMemory(#MAX_PATH)
Else
;...First byte must be null if no initial file name is to be displayed
PokeB(*selectedFile, $0)
EndIf
;...Fill in our OPENFILENAME structure
myOpenDlg.OPENFILENAME
myOpenDlg\hwndOwner = WindowID(GetActiveWindow())
myOpenDlg\lStructSize = SizeOf(OPENFILENAME)
myOpenDlg\hInstance = #Null
myOpenDlg\lpstrFilter = @pattern$
myOpenDlg\lpstrCustomFilter = #Null
myOpenDlg\nMaxCustFilter = #Null
myOpenDlg\nFilterIndex = patternPosition
myOpenDlg\lpstrFile = *selectedFile
;Global *fileptr=@myOpenDlg\lpstrFile
myOpenDlg\nMaxFile = #MAX_PATH
myOpenDlg\lpstrFileTitle = #Null
myOpenDlg\nMaxFileTitle = #Null
myOpenDlg\lpstrInitialDir= @defaultDir$
myOpenDlg\lpstrTitle = @title$
myOpenDlg\flags = #OFN_ENABLESIZING | #OFN_EXPLORER | #OFN_ENABLEHOOK
myOpenDlg\lpfnHook=@OF_HookFunc()
;...Allow multiselect
If multiSelect
myOpenDlg\flags = myOpenDlg\flags | #OFN_ALLOWMULTISELECT
EndIf
;GetView(view)
;...Open the FileRequester
GetOpenFileName_(@myOpenDlg)
;...Deal with multi selections which are null terminated within *selectedFile
;...With multi selections, the buffer null terminates folder and files
;...If the first string ends with the folder, we know we have multiple selections
If multiSelect And FileSize(GetFilePart(PeekS(*selectedFile))) = -1
;...Using ";" for folder/files separator
folder$ = PeekS(*selectedFile) + ";"
For n = Len(folder$) To #MAX_PATH - 1
nextFile$ = PeekS(*selectedFile + n)
If nextFile$
;...Using "," for file separator
files$ + nextFile$ + ","
n + Len(nextFile$)
EndIf
Next n
fileReturn$ = folder$ + files$
Else
;...Only one file is selected
fileReturn$ = PeekS(*selectedFile)
EndIf
ProcedureReturn fileReturn$
EndProcedure
;/===============================================
;/ Procedure - Extract multi filenames
;/===============================================
Procedure.s MyNextSelectedFileName(parseFile$, count)
fileReturn$ = StringField(parseFile$, count, ",")
ProcedureReturn fileReturn$
EndProcedure
;/===============================================
;/ Procedure - Display Selected Files
;/===============================================
Procedure DoFileOpenRequester()
getFile$ = ""
myPattern$ ="BMP|*.bmp|JPG|*.jpg;*.jpeg|TIF|*.tif;*.tiff|PNG|*.png"
getFile$ = MyOpenFileRequester("Choose Image", "", myPattern$, 0, openUsing, 1)
;...Check for multiple files
If FindString(getFile$, ";", 1)
ClearGadgetItemList(#Editor_0)
;...Get the selected Folder
theFolder$ = StringField(getFile$, folderFileSep, ";") + "\"
;...This is where the filenames begin
folderFileSep = FindString(getFile$, ";", 1) + 1
;...Get the comma separated filenames
theFiles$ = Mid(getFile$, folderFileSep, Len(getFile$) - folderFileSep + 1)
;...Count number of files selected
filecount = CountString(theFiles$, ",")
;...Extract filenames
For f = 1 To filecount
nextFile$ = MyNextSelectedFileName(theFiles$, f)
AddGadgetItem(#Editor_0, -1, theFolder$ + nextFile$)
Next f
ElseIf getFile$ <> ""
;...Single file selected
ClearGadgetItemList(#Editor_0)
AddGadgetItem(#Editor_0, -1, getFile$)
EndIf
EndProcedure
;/===============================================
;/ Procedure - Main Window
;/===============================================
If OpenWindow(#Window_0, 0, 0, 520, 320, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar) And CreateGadgetList(WindowID(#Window_0))
CreateMenu(#Menu_Main, WindowID(#Window_0))
MenuTitle("&File")
OpenSubMenu("&Open using...")
MenuItem(#Menu_Thumb, "Thumbnails")
MenuItem(#Menu_Report, "Report")
MenuItem(#Menu_List, "List")
MenuItem(#Menu_Large, "Large Icons")
MenuItem(#Menu_Tile, "Tiles")
CloseSubMenu()
MenuBar()
MenuItem(#Menu_Exit, "E&xit")
EditorGadget(#Editor_0, 10, 10, 500, 270)
quit = #False
;/===============================================
;/ Main Event Loop
;/===============================================
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Menu
openUsing = 0
MenuID = EventMenu()
Select MenuID
Case #Menu_Thumb
openUsing = #OFR_View_Thumbnail
Case #Menu_Report
openUsing = #OFR_View_Report
Case #Menu_List
openUsing = #OFR_View_List
Case #Menu_Large
openUsing = #OFR_View_Largeicon
Case #Menu_Tile
openUsing = #OFR_View_Tile
Case #Menu_Exit
quit = #True
EndSelect
If openUsing
DoFileOpenRequester()
EndIf
Case #PB_Event_CloseWindow
quit = #True
EndSelect
Until quit
EndIf
End