trouble with hooking the requester

Just starting out? Need help? Post your questions and find answers here.
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

trouble with hooking the requester

Post by localmotion34 »

i am about ready to set my copy of windows on fire, as this problem i have makes absolutey no sense.

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

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

It's late and my eyes are tired, but try this for the OFnotify Structure. I changed

lpOFN.OPENFILENAME

to

lpOFN.l

Code: Select all

Structure OFnotify 
  hdr.NMHDR 
  lpOFN.l 
  pszFile.l 
EndStructure 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

thanks sparkie, but no go. crashes when trying to get the structure size, and the hwndowner.

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

hmmm...no crash here :?
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

I take that back...you're right...it still crashes. I'll take a closer look in the morning. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

REMOVED.
Last edited by srod on Sat Nov 04, 2006 12:34 pm, edited 1 time in total.
I may look like a mule, but I'm not a complete ass.
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Re: trouble with hooking the requester

Post by lexvictory »

localmotion34 wrote: Debug PeekL(*ofn\hwndOwner) ;;;this crashes the **** out of PB
because hwnd_Owner isnt a pointer
but in your code, ure using WindowID(GetActiveWindow()), which to my knowledge, isnt correct, u use the window number; getactivewindow gets the hwnd/windowid

but even with those fixed, hwnd_owner still is 0....



and on a side note: the folders show in whatever view they want, no matter which menu item i pick


if i got anything wrong, tell me, sometimes im bad at this
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

My earlier code was half baked. This one seems to work.

A few changes were needed though:

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 
;/=============================================== 
Global *mparam 
*mparam=AllocateMemory(2000) 
*nparam=AllocateMemory(5000) 
;/=============================================== 
;/ Procedure - Sets view on Dialog init 
;/=============================================== 


Procedure OF_HookFunc(hDlg, msg, wParam, lParam) 
  Shared *of.openfilename  ;ADDED*************************
  Select msg 
    Case Dlg_Move 
      ;...Let's resize the dialog window 
      hwnd = GetParent_(hDlg) 
      MoveWindow_(hwnd, 0, 0, wParam, lParam, 1) 
    Case #WM_INITDIALOG 
      *of=lParam ;MOVED FROM #WM_NOTIFY********************
      PostMessage_(hDlg, Dlg_Move, 600, 500) 
    Case #WM_NOTIFY 
;      *of.OFnotify=lParam ;MOVED ********************
      *pnmhdr.NMHDR = lParam 
      Select *pnmhdr\code 
          
        Case #CDN_FOLDERCHANGE 
          ;--> Set our view choice here 
          openUsing = *of\lCustData
          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(#Window_0) 
  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\lCustData=view
  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(openusing) 
  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(openusing) 
        EndIf 
      Case #PB_Event_CloseWindow 
        quit = #True 
    EndSelect 
  Until quit 
EndIf 
End 
A few problems with structures (some of which were not required). Placed the 'OpenUsing' value into the myOpenDlg\lCustData field so that it could be accessed within the hook proc etc. so the GetView() proc was no longer needed.
I may look like a mule, but I'm not a complete ass.
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

i guess u got there b4 me srod; i started typing mine b4 ures was posted...

but i guess that happens a lot on here :lol:
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

lexvictory wrote:i guess u got there b4 me srod; i started typing mine b4 ures was posted...

but i guess that happens a lot on here :lol:
(Aye, I'm on a mission to beat netmaestro to every post - but don't tell him else he'll step up a gear and leave me back in the stables! 8) )
I may look like a mule, but I'm not a complete ass.
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

srod wrote:
lexvictory wrote:i guess u got there b4 me srod; i started typing mine b4 ures was posted...

but i guess that happens a lot on here :lol:
(Aye, I'm on a mission to beat netmaestro to every post - but don't tell him else he'll step up a gear and leave me back in the stables! 8) )
i smell a 3 letter word starting with w and ending with ar :lol:
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Confucius say he who post right post best...
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Damn it lex, I told you not to tell him! :evil:

Now I'm cat food!
I may look like a mule, but I'm not a complete ass.
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

ure the one who mentioned it in the first place :lol:
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

OK, thanks to your comments, i have figured it out.

HOWEVER, this example here only returns 20 files. PERIOD. even if i allocate 1000000 bytes for the string buffer, selecting 1000 files only returns 20 filenames. at all. ever. before i dynamically resize the string buffer, i need it to accurately return the files selected. anyone know why i can only get 20 files back?


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.l
  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 *ofn\lStructSize
          Debug *ofn\hwndOwner
          Debug SizeOf(OPENFILENAME)
          Debug PeekS(*ofn\lpstrFile)
          Debug MemorySize(*ofn\lpstrFile)
          ;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(1000000)
  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 = GetActiveWindow_()
  myOpenDlg\lStructSize = SizeOf(OPENFILENAME)
  myOpenDlg\hInstance = #Null
  myOpenDlg\lpstrFilter = @pattern$
  myOpenDlg\lpstrCustomFilter = #Null
  myOpenDlg\nMaxCustFilter = #Null
  myOpenDlg\nFilterIndex = patternPosition
  myOpenDlg\lpstrFile = *selectedFile
  myOpenDlg\nMaxFile = 1000000
  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$, 1, 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
    Debug filecount 
    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")
  ListViewGadget(#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

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
Post Reply