Page 1 of 2
Help , any idea for dialog Open with image preview
Posted: Tue Nov 15, 2005 11:30 pm
by rims
Hi, can anybody idea use Open dialog under WinXP in PB
I will open dialog with image preview not with file view.
Dialog same do this, but i must change this over menu or button.
Are any parameter to send from PB to dialog and change this over code in PB ?
Thanks for investigation
Richard
Posted: Wed Nov 16, 2005 2:20 am
by Sparkie
Hi rims, Welcome to Purebasic!
I fudged around with some old code I had laying around and here's what I came up with. I hope this is what you were looking for. It uses some Win API and does NOT use the native OpenFileRequester. Tested and working on WinXP with PB 3.94.
Code: Select all
;--> **********************************
;--> Code: Custom OpenFileRequester
;--> Author: Sparkie
;--> Date: November 15, 2005
;--> **********************************
#CDN_FOLDERCHANGE = -603
#OFN_ENABLESIZING = $800000
#FCIDM_SHVIEW_LARGEICON = $7029
#FCIDM_SHVIEW_SMALLICON = $702A
#FCIDM_SHVIEW_LIST = $702B
#FCIDM_SHVIEW_REPORT = $702C
#FCIDM_SHVIEW_THUMBNAIL = $702D
#FCIDM_SHVIEW_TILE = $702E
Enumeration
#Window_0
EndEnumeration
Enumeration
#Menu_Main
EndEnumeration
Enumeration
#Text_0
#Menu_Thumb
#Menu_Report
#Menu_List
#Menu_Small
#Menu_Large
#Menu_Tile
#Menu_Exit
EndEnumeration
Global openUsing
Procedure OF_HookFunc(hDlg, msg, wparam, lparam)
Select msg
Case #WM_NOTIFY
*pnmhdr.NMHDR = lparam
Select *pnmhdr\code
Case #CDN_FOLDERCHANGE
;--> Set our view choice here
hLV = FindWindowEx_(GetParent_(hDlg), 0, "SHELLDLL_DefView", #Null)
SendMessage_(hLV, #WM_COMMAND, openUsing, 0)
EndSelect
EndSelect
EndProcedure
;--> Title for Open dialog
OF_title$ = "Choose Images to View"
;--> Filter for file types to open
OF_filters$ = "bmp, jpg, jpeg|*.bmp;*.jpg;*.jpeg||"
;--> Thank you to Hi-Toro for his post
;--> http://purebasic.myforums.net/viewtopic.php?t=3173&highlight=lpstrFilter
;--> For filter to function properly, we need
;--> to replace | with null Chr0) directly in memory
*filter = AllocateMemory(Len(OF_filters$))
For i = 0 To Len(OF_filters$) - 1
n$ = Mid(OF_filters$, i + 1, 1)
If n$ = "|"
n$ = Chr (0)
EndIf
PokeB(*filter + i, Asc(n$))
Next
;--> Fill in our OPENFILENAME structure
OF_dir$ = "c:\"
OF_file$ = ""
*selectedFile = AllocateMemory(1024 * #MAX_PATH)
myOpenDlg.OPENFILENAME
myOpenDlg\lStructSize = SizeOf(OPENFILENAME)
myOpenDlg\hInstance = #Null
myOpenDlg\lpstrFilter = *filter
myOpenDlg\lpstrCustomFilter = #Null
myOpenDlg\nMaxCustFilter=#Null
myOpenDlg\nFilterIndex=0
myOpenDlg\lpstrFile = *selectedFile
myOpenDlg\nMaxFile = 1024 * #MAX_PATH
myOpenDlg\lpstrFileTitle = #Null
myOpenDlg\nMaxFileTitle = #Null
myOpenDlg\lpstrInitialDir= @OF_dir$
myOpenDlg\lpstrTitle = @OF_title$
myOpenDlg\Flags = #OFN_ENABLESIZING | #OFN_ALLOWMULTISELECT | #OFN_EXPLORER | #OFN_HIDEREADONLY | #OFN_ENABLEHOOK
myOpenDlg\lpfnHook=@OF_HookFunc()
If OpenWindow(#Window_0, 0, 0, 500, 300, #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar, "Customized File Open") And CreateGadgetList(WindowID())
myOpenDlg\hwndOwner = WindowID()
TextGadget(#Text_0, 10, 100, 280, 50, "No file has been selected")
CreateMenu(#Menu_Main, WindowID())
MenuTitle("&File")
OpenSubMenu("&Open using...")
MenuItem(#Menu_Thumb, "Thumbnails")
MenuItem(#Menu_Report, "Report")
MenuItem(#Menu_List, "List")
MenuItem(#Menu_Small, "Small Icons")
MenuItem(#Menu_Large, "Large Icons")
MenuItem(#Menu_Tile, "Tiles")
CloseSubMenu()
MenuBar()
MenuItem(#Menu_Exit, "E&xit")
quit = #False
Repeat
event = WaitWindowEvent()
Select event
Case #PB_EventMenu
MenuID = EventMenuID()
openUsing = 0
Select MenuID
Case #Menu_Thumb
openUsing = #FCIDM_SHVIEW_THUMBNAIL
Case #Menu_Report
openUsing = #FCIDM_SHVIEW_REPORT
Case #Menu_List
openUsing = #FCIDM_SHVIEW_LIST
Case #Menu_Small
openUsing = #FCIDM_SHVIEW_SMALLICON
Case #Menu_Large
openUsing = #FCIDM_SHVIEW_LARGEICON
Case #Menu_Tile
openUsing = #FCIDM_SHVIEW_TILE
Case #Menu_Exit
quit = #True
EndSelect
If openUsing
If GetOpenFileName_(@myOpenDlg) <> 0
SetGadgetText(#Text_0, "You selected.... " + PeekS(*selectedFile))
Else
SetGadgetText(#Text_0, "No file has been selected")
EndIf
EndIf
Case #PB_EventCloseWindow
quit = #True
EndSelect
Until quit
EndIf
End
Posted: Wed Nov 16, 2005 7:42 am
by Pantcho!!

Damn Sparkie! you did it again
i searche for this kinda method!
thanks.
Posted: Wed Nov 16, 2005 10:37 am
by PB
> working on WinXP with PB 3.94
No thumbnails seen on Win2K Pro and v3.94, must be XP-specific.
Posted: Wed Nov 16, 2005 2:47 pm
by Sparkie
@Pantcho: You're welcome.
@PB: Since rims was only asking for XP support, I forgot to add the XP only statement. I'll see if I can expand the code a bit to include OS < XP.

Posted: Wed Nov 16, 2005 8:59 pm
by PB
> rims was only asking for XP support
True.

I didn't notice that on the first read.
Posted: Wed Nov 16, 2005 10:30 pm
by rims
Hi Sparkie,
Your code work fine, a litle bit more a code.
I think in winAPI must be parameter for this function, for easy use.
I hope that's true?
Richard
Posted: Wed Nov 16, 2005 11:18 pm
by Sparkie
@PB: Try changing the #FCIDM_SHVIEW_THUMBNAIL constant value on line 13 to $7031 and see if that works on W2K.
@rims: Sorry, but AFAIK there is no single API function that will accomplish this task.
Posted: Thu Nov 17, 2005 1:53 am
by PB
> @PB: Try changing the #FCIDM_SHVIEW_THUMBNAIL constant value
> on line 13 to $7031 and see if that works on W2K.
Yep, works!

Posted: Mon May 01, 2006 11:21 am
by Trond
Thumbnails works on Windows 2000 until I browse to My Pictures. Then I get an Internet Explorer script error in file://C:\WINNT\Web\ImgView.htt, line 344, position 13. Error: Access denied.
Then one more, but at line 115 (still position 13), also access denied.
Posted: Mon May 01, 2006 12:42 pm
by Sparkie
Posted: Mon May 01, 2006 1:26 pm
by Trond
Then it always opens in list view mode and jammed into the top-left corner of my screen.
Also, is there a way to enable the "places bar" (with my documents, etc..)?
Posted: Mon May 01, 2006 2:48 pm
by Sparkie
@Trond: I will have more time to look at this when I get home tonight. For now, see if this works any better.
Code: Select all
;\**********************************
;\Code: Custom OpenFileRequester
;\Author: Sparkie
;\Date: November 15, 2005 REV: May 1, 2006
;\ Add PlacesBar and attempt to fix Win2k bug
;\**********************************
;...Need to add the following members to OPENFILENAME structure for adding PlacesBar
Structure OFEX Extends OPENFILENAME
pvReserved.l
dwReserved.l
FlagsEx.l
EndStructure
#CDN_FOLDERCHANGE = -603
#OFN_ENABLESIZING = $800000
#OFN_EX_NOPLACESBAR = 1
#FCIDM_SHVIEW_LARGEICON = $7029
#FCIDM_SHVIEW_SMALLICON = $702A
#FCIDM_SHVIEW_LIST = $702B
#FCIDM_SHVIEW_REPORT = $702C
#FCIDM_SHVIEW_THUMBNAIL = $702D
#FCIDM_SHVIEW_TILE = $702E
Enumeration
#Window_0
EndEnumeration
Enumeration
#Menu_Main
EndEnumeration
Enumeration
#Text_0
#Menu_Thumb
#Menu_Report
#Menu_List
#Menu_Small
#Menu_Large
#Menu_Tile
#Menu_Exit
EndEnumeration
Global openUsing
Procedure OF_HookFunc(hDlg, msg, wParam, lParam)
Select msg
Case #WM_NOTIFY
*pnmhdr.NMHDR = lParam
Select *pnmhdr\code
Case #CDN_FOLDERCHANGE
;...Set our view choice here
hLV = FindWindowEx_(GetParent_(hDlg), 0, "SHELLDLL_DefView", #Null)
SendMessage_(hLV, #WM_COMMAND, openUsing, 0)
EndSelect
EndSelect
EndProcedure
;...Title for Open dialog
OF_title$ = "Choose Images to View"
;...Filter for file types to open
OF_filters$ = "bmp, jpg, jpeg|*.bmp;*.jpg;*.jpeg||"
;...Thank you to Hi-Toro for his post
;...http://purebasic.myforums.net/viewtopic.php?t=3173&highlight=lpstrFilter
;...For filter to function properly, we need
;...to replace | with null Chr0) directly in memory
*filter = AllocateMemory(Len(OF_filters$))
For i = 0 To Len(OF_filters$) - 1
n$ = Mid(OF_filters$, i + 1, 1)
If n$ = "|"
n$ = Chr (0)
EndIf
PokeB(*filter + i, Asc(n$))
Next
;...Fill in our OPENFILENAME structure
OF_dir$ = "c:\"
OF_file$ = ""
*selectedFile = AllocateMemory(1024 * #MAX_PATH)
myOpenDlg.OFEX
myOpenDlg\lStructSize = SizeOf(OFEX)
myOpenDlg\hInstance = #Null
myOpenDlg\lpstrFilter = *filter
myOpenDlg\lpstrCustomFilter = #Null
myOpenDlg\nMaxCustFilter=#Null
myOpenDlg\nFilterIndex=0
myOpenDlg\lpstrFile = *selectedFile
myOpenDlg\nMaxFile = 1024 * #MAX_PATH
myOpenDlg\lpstrFileTitle = #Null
myOpenDlg\nMaxFileTitle = #Null
myOpenDlg\lpstrInitialDir= @OF_dir$
myOpenDlg\lpstrTitle = @OF_title$
myOpenDlg\Flags = #OFN_ENABLESIZING | #OFN_ALLOWMULTISELECT | #OFN_EXPLORER | #OFN_HIDEREADONLY | #OFN_ENABLEHOOK
;...Set the following to #OFN_EX_NOPLACESBAR to remove PlacesBar
myOpenDlg\FlagsEx = 0
myOpenDlg\lpfnHook=@OF_HookFunc()
If OpenWindow(#Window_0, 0, 0, 500, 300, "Customized File Open", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar) And CreateGadgetList(WindowID(#Window_0))
myOpenDlg\hwndOwner = WindowID(#Window_0)
TextGadget(#Text_0, 10, 100, 280, 50, "No file has been selected")
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_Small, "Small Icons")
MenuItem(#Menu_Large, "Large Icons")
MenuItem(#Menu_Tile, "Tiles")
CloseSubMenu()
MenuBar()
MenuItem(#Menu_Exit, "E&xit")
quit = #False
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Menu
MenuID = EventMenu()
openUsing = 0
Select MenuID
Case #Menu_Thumb
If openUsing = #FCIDM_SHVIEW_THUMBNAIL And OSVersion() = #PB_OS_Windows_2000
openUsing = #FCIDM_SHVIEW_THUMBNAIL + 4
Else
openUsing = #FCIDM_SHVIEW_THUMBNAIL
EndIf
Case #Menu_Report
openUsing = #FCIDM_SHVIEW_REPORT
Case #Menu_List
openUsing = #FCIDM_SHVIEW_LIST
Case #Menu_Small
openUsing = #FCIDM_SHVIEW_SMALLICON
Case #Menu_Large
openUsing = #FCIDM_SHVIEW_LARGEICON
Case #Menu_Tile
openUsing = #FCIDM_SHVIEW_TILE
Case #Menu_Exit
quit = #True
EndSelect
If openUsing
If GetOpenFileName_(@myOpenDlg) <> 0
SetGadgetText(#Text_0, "You selected.... " + PeekS(*selectedFile))
Else
SetGadgetText(#Text_0, "No file has been selected")
EndIf
EndIf
Case #PB_Event_CloseWindow
quit = #True
EndSelect
Until quit
EndIf
End
Posted: Mon May 01, 2006 4:54 pm
by Trond
Thank you for helping me. Your new code shows thumbnails when I replace the thumbnail constant with $7031. I still gives a script error in my pictures, but it shows the places bar.
Another thing I noticed is that if the user changes view mode and then changes folder, his change in view mode is not preserved, but this is not really important as long as it works inside my pictures.
Posted: Mon May 01, 2006 5:50 pm
by Sparkie
Trond, in regrads to the script errors, are you by any chance using Tweak UI
